Merge "Apply layers on blank lines"
diff --git a/java/com/google/gerrit/server/IdentifiedUser.java b/java/com/google/gerrit/server/IdentifiedUser.java
index d45d329..b069e39 100644
--- a/java/com/google/gerrit/server/IdentifiedUser.java
+++ b/java/com/google/gerrit/server/IdentifiedUser.java
@@ -16,7 +16,6 @@
 
 import static com.google.common.base.MoreObjects.firstNonNull;
 import static com.google.common.collect.ImmutableSet.toImmutableSet;
-import static com.google.common.flogger.LazyArgs.lazy;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableSet;
@@ -422,13 +421,9 @@
     if (effectiveGroups == null) {
       if (authConfig.isIdentityTrustable(state().externalIds())) {
         effectiveGroups = groupBackend.membershipsOf(this);
-        logger.atFinest().log(
-            "Known groups of %s: %s", getLoggableName(), lazy(effectiveGroups::getKnownGroups));
       } else {
         effectiveGroups = registeredGroups;
-        logger.atFinest().log(
-            "%s has a non-trusted identity, falling back to %s as known groups",
-            getLoggableName(), lazy(registeredGroups::getKnownGroups));
+        logger.atFinest().log("%s has a non-trusted identity", getLoggableName());
       }
     }
     return effectiveGroups;
diff --git a/java/com/google/gerrit/server/restapi/change/Submit.java b/java/com/google/gerrit/server/restapi/change/Submit.java
index 0a47d62..36b859c 100644
--- a/java/com/google/gerrit/server/restapi/change/Submit.java
+++ b/java/com/google/gerrit/server/restapi/change/Submit.java
@@ -14,7 +14,6 @@
 
 package com.google.gerrit.server.restapi.change;
 
-import static com.google.common.collect.ImmutableList.toImmutableList;
 import static com.google.gerrit.git.ObjectIds.abbreviateName;
 import static com.google.gerrit.server.project.ProjectCache.illegalState;
 import static java.util.stream.Collectors.joining;
@@ -72,10 +71,10 @@
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import org.eclipse.jgit.errors.ConfigInvalidException;
@@ -100,6 +99,8 @@
       "Submit all ${topicSize} changes of the same topic "
           + "(${submitSize} changes including ancestors and other "
           + "changes related by topic)";
+  private static final String BLOCKED_HIDDEN_SUBMIT_TOOLTIP =
+      "This change depends on other hidden changes which are not ready";
   private static final String CLICK_FAILURE_TOOLTIP = "Clicking the button would fail";
   private static final String CHANGE_UNMERGEABLE = "Problems with integrating this change";
 
@@ -239,15 +240,48 @@
    */
   @Nullable
   private String problemsForSubmittingChangeset(ChangeData cd, ChangeSet cs, CurrentUser user) {
-    Optional<String> reason =
-        MergeOp.checkCommonSubmitProblems(cd.change(), cs, false, permissionBackend, user).stream()
-            .findFirst()
-            .map(MergeOp.ChangeProblem::getProblem);
-    if (reason.isPresent()) {
-      return reason.get();
-    }
-
     try {
+      if (cs.furtherHiddenChanges()) {
+        logger.atFine().log(
+            "Change %d cannot be submitted by user %s because it depends on hidden changes: %s",
+            cd.getId().get(), user.getLoggableName(), cs.nonVisibleChanges());
+        return BLOCKED_HIDDEN_SUBMIT_TOOLTIP;
+      }
+      for (ChangeData c : cs.changes()) {
+        Set<ChangePermission> can =
+            permissionBackend
+                .user(user)
+                .change(c)
+                .test(EnumSet.of(ChangePermission.READ, ChangePermission.SUBMIT));
+        if (!can.contains(ChangePermission.READ)) {
+          logger.atFine().log(
+              "Change %d cannot be submitted by user %s because it depends on change %d which the user cannot read",
+              cd.getId().get(), user.getLoggableName(), c.getId().get());
+          return BLOCKED_HIDDEN_SUBMIT_TOOLTIP;
+        }
+        if (!can.contains(ChangePermission.SUBMIT)) {
+          return "You don't have permission to submit change " + c.getId();
+        }
+        if (c.change().isWorkInProgress()) {
+          return "Change " + c.getId() + " is marked work in progress";
+        }
+        try {
+          // The data in the change index may be stale (e.g. if submit requirements have been
+          // changed). For that one change for which the submit action is computed, use the
+          // freshly loaded ChangeData instance 'cd' instead of the potentially stale ChangeData
+          // instance 'c' that was loaded from the index. This makes a difference if the ChangeSet
+          // 'cs' only contains this one single change. If the ChangeSet contains further changes
+          // those may still be stale.
+          MergeOp.checkSubmitRequirements(cd.getId().equals(c.getId()) ? cd : c);
+        } catch (ResourceConflictException e) {
+          return (c.getId() == cd.getId())
+              ? String.format("Change %s is not ready: %s", cd.getId(), e.getMessage())
+              : String.format(
+                  "Change %s must be submitted with change %s but %s is not ready: %s",
+                  cd.getId(), c.getId(), c.getId(), e.getMessage());
+        }
+      }
+
       if (!useMergeabilityCheck) {
         return null;
       }
@@ -264,7 +298,7 @@
         return "Problems with change(s): "
             + unmergeable.stream().map(c -> c.getId().toString()).collect(joining(", "));
       }
-    } catch (IOException e) {
+    } catch (PermissionBackendException | IOException e) {
       logger.atSevere().withCause(e).log("Error checking if change is submittable");
       throw new StorageException("Could not determine problems for the change", e);
     }
