Iterating over received parent commits.

This commit is contained in:
Winston Li 2014-11-15 17:37:11 +00:00
parent 6d4309267e
commit ba7d0d318c

View file

@ -21,16 +21,19 @@ public class CheckNonFastForwardHook implements PreReceiveHook {
@Override @Override
public void onPreReceive(ReceivePack receivePack, Collection<ReceiveCommand> receiveCommands) { public void onPreReceive(ReceivePack receivePack, Collection<ReceiveCommand> receiveCommands) {
System.out.println("There are " + receiveCommands.size() + " receive commands.");
System.out.println("All commits: ");
System.out.println(receiveCommands);
for (ReceiveCommand receiveCommand : receiveCommands) { for (ReceiveCommand receiveCommand : receiveCommands) {
receiveCommand.setResult(RefUpdate.Result.REJECTED); // receiveCommand.setResult(RefUpdate.Result.REJECTED);
System.out.println(receiveCommand.getRef());
try { try {
System.out.println("Old: " + receiveCommand.getOldId());
System.out.println("New: " + receiveCommand.getNewId());
// a RevWalk allows to walk over commits based on some filtering that is // a RevWalk allows to walk over commits based on some filtering that is
// defined // defined
RevWalk walk = new RevWalk(receivePack.getRepository()); RevWalk walk = new RevWalk(receivePack.getRepository());
RevCommit commit = walk.parseCommit(receiveCommand.getNewId()); RevCommit commit = walk.parseCommit(receiveCommand.getNewId());
System.out.println("Parent commit: " + commit.getParents()[0].getId());
RevTree tree = commit.getTree(); RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree); System.out.println("Having tree: " + tree);