From 1afbbeac15bec93abdba6e1f42803d28114268da Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 15 Oct 2012 13:54:00 +0200 Subject: [PATCH 1/2] fix abort during pre receive hook --- .../java/sonia/scm/web/GitReceiveHook.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceiveHook.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceiveHook.java index 2696a03846..9c8d9e5f58 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceiveHook.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/web/GitReceiveHook.java @@ -65,7 +65,6 @@ import java.io.File; import java.io.IOException; import java.util.Collection; -import java.util.Collections; import java.util.List; /** @@ -287,6 +286,11 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook catch (Exception ex) { logger.error("could not handle receive commands", ex); + + if (type == RepositoryHookType.PRE_RECEIVE) + { + sendError(rpack, receiveCommands, ex.getMessage()); + } } } @@ -339,6 +343,30 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook } } + /** + * Method description + * + * + * @param rpack + * @param commands + * @param message + */ + private void sendError(ReceivePack rpack, Iterable commands, + String message) + { + if (logger.isWarnEnabled()) + { + logger.warn("abort git push request with msg: {}", message); + } + + for (ReceiveCommand rc : commands) + { + rc.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON); + } + + rpack.sendError(PREFIX_MSG.concat(Util.nonNull(message))); + } + /** * Method description * @@ -350,8 +378,8 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook */ private void sendError(ReceivePack rpack, ReceiveCommand rc, String message) { - rpack.sendError(PREFIX_MSG.concat(Util.nonNull(message))); rc.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON); + rpack.sendError(PREFIX_MSG.concat(Util.nonNull(message))); } //~--- get methods ---------------------------------------------------------- From 74a8eaec0fd44088206e006b5403579b5c727e38 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Tue, 16 Oct 2012 08:06:53 +0200 Subject: [PATCH 2/2] close branch issue-242