@@ -297,15 +331,6 @@
         mergeSuperSet
             .get()
             .completeChangeSet(cd.change(), resource.getUser(), /*includingTopicClosure= */ false);
-    // Replace potentially stale ChangeData for the current change with the fresher one.
-    cs =
-        new ChangeSet(
-            cs.changes().stream()
-                .map(csChange -> csChange.getId().equals(cd.getId()) ? cd : csChange)
-                .collect(toImmutableList()),
-            cs.nonVisibleChanges());
-    String submitProblems = problemsForSubmittingChangeset(cd, cs, resource.getUser());
-
     String topic = change.getTopic();
     int topicSize = 0;
     if (!Strings.isNullOrEmpty(topic)) {
@@ -313,6 +338,8 @@
     }
     boolean treatWithTopic = submitWholeTopic && !Strings.isNullOrEmpty(topic) && topicSize > 1;
 
+    String submitProblems = problemsForSubmittingChangeset(cd, cs, resource.getUser());
+
     if (submitProblems != null) {
       return new UiAction.Description()
           .setLabel(treatWithTopic ? submitTopicLabel : (cs.size() > 1) ? labelWithParents : label)
diff --git a/java/com/google/gerrit/server/submit/MergeMetrics.java b/java/com/google/gerrit/server/submit/MergeMetrics.java
index ed07f2f..b56d9ef 100644
--- a/java/com/google/gerrit/server/submit/MergeMetrics.java
+++ b/java/com/google/gerrit/server/submit/MergeMetrics.java
@@ -54,36 +54,32 @@
                 .setRate());
   }
 
