fix abort during pre receive hook

This commit is contained in:
Sebastian Sdorra
2012-10-15 13:54:00 +02:00
parent 3abacd8998
commit 1afbbeac15

View File

@@ -65,7 +65,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@@ -287,6 +286,11 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
catch (Exception ex) catch (Exception ex)
{ {
logger.error("could not handle receive commands", 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<ReceiveCommand> 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 * Method description
* *
@@ -350,8 +378,8 @@ public class GitReceiveHook implements PreReceiveHook, PostReceiveHook
*/ */
private void sendError(ReceivePack rpack, ReceiveCommand rc, String message) private void sendError(ReceivePack rpack, ReceiveCommand rc, String message)
{ {
rpack.sendError(PREFIX_MSG.concat(Util.nonNull(message)));
rc.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON); rc.setResult(ReceiveCommand.Result.REJECTED_OTHER_REASON);
rpack.sendError(PREFIX_MSG.concat(Util.nonNull(message)));
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------