Prevent related changes when rebasing on the tip of a branch

In I4ef9cdef we unconditionally set the patch set groups of a
newly-created rebased patch set to the groups of whatever the base
change happened to be. For rebasing on an open (or even abandoned)
change, this is appropriate: rebase should add the new patch set to the
end of the related changes list. However, this also unintentionally
added to the relation chain when the change happened to be merged. In
this case, as when pushing a rebased change, the new patch set should be
the root of its own relation chain.

Change-Id: Ibe2718509af6fd55a46a88bc8fe73a12116cec98
This commit is contained in:
Dave Borowitz
2018-10-15 13:17:03 -07:00
parent bf580eed8b
commit c878015408
2 changed files with 12 additions and 14 deletions

View File

@@ -20,12 +20,14 @@ import com.google.gerrit.extensions.api.changes.NotifyHandling;
import com.google.gerrit.extensions.restapi.MergeConflictException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.RevId;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.change.RebaseUtil.Base;
import com.google.gerrit.server.git.GroupCollector;
import com.google.gerrit.server.git.MergeUtil;
import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.permissions.PermissionBackendException;
@@ -199,8 +201,14 @@ public class RebaseChangeOp implements BatchUpdateOp {
+ " was rebased");
}
if (base != null) {
patchSetInserter.setGroups(base.patchSet().getGroups());
if (base != null && base.notes().getChange().getStatus() != Change.Status.MERGED) {
if (base.notes().getChange().getStatus() != Change.Status.MERGED) {
// Add to end of relation chain for open base change.
patchSetInserter.setGroups(base.patchSet().getGroups());
} else {
// If the base is merged, start a new relation chain.
patchSetInserter.setGroups(GroupCollector.getDefaultGroups(rebasedCommit));
}
}
patchSetInserter.updateRepo(ctx);
}