-  public void countChangesThatWereSubmittedWithRebaserApproval(ChangeSet cs) {
-    for (ChangeData cd : cs.changes()) {
-      if (isRebaseOnBehalfOfUploader(cd)
-          && hasCodeReviewApprovalOfRealUploader(cd)
-          && !hasCodeReviewApprovalOfUserThatIsNotTheRealUploader(cd)
-          && ignoresCodeReviewApprovalsOfUploader(cd)) {
-        // 1. The patch set that is being submitted was created by rebasing on behalf of the
-        // uploader.
-        //
-        // The uploader of the patch set is the original uploader on whose behalf the rebase was
-        // done. The real uploader is the user that did the rebase on behalf of the uploader (e.g.
-        // by clicking on the rebase button).
-        //
-        // 2. The change has a Code-Review approval of the real uploader (aka the rebaser).
-        //
-        // 3. The change doesn't have a Code-Review approval of any other user (a user that is not
-        // the real uploader).
-        //
-        // 4. Code-Review approvals of the uploader are ignored.
-        //
-        // If instead of a rebase on behalf of the uploader a normal rebase would have been done the
-        // rebaser would have been the uploader of the patch set. In this case the Code-Review
-        // approval of the rebaser would not have counted since Code-Review approvals of the
-        // uploader are ignored.
-        //
-        // In this case we assume that the change would not be submittable if a normal rebase had
-        // been done. This is not always correct (e.g. if there are approvals of multiple reviewers)
-        // but it's good enough for the metric.
-        countChangesThatWereSubmittedWithRebaserApproval.increment();
-      }
+  public void countChangesThatWereSubmittedWithRebaserApproval(ChangeData cd) {
+    if (isRebaseOnBehalfOfUploader(cd)
+        && hasCodeReviewApprovalOfRealUploader(cd)
+        && !hasCodeReviewApprovalOfUserThatIsNotTheRealUploader(cd)
+        && ignoresCodeReviewApprovalsOfUploader(cd)) {
+      // 1. The patch set that is being submitted was created by rebasing on behalf of the uploader.
+      // The uploader of the patch set is the original uploader on whom's behalf the rebase was
+      // done. The real uploader is the user that did the rebase on behalf of the uploader (e.g. by
+      // clicking on the rebase button).
+      //
+      // 2. The change has a Code-Review approval of the real uploader (aka the rebaser).
+      //
+      // 3. The change doesn't have a Code-Review approval of any other user (a user that is not the
+      // real uploader).
+      //
+      // 4. Code-Review approvals of the uploader are ignored.
+      //
+      // If instead of a rebase on behalf of the uploader a normal rebase would have been done the
+      // rebaser would have been the uploader of the patch set. In this case the Code-Review
+      // approval of the rebaser would not have counted since Code-Review approvals of the uploader
+      // are ignored.
+      //
+      // In this case we assume that the change would not be submittable if a normal rebase had been
+      // done. This is not always correct (e.g. if there are approvals of multiple reviewers) but
+      // it's good enough for the metric.
+      countChangesThatWereSubmittedWithRebaserApproval.increment();
     }
   }
 
diff --git a/java/com/google/gerrit/server/submit/MergeOp.java b/java/com/google/gerrit/server/submit/MergeOp.java
index 233f00e..eb41690 100644
--- a/java/com/google/gerrit/server/submit/MergeOp.java
+++ b/java/com/google/gerrit/server/submit/MergeOp.java
@@ -69,7 +69,6 @@
 import com.google.gerrit.metrics.MetricMaker;
 import com.google.gerrit.server.ChangeMessagesUtil;
 import com.google.gerrit.server.ChangeUtil;
-import com.google.gerrit.server.CurrentUser;
 import com.google.gerrit.server.IdentifiedUser;
 import com.google.gerrit.server.InternalUser;
 import com.google.gerrit.server.change.NotifyResolver;
@@ -84,8 +83,6 @@
 import com.google.gerrit.server.logging.TraceContext;
 import com.google.gerrit.server.notedb.ChangeNotes;
 import com.google.gerrit.server.notedb.StoreSubmitRequirementsOp;
-import com.google.gerrit.server.permissions.ChangePermission;
-import com.google.gerrit.server.permissions.PermissionBackend;
 import com.google.gerrit.server.permissions.PermissionBackendException;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gerrit.server.project.ProjectCache;
@@ -115,7 +112,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Deque;
-import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
@@ -296,7 +292,6 @@
   private final ChangeData.Factory changeDataFactory;
   private final StoreSubmitRequirementsOp.Factory storeSubmitRequirementsOpFactory;
   private final MergeMetrics mergeMetrics;
-  private final PermissionBackend permissionBackend;
 
   // Changes that were updated by this MergeOp.
   private final Map<Change.Id, Change> updatedChanges;
@@ -341,8 +336,7 @@
       MergeMetrics mergeMetrics,
       ProjectCache projectCache,
       ExperimentFeatures experimentFeatures,
-      @GerritServerConfig Config config,
-      PermissionBackend permissionBackend) {
+      @GerritServerConfig Config config) {
     this.cmUtil = cmUtil;
     this.batchUpdateFactory = batchUpdateFactory;
     this.batchUpdates = batchUpdates;
@@ -368,7 +362,6 @@
     hasImplicitMergeTimeoutSeconds =
         ConfigUtil.getTimeUnit(
             config, "change", null, "implicitMergeCalculationTimeout", 60, TimeUnit.SECONDS);
-    this.permissionBackend = permissionBackend;
   }
 
   @Override
@@ -378,12 +371,6 @@
     }
   }
 
