Fix the wrong order of RevWalk.isMergedInto in RebaseSorter

RevWalk.isMergedInto takes the base as first argument and the tip as
the second argument to check if the base is merged into the tip. The
test didn't detect it because in the test the base is the same as the
tip.

Also add a regression test for this bug.

Change-Id: I43742aa4bd75ea64e729c1d3ecf40369002c7e55
This commit is contained in:
Zhen Chen 2017-03-30 11:11:39 -07:00
parent 62e6711dcd
commit 15e9a266b3
2 changed files with 44 additions and 2 deletions

View File

@ -333,6 +333,48 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
assertThat(log).contains(mergeReview.getCommit());
}
@Test
public void submitMergeOfNonChangeBranchNonTip() throws Exception {
// Merge a branch with commits that have not been submitted as
// changes.
//
// MC -- merge commit (pushed for review and submitted)
// |\ S2 -- new stable tip (pushed directly to refs/heads/stable)
// M \ /
// | S1 -- stable (pushed directly to refs/heads/stable)
// | /
// I -- master
//
RevCommit initial = getRemoteHead(project, "master");
// push directly to stable to S1
PushOneCommit.Result s1 = pushFactory.create(
db, admin.getIdent(), testRepo, "new commit into stable", "stable1.txt", "")
.to("refs/heads/stable");
// move the stable tip ahead to S2
pushFactory.create(
db, admin.getIdent(), testRepo, "Tip of branch stable", "stable2.txt", "")
.to("refs/heads/stable");
testRepo.reset(initial);
// move the master ahead
PushOneCommit.Result m = pushFactory.create(
db, admin.getIdent(), testRepo, "Move master ahead", "master.txt", "")
.to("refs/heads/master");
// create merge change
PushOneCommit mc =
pushFactory.create(db, admin.getIdent(), testRepo, "The merge commit", "merge.txt", "");
mc.setParents(ImmutableList.of(m.getCommit(), s1.getCommit()));
PushOneCommit.Result mergeReview = mc.to("refs/for/master");
approve(mergeReview.getChangeId());
submit(mergeReview.getChangeId());
List<RevCommit> log = getRemoteLog();
assertThat(log).contains(s1.getCommit());
assertThat(log).contains(mergeReview.getCommit());
}
private void assertSubmitter(PushOneCommit.Result change) throws Exception {
ChangeInfo info = get(change.getChangeId(), ListChangesOption.MESSAGES);
assertThat(info.messages).isNotNull();

View File

@ -94,8 +94,8 @@ public class RebaseSorter {
mirw.reset();
mirw.markStart(commit);
for (RevCommit accepted : alreadyAccepted) {
if (mirw.isMergedInto(mirw.parseCommit(accepted),
mirw.parseCommit(commit))) {
if (mirw.isMergedInto(mirw.parseCommit(commit),
mirw.parseCommit(accepted))) {
return true;
}
}