MergeSuperSet: collect ancestors for new branches

When pushing changes to a new branch, we need to include all
the ancestors into the merge set.

Bug: issue 3518
Change-Id: I53e7905704328b0f2e637ba55efef80ead0b897b
This commit is contained in:
Stefan Beller
2015-08-12 10:10:21 -07:00
parent 6e66b089f9
commit fff80eaa35
2 changed files with 28 additions and 7 deletions

View File

@@ -23,8 +23,10 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.GitUtil;
import com.google.gerrit.extensions.client.SubmitType;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.server.git.ProjectConfig;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -120,6 +122,28 @@ public class SubmittedTogetherIT extends AbstractDaemonTest {
}
}
@Test
public void testNewBranchTwoChangesTogether() throws Exception {
Project.NameKey p1 = createProject("a-new-project", null, false);
TestRepository<?> repo1 = cloneProject(p1);
RevCommit c1 = repo1.branch("HEAD").commit().insertChangeId()
.add("a.txt", "1")
.message("subject: 1")
.create();
String id1 = GitUtil.getChangeId(repo1, c1).get();
pushHead(repo1, "refs/for/master", false);
RevCommit c2 = repo1.branch("HEAD").commit().insertChangeId()
.add("b.txt", "2")
.message("subject: 2")
.create();
String id2 = GitUtil.getChangeId(repo1, c2).get();
pushHead(repo1, "refs/for/master", false);
assertSubmittedTogether(id1);
assertSubmittedTogether(id2, id2, id1);
}
@Test
public void testCherryPickWithoutAncestors() throws Exception {
ProjectConfig cfg = projectCache.checkedGet(project).getConfig();

View File

@@ -119,17 +119,14 @@ public class MergeSuperSet {
Branch.NameKey destBranch = cd.change().getDest();
repo.getRefDatabase().refresh();
Ref ref = repo.getRefDatabase().getRef(destBranch.get());
if (ref == null) {
ret.add(cd.change());
// A new empty branch doesn't have additional changes
continue;
}
rw.reset();
rw.sort(RevSort.TOPO);
rw.markStart(commit);
RevCommit head = rw.parseCommit(ref.getObjectId());
rw.markUninteresting(head);
if (ref != null) {
RevCommit head = rw.parseCommit(ref.getObjectId());
rw.markUninteresting(head);
}
List<String> hashes = new ArrayList<>();
for (RevCommit c : rw) {