-  /**
-   * Check that SRs are fulfilled or throw otherwise
-   *
-   * @param cd change that is being checked
-   * @throws ResourceConflictException the exception that is thrown if the SR is not fulfilled
-   */
   public static void checkSubmitRequirements(ChangeData cd) throws ResourceConflictException {
     PatchSet patchSet = cd.currentPatchSet();
     if (patchSet == null) {
@@ -438,119 +425,32 @@
     return cd.submitRecords(submitRuleOptions(/* allowClosed= */ false));
   }
 
-  @AutoValue
-  public abstract static class ChangeProblem {
-    public abstract Change.Id getChangeId();
-
-    public abstract String getProblem();
-
-    public static ChangeProblem create(Change.Id changeId, String problem) {
-      return new AutoValue_MergeOp_ChangeProblem(changeId, problem);
-    }
-  }
-
-  /**
-   * Returns a list of messages describing what prevents the current change from being submitted.
-   *
-   * <p>The method checks all changes in the {@code cs} for their current status, submitability and
-   * permissions.
-   *
-   * @param triggeringChange Change for which merge/submit action was initiated
-   * @param cs Set of changes that the current change depends on
-   * @param allowMerged True if change being already merged is not a problem to be reported
-   * @param permissionBackend Interface for checking user ACLs
-   * @param caller The user who is triggering a merge
-   * @return List of problems preventing merge
-   */
-  public static ImmutableList<ChangeProblem> checkCommonSubmitProblems(
-      Change triggeringChange,
-      ChangeSet cs,
-      boolean allowMerged,
-      PermissionBackend permissionBackend,
-      CurrentUser caller) {
-    ImmutableList.Builder<ChangeProblem> problems = ImmutableList.builder();
-    if (cs.furtherHiddenChanges()) {
-      logger.atFine().log(
-          "Change %d cannot be submitted by user %s because it depends on hidden changes: %s",
-          triggeringChange.getId().get(), caller.getLoggableName(), cs.nonVisibleChanges());
-      problems.add(
-          ChangeProblem.create(
-              triggeringChange.getId(),
-              String.format(
-                  "Change %d depends on other hidden changes", triggeringChange.getId().get())));
-    }
+  private void checkSubmitRulesAndState(ChangeSet cs, boolean allowMerged)
+      throws ResourceConflictException {
+    checkArgument(
+        !cs.furtherHiddenChanges(), "checkSubmitRulesAndState called for topic with hidden change");
     for (ChangeData cd : cs.changes()) {
       try {
-        Set<ChangePermission> can =
-            permissionBackend
-                .user(caller)
-                .change(cd)
-                .test(EnumSet.of(ChangePermission.READ, ChangePermission.SUBMIT));
-        if (!can.contains(ChangePermission.READ)) {
-          // The READ permission should already be handled during generation of ChangeSet, however
-          // MergeSuperSetComputation is an interface and on API level doesn't guarantee that this
-          // have been verified for all changes. Additionally, this protects against potential
-          // issues due to staleness.
-          logger.atFine().log(
-              "Change %d cannot be submitted by user %s because it depends on change %d which the"
-                  + "user cannot read",
-              triggeringChange.getId().get(), caller.getLoggableName(), cd.getId().get());
-          problems.add(
-              ChangeProblem.create(
-                  cd.getId(),
-                  String.format(
-                      "Change %d depends on other hidden changes",
-                      triggeringChange.getId().get())));
-        } else if (!can.contains(ChangePermission.SUBMIT)) {
-          logger.atFine().log(
-              "Change %d cannot be submitted by user %s because it depends on change %d which the"
-                  + "user cannot submit",
-              triggeringChange.getId().get(), caller.getLoggableName(), cd.getId().get());
-          problems.add(
-              ChangeProblem.create(
-                  cd.getId(),
-                  String.format("Insufficient permission to submit change %d", cd.getId().get())));
-        } else if (!cd.change().isNew()) {
+        if (!cd.change().isNew()) {
           if (!(cd.change().isMerged() && allowMerged)) {
-            problems.add(
-                ChangeProblem.create(
-                    cd.getId(),
-                    String.format(
-                        "Change %d is %s", cd.getId().get(), ChangeUtil.status(cd.change()))));
+            commitStatus.problem(
+                cd.getId(), "Change " + cd.getId() + " is " + ChangeUtil.status(cd.change()));
           }
         } else if (cd.change().isWorkInProgress()) {
-          problems.add(
-              ChangeProblem.create(
-                  cd.getId(),
-                  String.format("Change %d is marked work in progress", cd.getId().get())));
+          commitStatus.problem(cd.getId(), "Change " + cd.getId() + " is work in progress");
         } else {
           checkSubmitRequirements(cd);
+          mergeMetrics.countChangesThatWereSubmittedWithRebaserApproval(cd);
         }
       } catch (ResourceConflictException e) {
-        // Exception is thrown means submit requirement is not fulfilled.
-        problems.add(
-            ChangeProblem.create(
-                cd.getId(),
-                triggeringChange.getId().equals(cd.getId())
-                    ? String.format("Change %s is not ready: %s", cd.getId(), e.getMessage())
-                    : String.format(
-                        "Change %s must be submitted with change %s but %s is not ready: %s",
-                        triggeringChange.getId(), cd.getId(), cd.getId(), e.getMessage())));
-      } catch (StorageException | PermissionBackendException e) {
+        commitStatus.problem(cd.getId(), e.getMessage());
+      } catch (StorageException e) {
         String msg = "Error checking submit rules for change";
-        logger.atWarning().withCause(e).log("%s %s", msg, triggeringChange.getId());
-        problems.add(ChangeProblem.create(cd.getId(), msg));
+        logger.atWarning().withCause(e).log("%s %s", msg, cd.getId());
+        commitStatus.problem(cd.getId(), msg);
       }
     }
-    return problems.build();
-  }
-
-  private void checkSubmitRulesAndState(Change triggeringChange, ChangeSet cs, boolean allowMerged)
-      throws ResourceConflictException {
-    checkCommonSubmitProblems(triggeringChange, cs, allowMerged, permissionBackend, caller).stream()
-        .forEach(cp -> commitStatus.problem(cp.getChangeId(), cp.getProblem()));
     commitStatus.maybeFailVerbose();
-    mergeMetrics.countChangesThatWereSubmittedWithRebaserApproval(cs);
   }
 
   private void bypassSubmitRulesAndRequirements(ChangeSet cs) {
@@ -680,7 +580,7 @@
                       this.commitStatus = new CommitStatus(filteredNoteDbChangeSet, isRetry);
                       if (checkSubmitRules) {
                         logger.atFine().log("Checking submit rules and state");
-                        checkSubmitRulesAndState(change, filteredNoteDbChangeSet, isRetry);
+                        checkSubmitRulesAndState(filteredNoteDbChangeSet, isRetry);
                       } else {
                         logger.atFine().log("Bypassing submit rules");
                         bypassSubmitRulesAndRequirements(filteredNoteDbChangeSet);
diff --git a/javatests/com/google/gerrit/acceptance/api/change/DefaultSubmitRequirementsIT.java b/javatests/com/google/gerrit/acceptance/api/change/DefaultSubmitRequirementsIT.java
index 9af7a2d..fc8eaed 100644
--- a/javatests/com/google/gerrit/acceptance/api/change/DefaultSubmitRequirementsIT.java
+++ b/javatests/com/google/gerrit/acceptance/api/change/DefaultSubmitRequirementsIT.java
@@ -41,8 +41,7 @@
         .isEqualTo(
             String.format(
                 "Failed to submit 1 change due to the following problems:\n"
-                    + "Change %1$s: Change %1$s is not ready: "
-                    + "submit requirement 'No-Unresolved-Comments' is unsatisfied.",
+                    + "Change %s: submit requirement 'No-Unresolved-Comments' is unsatisfied.",
                 r.getChange().getId().get()));
 
     // Resolve the comment and check that the change can be submitted now.
diff --git a/javatests/com/google/gerrit/acceptance/rest/change/AbstractSubmit.java b/javatests/com/google/gerrit/acceptance/rest/change/AbstractSubmit.java
index 0b86406..25af040 100644
--- a/javatests/com/google/gerrit/acceptance/rest/change/AbstractSubmit.java
+++ b/javatests/com/google/gerrit/acceptance/rest/change/AbstractSubmit.java
@@ -589,7 +589,7 @@
             + num
             + ": Change "
             + num
-            + " is marked work in progress");
+            + " is work in progress");
   }
 
   @Test
@@ -607,7 +607,7 @@
               + num
               + ": Change "
               + num
-              + " is marked work in progress");
+              + " is work in progress");
     }
   }
 
