Added environment variables to RepositoryAction#ofCommand.

This commit is contained in:
Andrew Lalis 2022-04-29 09:22:10 +02:00
parent 540616db42
commit e33b594a5e
2 changed files with 14 additions and 2 deletions

View File

@ -6,7 +6,7 @@
<groupId>nl.andrewl</groupId> <groupId>nl.andrewl</groupId>
<artifactId>distribugit</artifactId> <artifactId>distribugit</artifactId>
<version>1.3.0</version> <version>1.3.1</version>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
@ -38,7 +38,7 @@
<dependency> <dependency>
<groupId>org.kohsuke</groupId> <groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId> <artifactId>github-api</artifactId>
<version>1.303</version> <version>1.306</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/info.picocli/picocli --> <!-- https://mvnrepository.com/artifact/info.picocli/picocli -->
<dependency> <dependency>

View File

@ -17,6 +17,16 @@ public interface RepositoryAction {
* An action which executes a system command, as handled by * An action which executes a system command, as handled by
* {@link ProcessBuilder}. Note that the working directory of the command * {@link ProcessBuilder}. Note that the working directory of the command
* is set to the directory of the repository. * is set to the directory of the repository.
* <p>
* Commands invoked via this method have access to the following
* environment variables:
* </p>
* <ul>
* <li>DISTRIBUGIT_INVOKE_DIR - The directory in which distribugit
* was invoked.</li>
* <li>DISTRIBUGIT_WORKING_DIR - The working directory of distribugit,
* which contains all repositories.</li>
* </ul>
* @param command The command to run. * @param command The command to run.
* @return The command action. * @return The command action.
*/ */
@ -24,6 +34,8 @@ public interface RepositoryAction {
return git -> { return git -> {
ProcessBuilder pb = new ProcessBuilder(command); ProcessBuilder pb = new ProcessBuilder(command);
pb.directory(git.getRepository().getWorkTree()); 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(); pb.inheritIO();
Process p = pb.start(); Process p = pb.start();
int result = p.waitFor(); int result = p.waitFor();