diff options
author | Laurent Delaigue <laurent.delaigue@obeo.fr> | 2015-02-23 11:18:50 +0100 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2015-03-02 15:33:30 +0100 |
commit | 26fd56f167e6377777e6d46c14779183e4bcb55a (patch) | |
tree | 1d852b5ff1a32930773aff6218c03b09e6e56245 /org.eclipse.jgit.java7.test | |
parent | 12a55c34753669365d9e644e592d9d8c10e742f1 (diff) | |
download | jgit-26fd56f167e6377777e6d46c14779183e4bcb55a.tar.gz jgit-26fd56f167e6377777e6d46c14779183e4bcb55a.zip |
Refactored pre-commit hook to make it less invasive.
Hooks are now obtained via a convenient API like git commands, and
callers don't have to check for their existence.
The pre-commit hook has been updated accordingly.
Change-Id: I3383ffb10e2f3b588d7367b9139b606ec7f62758
Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
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); } } |