diff --git a/javatests/com/google/gerrit/acceptance/rest/change/SubmitByFastForwardIT.java b/javatests/com/google/gerrit/acceptance/rest/change/SubmitByFastForwardIT.java
index 5f1a982..1d8e0b8 100644
--- a/javatests/com/google/gerrit/acceptance/rest/change/SubmitByFastForwardIT.java
+++ b/javatests/com/google/gerrit/acceptance/rest/change/SubmitByFastForwardIT.java
@@ -95,15 +95,12 @@
     PushOneCommit.Result change2 = createChange();
 
     Change.Id id1 = change1.getPatchSetId().changeId();
-    Change.Id id2 = change2.getPatchSetId().changeId();
     submitWithConflict(
         change2.getChangeId(),
-        String.format(
-            "Failed to submit 2 changes due to the following problems:\n"
-                + "Change %d"
-                + ": Change %d must be submitted with change %d but %d is not ready: "
-                + "submit requirement 'Code-Review' is unsatisfied.",
-            id1.get(), id2.get(), id1.get(), id1.get()));
+        "Failed to submit 2 changes due to the following problems:\n"
+            + "Change "
+            + id1
+            + ": submit requirement 'Code-Review' is unsatisfied.");
 
     RevCommit updatedHead = projectOperations.project(project).getHead("master");
     assertThat(updatedHead.getId()).isEqualTo(initialHead.getId());
