summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMartin Goellnitz <m.goellnitz@outlook.com>2016-09-10 11:29:30 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2016-09-13 17:13:48 +0200
commit57a263f1823d164142235a72072154f0568cb61c (patch)
tree6383c05dee569f5103b0ee0a39a29b4a68217a21 /org.eclipse.jgit.test
parentabeaafc9c7c9dcea72ea5c7e0e93417bb2111cc6 (diff)
downloadjgit-57a263f1823d164142235a72072154f0568cb61c.tar.gz
jgit-57a263f1823d164142235a72072154f0568cb61c.zip
Add support for post-commit hooks
Change-Id: I6691b454404dd4db3c690ecfc7515de765bc2ef7 Signed-off-by: Martin Goellnitz <m.goellnitz@outlook.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java62
1 files changed, 62 insertions, 0 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 e07076e322..a680ef9f9c 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
@@ -54,6 +54,7 @@ import java.io.PrintStream;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.AbortedByHookException;
import org.eclipse.jgit.hooks.CommitMsgHook;
+import org.eclipse.jgit.hooks.PostCommitHook;
import org.eclipse.jgit.hooks.PreCommitHook;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
@@ -76,6 +77,18 @@ public class HookTest extends RepositoryTestCase {
}
@Test
+ public void testFindPostCommitHook() throws Exception {
+ assumeSupportedPlatform();
+
+ assertNull("no hook should be installed",
+ FS.DETECTED.findHook(db, PostCommitHook.NAME));
+ File hookFile = writeHookFile(PostCommitHook.NAME,
+ "#!/bin/bash\necho \"test $1 $2\"");
+ assertEquals("expected to find post-commit hook", hookFile,
+ FS.DETECTED.findHook(db, PostCommitHook.NAME));
+ }
+
+ @Test
public void testFailedCommitMsgHookBlocksCommit() throws Exception {
assumeSupportedPlatform();
@@ -133,6 +146,55 @@ public class HookTest extends RepositoryTestCase {
}
@Test
+ public void testPostCommitRunHook() throws Exception {
+ assumeSupportedPlatform();
+
+ writeHookFile(PostCommitHook.NAME,
+ "#!/bin/sh\necho \"test $1 $2\"\nread INPUT\necho $INPUT\necho 1>&2 \"stderr\"");
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayOutputStream err = new ByteArrayOutputStream();
+ ProcessResult res = FS.DETECTED.runHookIfPresent(db,
+ PostCommitHook.NAME,
+ new String[] {
+ "arg1", "arg2" },
+ new PrintStream(out), new PrintStream(err), "stdin");
+
+ assertEquals("unexpected hook output", "test arg1 arg2\nstdin\n",
+ out.toString("UTF-8"));
+ assertEquals("unexpected output on stderr stream", "stderr\n",
+ err.toString("UTF-8"));
+ assertEquals("unexpected exit code", 0, res.getExitCode());
+ assertEquals("unexpected process status", ProcessResult.Status.OK,
+ res.getStatus());
+ }
+
+ @Test
+ public void testAllCommitHooks() throws Exception {
+ assumeSupportedPlatform();
+
+ writeHookFile(PreCommitHook.NAME,
+ "#!/bin/sh\necho \"test pre-commit\"\n\necho 1>&2 \"stderr pre-commit\"\nexit 0");
+ writeHookFile(CommitMsgHook.NAME,
+ "#!/bin/sh\necho \"test commit-msg $1\"\n\necho 1>&2 \"stderr commit-msg\"\nexit 0");
+ writeHookFile(PostCommitHook.NAME,
+ "#!/bin/sh\necho \"test post-commit\"\necho 1>&2 \"stderr post-commit\"\nexit 0");
+ Git git = Git.wrap(db);
+ String path = "a.txt";
+ writeTrashFile(path, "content");
+ git.add().addFilepattern(path).call();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ git.commit().setMessage("commit")
+ .setHookOutputStream(new PrintStream(out)).call();
+ } catch (AbortedByHookException e) {
+ fail("unexpected hook failure");
+ }
+ assertEquals("unexpected hook output",
+ "test pre-commit\ntest commit-msg .git/COMMIT_EDITMSG\ntest post-commit\n",
+ out.toString("UTF-8"));
+ }
+
+ @Test
public void testRunHook() throws Exception {
assumeSupportedPlatform();