summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.java7.test
diff options
context:
space:
mode:
authorLaurent Goubet <laurent.goubet@obeo.fr>2014-10-31 15:20:14 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2015-02-02 21:23:32 +0100
commit494e893c541b5cf465b362c69354c08d7a81c249 (patch)
tree7505ccfce4dce906d697d9c45573617dddcc2d09 /org.eclipse.jgit.java7.test
parentd2e0bfa56844642435c9ba81d488aa0da9b22b36 (diff)
downloadjgit-494e893c541b5cf465b362c69354c08d7a81c249.tar.gz
jgit-494e893c541b5cf465b362c69354c08d7a81c249.zip
Support for the pre-commit hook
Introduce support for the pre-commit hook into JGit, along with the --no-verify commit command option to bypass it when rebasing / cherry-picking. Change-Id: If86df98577fa56c5c03d783579c895a38bee9d18 Signed-off-by: Laurent Goubet <laurent.goubet@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.MF1
-rw-r--r--org.eclipse.jgit.java7.test/src/org/eclipse/jgit/util/HookTest.java30
2 files changed, 31 insertions, 0 deletions
diff --git a/org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF
index a6e8f67dd5..182c2679e3 100644
--- a/org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.java7.test/META-INF/MANIFEST.MF
@@ -6,6 +6,7 @@ Bundle-Version: 3.7.0.qualifier
Bundle-Vendor: %provider_name
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.eclipse.jgit.api;version="[3.7.0,3.8.0)",
+ org.eclipse.jgit.api.errors;version="[3.7.0,3.8.0)",
org.eclipse.jgit.diff;version="[3.7.0,3.8.0)",
org.eclipse.jgit.dircache;version="[3.7.0,3.8.0)",
org.eclipse.jgit.internal.storage.file;version="3.7.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 73086ab4af..96550889c8 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
@@ -44,12 +44,15 @@ package org.eclipse.jgit.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.File;
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.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.junit.Assume;
@@ -91,6 +94,33 @@ public class HookTest extends RepositoryTestCase {
res.getStatus());
}
+ @Test
+ public void testPreCommitHook() throws Exception {
+ assumeSupportedPlatform();
+
+ Hook h = Hook.PRE_COMMIT;
+ writeHookFile(h.getName(),
+ "#!/bin/sh\necho \"test\"\n\necho 1>&2 \"stderr\"\nexit 1");
+ 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();
+ fail("expected pre-commit hook to abort commit");
+ } catch (RejectCommitException e) {
+ assertEquals("unexpected error message from pre-commit hook",
+ "Commit 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);
+ }
+ }
+
private File writeHookFile(final String name, final String data)
throws IOException {
File path = new File(db.getWorkTree() + "/.git/hooks/", name);