diff --git a/javatests/com/google/gerrit/acceptance/server/change/SubmittedTogetherIT.java b/javatests/com/google/gerrit/acceptance/server/change/SubmittedTogetherIT.java
index 4ee5967..5a4f073 100644
--- a/javatests/com/google/gerrit/acceptance/server/change/SubmittedTogetherIT.java
+++ b/javatests/com/google/gerrit/acceptance/server/change/SubmittedTogetherIT.java
@@ -16,10 +16,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.gerrit.acceptance.GitUtil.pushHead;
-import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block;
 import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.NON_VISIBLE_CHANGES;
-import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
-import static com.google.gerrit.testing.GerritJUnit.assertThrows;
 
 import com.google.gerrit.acceptance.AbstractDaemonTest;
 import com.google.gerrit.acceptance.GitUtil;
@@ -28,8 +25,6 @@
 import com.google.gerrit.acceptance.config.GerritConfig;
 import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
 import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
-import com.google.gerrit.entities.BranchNameKey;
-import com.google.gerrit.entities.Permission;
 import com.google.gerrit.entities.Project;
 import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo;
 import com.google.gerrit.extensions.client.ChangeStatus;
@@ -37,7 +32,6 @@
 import com.google.gerrit.extensions.client.SubmitType;
 import com.google.gerrit.extensions.common.FileInfo;
 import com.google.gerrit.extensions.common.RevisionInfo;
-import com.google.gerrit.extensions.restapi.ResourceConflictException;
 import com.google.gerrit.testing.ConfigSuite;
 import com.google.inject.Inject;
 import java.util.EnumSet;
@@ -342,41 +336,6 @@
     assertSubmittedTogether(id2, id2, id1);
   }
 
-  @Test
-  public void permissionToSubmitForSomeChangesInTopic() throws Exception {
-    projectOperations
-        .project(project)
-        .forUpdate()
-        .add(block(Permission.SUBMIT).ref("refs/heads/testbranch").group(REGISTERED_USERS))
-        .update();
-
-    createBranch(BranchNameKey.create(getProject(), "testbranch"));
-    RevCommit initialHead = projectOperations.project(project).getHead("master");
-    // Create two independent commits and push.
-    RevCommit c1_1 = commitBuilder().add("a.txt", "1").message("subject: 1").create();
-    String id1 = getChangeId(c1_1);
-    pushHead(testRepo, "refs/for/master%topic=" + name("connectingTopic"), false);
-
-    testRepo.reset(initialHead);
-    RevCommit c2_1 = commitBuilder().add("b.txt", "2").message("subject: 2").create();
-    String id2 = getChangeId(c2_1);
-    pushHead(testRepo, "refs/for/testbranch%topic=" + name("connectingTopic"), false);
-
-    approve(id1);
-    approve(id2);
-    if (isSubmitWholeTopicEnabled()) {
-      ResourceConflictException e =
-          assertThrows(ResourceConflictException.class, () -> submit(id1));
-      assertThat(e.getMessage())
-          .contains(
-              String.format(
-                  "Insufficient permission to submit change %d",
-                  gApi.changes().id(id2).get()._number));
-    } else {
-      submit(id1);
-    }
-  }
-
   private String getChangeId(RevCommit c) throws Exception {
     return GitUtil.getChangeId(testRepo, c).get();
   }