Merge "Don't enforce maximum number of files on direct pushes"
This commit is contained in:
		@@ -403,6 +403,17 @@ public class CommitValidators {
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<CommitValidationMessage> onCommitReceived(CommitReceivedEvent receiveEvent)
 | 
			
		||||
        throws CommitValidationException {
 | 
			
		||||
      // TODO(zieren): Refactor interface to signal the intent of the event instead of hard-coding
 | 
			
		||||
      // it here. Due to interface limitations, this method is called from both receive commits
 | 
			
		||||
      // and from main Gerrit (e.g. when publishing a change edit). This is why we need to gate the
 | 
			
		||||
      // early return on REFS_CHANGES (though pushes to refs/changes are not possible).
 | 
			
		||||
      String refName = receiveEvent.command.getRefName();
 | 
			
		||||
      if (!refName.startsWith("refs/for/") && !refName.startsWith(RefNames.REFS_CHANGES)) {
 | 
			
		||||
        // This is a direct push bypassing review. We don't need to enforce any file-count limits
 | 
			
		||||
        // here.
 | 
			
		||||
        return Collections.emptyList();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      PatchListKey patchListKey =
 | 
			
		||||
          PatchListKey.againstBase(
 | 
			
		||||
              receiveEvent.commit.getId(), receiveEvent.commit.getParentCount());
 | 
			
		||||
 
 | 
			
		||||
@@ -29,6 +29,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
 | 
			
		||||
import com.google.gerrit.acceptance.ExtensionRegistry;
 | 
			
		||||
import com.google.gerrit.acceptance.ExtensionRegistry.Registration;
 | 
			
		||||
import com.google.gerrit.acceptance.PushOneCommit;
 | 
			
		||||
import com.google.gerrit.acceptance.config.GerritConfig;
 | 
			
		||||
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
 | 
			
		||||
import com.google.gerrit.common.data.Permission;
 | 
			
		||||
import com.google.gerrit.extensions.api.projects.BranchInput;
 | 
			
		||||
@@ -206,4 +207,22 @@ public class RefOperationValidationIT extends AbstractDaemonTest {
 | 
			
		||||
      r4.assertErrorStatus(UPDATE_NONFASTFORWARD.name());
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  @GerritConfig(name = "change.maxFiles", value = "0")
 | 
			
		||||
  public void dontEnforceFileCountForDirectPushes() throws Exception {
 | 
			
		||||
    PushOneCommit push =
 | 
			
		||||
        pushFactory.create(admin.newIdent(), testRepo, "change", "c.txt", "content");
 | 
			
		||||
    PushOneCommit.Result result = push.to("refs/heads/master");
 | 
			
		||||
    result.assertOkStatus();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  @GerritConfig(name = "change.maxFiles", value = "0")
 | 
			
		||||
  public void enforceFileCountLimitOnPushesForReview() throws Exception {
 | 
			
		||||
    PushOneCommit push =
 | 
			
		||||
        pushFactory.create(admin.newIdent(), testRepo, "change", "c.txt", "content");
 | 
			
		||||
    PushOneCommit.Result result = push.to("refs/for/master");
 | 
			
		||||
    result.assertErrorStatus("Exceeding maximum number of files per change");
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user