]> source.dussan.org Git - jgit.git/commitdiff
Reject non-fast-forwards earlier in BaseReceivePack 84/6084/1
authorShawn O. Pearce <spearce@spearce.org>
Tue, 22 May 2012 22:59:53 +0000 (15:59 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 22 May 2012 23:28:34 +0000 (16:28 -0700)
If BaseReceivePack has setAllowNonFastForwards(false) configured
(such as by receive.denynonfastforwards), automatically reject
any command that attempts a non-fast-forward update before it goes
further in processing.

This matches with other checks in validateCommands(), such as the
early failure of delete attempts when isAllowDeletes() is false.

Change-Id: I3bb28e4dd6d17cb31ede09eb84ceb67cdb17ea5d

org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java

index c0d44b1db93679b6384fa250f0e76bb7abf8b28b..a0b1c58c67c9a56b181a1d487ea31f1974bdf702 100644 (file)
@@ -1100,6 +1100,12 @@ public abstract class BaseReceivePack {
                                } else {
                                        cmd.setType(ReceiveCommand.Type.UPDATE_NONFASTFORWARD);
                                }
+
+                               if (cmd.getType() == ReceiveCommand.Type.UPDATE_NONFASTFORWARD
+                                               && !isAllowNonFastForwards()) {
+                                       cmd.setResult(Result.REJECTED_NONFASTFORWARD);
+                                       continue;
+                               }
                        }
 
                        if (!cmd.getRefName().startsWith(Constants.R_REFS)
@@ -1123,8 +1129,10 @@ public abstract class BaseReceivePack {
 
        /** Execute commands to update references. */
        protected void executeCommands() {
-               List<ReceiveCommand> toApply = ReceiveCommand.filter(commands,
-                               Result.NOT_ATTEMPTED);
+               List<ReceiveCommand> toApply = filterCommands(Result.NOT_ATTEMPTED);
+               if (toApply.isEmpty())
+                       return;
+
                ProgressMonitor updating = NullProgressMonitor.INSTANCE;
                if (sideBand) {
                        SideBandProgressMonitor pm = new SideBandProgressMonitor(msgOut);