Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java7
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java7
2 files changed, 12 insertions, 2 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java
index e34c3cebd6..e5fcbf9d7c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java
@@ -199,7 +199,8 @@ public class HookTest extends RepositoryTestCase {
assumeSupportedPlatform();
writeHookFile(PreCommitHook.NAME,
- "#!/bin/sh\necho \"test $1 $2\"\nread INPUT\necho $INPUT\necho 1>&2 \"stderr\"");
+ "#!/bin/sh\necho \"test $1 $2\"\nread INPUT\necho $INPUT\n"
+ + "echo $GIT_DIR\necho $GIT_WORK_TREE\necho 1>&2 \"stderr\"");
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
ProcessResult res = FS.DETECTED.runHookIfPresent(db,
@@ -208,7 +209,9 @@ public class HookTest extends RepositoryTestCase {
"arg1", "arg2" },
new PrintStream(out), new PrintStream(err), "stdin");
- assertEquals("unexpected hook output", "test arg1 arg2\nstdin\n",
+ assertEquals("unexpected hook output",
+ "test arg1 arg2\nstdin\n" + db.getDirectory().getAbsolutePath()
+ + '\n' + db.getWorkTree().getAbsolutePath() + '\n',
out.toString("UTF-8"));
assertEquals("unexpected output on stderr stream", "stderr\n",
err.toString("UTF-8"));
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
index 7f0308f071..e864ba76c1 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS.java
@@ -1110,6 +1110,13 @@ public abstract class FS {
hookPath);
ProcessBuilder hookProcess = runInShell(cmd, args);
hookProcess.directory(runDirectory);
+ Map<String, String> environment = hookProcess.environment();
+ environment.put(Constants.GIT_DIR_KEY,
+ repository.getDirectory().getAbsolutePath());
+ if (!repository.isBare()) {
+ environment.put(Constants.GIT_WORK_TREE_KEY,
+ repository.getWorkTree().getAbsolutePath());
+ }
try {
return new ProcessResult(runProcess(hookProcess, outRedirect,
errRedirect, stdinArgs), Status.OK);

Back to the top