summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java26
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/hooks/PostCommitHook.java13
2 files changed, 35 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java
index 4cbd6c2eb9..ce3ad2239a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/GitHook.java
@@ -170,14 +170,32 @@ public abstract class GitHook<T> implements Callable<T> {
getParameters(), getOutputStream(), stderrStream,
getStdinArgs());
if (result.isExecutedWithError()) {
- throw new AbortedByHookException(
- new String(errorByteArray.toByteArray(),
- Charset.defaultCharset().name()),
- getHookName(), result.getExitCode());
+ handleError(new String(errorByteArray.toByteArray(),
+ Charset.defaultCharset().name()), result);
}
}
/**
+ * Process that the hook exited with an error. This default implementation
+ * throws an {@link AbortedByHookException }. Hooks which need a different
+ * behavior can overwrite this method.
+ *
+ * @param message
+ * error message
+ * @param result
+ * The process result of the hook
+ * @throws AbortedByHookException
+ * When the hook should be aborted
+ * @since 5.11
+ */
+ protected void handleError(String message,
+ final ProcessResult result)
+ throws AbortedByHookException {
+ throw new AbortedByHookException(message, getHookName(),
+ result.getExitCode());
+ }
+
+ /**
* Check whether a 'native' (i.e. script) hook is installed in the
* repository.
*
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/PostCommitHook.java b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/PostCommitHook.java
index 0b61ebea3f..b9dafcca31 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/hooks/PostCommitHook.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/hooks/PostCommitHook.java
@@ -14,6 +14,7 @@ import java.io.PrintStream;
import org.eclipse.jgit.api.errors.AbortedByHookException;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.util.ProcessResult;
/**
* The <code>post-commit</code> hook implementation. This hook is run after the
@@ -73,4 +74,16 @@ public class PostCommitHook extends GitHook<Void> {
return NAME;
}
+
+ /**
+ * Overwrites the default implementation to never throw an
+ * {@link AbortedByHookException}, as the commit has already been done and
+ * the exit code of the post-commit hook has no effect.
+ */
+ @Override
+ protected void handleError(String message, ProcessResult result)
+ throws AbortedByHookException {
+ // Do nothing as the exit code of the post-commit hook has no effect.
+ }
+
}