diff options
Diffstat (limited to 'org.eclipse.jgit.java7.test')
-rw-r--r-- | org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF | 1 | ||||
-rw-r--r-- | org.eclipse.jgit.java7.test/src/org/eclipse/jgit/util/HookTest.java | 32 |
2 files changed, 16 insertions, 17 deletions
diff --git a/org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF index a1b2782cb5..a160c8c49f 100644 --- a/org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF @@ -9,6 +9,7 @@ Import-Package: org.eclipse.jgit.api;version="[4.0.0,4.1.0)", org.eclipse.jgit.api.errors;version="[4.0.0,4.1.0)", org.eclipse.jgit.diff;version="[4.0.0,4.1.0)", org.eclipse.jgit.dircache;version="[4.0.0,4.1.0)", + org.eclipse.jgit.hooks;version="[4.0.0,4.1.0)", org.eclipse.jgit.internal.storage.file;version="4.0.0", org.eclipse.jgit.junit;version="[4.0.0,4.1.0)", org.eclipse.jgit.lib;version="[4.0.0,4.1.0)", diff --git a/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/util/HookTest.java b/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/util/HookTest.java index 96550889c8..0324efca6a 100644 --- a/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/util/HookTest.java +++ b/org.eclipse.jgit.java7.test/src/org/eclipse/jgit/util/HookTest.java @@ -52,7 +52,8 @@ import java.io.IOException; import java.io.PrintStream; import org.eclipse.jgit.api.Git; -import org.eclipse.jgit.api.errors.RejectCommitException; +import org.eclipse.jgit.api.errors.AbortedByHookException; +import org.eclipse.jgit.hooks.PreCommitHook; import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.RepositoryTestCase; import org.junit.Assume; @@ -64,25 +65,25 @@ public class HookTest extends RepositoryTestCase { public void testFindHook() throws Exception { assumeSupportedPlatform(); - Hook h = Hook.PRE_COMMIT; - assertNull("no hook should be installed", FS.DETECTED.findHook(db, h)); - File hookFile = writeHookFile(h.getName(), + assertNull("no hook should be installed", + FS.DETECTED.findHook(db, PreCommitHook.NAME)); + File hookFile = writeHookFile(PreCommitHook.NAME, "#!/bin/bash\necho \"test $1 $2\""); - assertEquals("exected to find pre-commit hook", hookFile, - FS.DETECTED.findHook(db, h)); + assertEquals("expected to find pre-commit hook", hookFile, + FS.DETECTED.findHook(db, PreCommitHook.NAME)); } @Test public void testRunHook() throws Exception { assumeSupportedPlatform(); - Hook h = Hook.PRE_COMMIT; - writeHookFile( - h.getName(), + writeHookFile(PreCommitHook.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.runIfPresent(db, h, new String[] { + ProcessResult res = FS.DETECTED.runHookIfPresent(db, + PreCommitHook.NAME, + new String[] { "arg1", "arg2" }, new PrintStream(out), new PrintStream(err), "stdin"); assertEquals("unexpected hook output", "test arg1 arg2\nstdin\n", @@ -95,11 +96,10 @@ public class HookTest extends RepositoryTestCase { } @Test - public void testPreCommitHook() throws Exception { + public void testFailedPreCommitHookBlockCommit() throws Exception { assumeSupportedPlatform(); - Hook h = Hook.PRE_COMMIT; - writeHookFile(h.getName(), + writeHookFile(PreCommitHook.NAME, "#!/bin/sh\necho \"test\"\n\necho 1>&2 \"stderr\"\nexit 1"); Git git = Git.wrap(db); String path = "a.txt"; @@ -110,14 +110,12 @@ public class HookTest extends RepositoryTestCase { git.commit().setMessage("commit") .setHookOutputStream(new PrintStream(out)).call(); fail("expected pre-commit hook to abort commit"); - } catch (RejectCommitException e) { + } catch (AbortedByHookException e) { assertEquals("unexpected error message from pre-commit hook", - "Commit rejected by \"pre-commit\" hook.\nstderr\n", + "Rejected by \"pre-commit\" hook.\nstderr\n", e.getMessage()); assertEquals("unexpected output from pre-commit hook", "test\n", out.toString()); - } catch (Throwable e) { - fail("unexpected exception thrown by pre-commit hook: " + e); } } |