From e33b594a5e287db0366c0367712ff7cfa839726d Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Fri, 29 Apr 2022 09:22:10 +0200 Subject: [PATCH] Added environment variables to RepositoryAction#ofCommand. --- pom.xml | 4 ++-- .../nl/andrewl/distribugit/RepositoryAction.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9e4afbf..2ef3d2e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ nl.andrewl distribugit - 1.3.0 + 1.3.1 17 @@ -38,7 +38,7 @@ org.kohsuke github-api - 1.303 + 1.306 diff --git a/src/main/java/nl/andrewl/distribugit/RepositoryAction.java b/src/main/java/nl/andrewl/distribugit/RepositoryAction.java index 21fe36e..3e24413 100644 --- a/src/main/java/nl/andrewl/distribugit/RepositoryAction.java +++ b/src/main/java/nl/andrewl/distribugit/RepositoryAction.java @@ -17,6 +17,16 @@ public interface RepositoryAction { * An action which executes a system command, as handled by * {@link ProcessBuilder}. Note that the working directory of the command * is set to the directory of the repository. + *

+ * Commands invoked via this method have access to the following + * environment variables: + *

+ *
    + *
  • DISTRIBUGIT_INVOKE_DIR - The directory in which distribugit + * was invoked.
  • + *
  • DISTRIBUGIT_WORKING_DIR - The working directory of distribugit, + * which contains all repositories.
  • + *
* @param command The command to run. * @return The command action. */ @@ -24,6 +34,8 @@ public interface RepositoryAction { return git -> { ProcessBuilder pb = new ProcessBuilder(command); pb.directory(git.getRepository().getWorkTree()); + pb.environment().put("DISTRIBUGIT_INVOKE_DIR", pb.directory().getParentFile().getParentFile().getAbsolutePath()); + pb.environment().put("DISTRIBUGIT_WORKING_DIR", pb.directory().getParentFile().getAbsolutePath()); pb.inheritIO(); Process p = pb.start(); int result = p.waitFor();