Skip to content

Commit 00a1b53

Browse files
vs-systencessjujokini
authored andcommitted
Avoid double handling of change(s) on merge of merge
A change was included twice to the batch update. This caused exception on staging approve and changes were left on 'integrating' status. Fixes: QTQAINFRA-3379 Change-Id: I776f942ee54351e1e9478d631a189728d5fbc658 Reviewed-by: Jukka Jokiniva <[email protected]>
1 parent 731ba87 commit 00a1b53

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/main/java/com/googlesource/gerrit/plugins/qtcodereview/QtUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import java.sql.Timestamp;
4141
import java.util.AbstractMap;
4242
import java.util.ArrayList;
43+
import java.util.HashMap;
4344
import java.util.Iterator;
4445
import java.util.List;
4546
import java.util.Map;
@@ -512,8 +513,7 @@ public List<Map.Entry<ChangeData, RevCommit>> listChangesNotMerged(
512513
Repository git, final Branch.NameKey branch, final Branch.NameKey destination)
513514
throws IOException, BranchNotFoundException {
514515

515-
List<Map.Entry<ChangeData, RevCommit>> result =
516-
new ArrayList<Map.Entry<ChangeData, RevCommit>>();
516+
Map<Change.Id, Map.Entry<ChangeData, RevCommit>> map = new HashMap<>();
517517
RevWalk revWalk = new RevWalk(git);
518518

519519
try {
@@ -542,13 +542,13 @@ public List<Map.Entry<ChangeData, RevCommit>> listChangesNotMerged(
542542
logger.atWarning().log(
543543
"qtcodereview: commit belongs to multiple changes: %s", commit.name());
544544
ChangeData cd = changes.get(0);
545-
result.add(new AbstractMap.SimpleEntry<ChangeData, RevCommit>(cd, commit));
545+
map.put(cd.getId(), new AbstractMap.SimpleEntry<ChangeData, RevCommit>(cd, commit));
546546
}
547547
}
548548
} finally {
549549
revWalk.dispose();
550550
}
551-
return result;
551+
return new ArrayList<Map.Entry<ChangeData, RevCommit>>(map.values());
552552
}
553553

554554
public static RevCommit merge(

src/test/java/com/googlesource/gerrit/plugins/qtcodereview/QtCommandBuildApproveIT.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,39 @@ public void cherryPicked_Stays_Intact_After_Merge_And_Build() throws Exception {
130130
assertThat(changes.id(project.get(), "master", cp.changeId).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.NEW);
131131
}
132132

133+
@Test
134+
public void avoid_Double_Handling_Of_Change_On_Merge_Of_Merge() throws Exception {
135+
// make a change on feature branch
136+
final PushOneCommit.Result f1 = pushCommit("feature", "f1-commitmsg", "f1-file", "f1-content");
137+
approve(f1.getChangeId());
138+
gApi.changes().id(f1.getCommit().getName()).current().submit();
139+
140+
// make a change on master branch
141+
final PushOneCommit.Result m1 = pushCommit("master", "m1-commitmsg", "m1-file", "m1-content");
142+
approve(m1.getChangeId());
143+
144+
// merge feature branch into master
145+
final PushOneCommit mm = pushFactory.create(admin.newIdent(), testRepo);
146+
mm.setParents(ImmutableList.of(f1.getCommit(), m1.getCommit()));
147+
final PushOneCommit.Result m = mm.to("refs/for/master");
148+
m.assertOkStatus();
149+
approve(m.getChangeId());
150+
151+
// Stage master branch change
152+
QtStage(m1);
153+
// Stage merge change
154+
QtStage(m);
155+
156+
// Create build and approve it
157+
QtNewBuild("master", "merge-build-000");
158+
QtApproveBuild("master", "merge-build-000");
159+
160+
final Changes changes = gApi.changes();
161+
assertThat(changes.id(project.get(), "feature", f1.getChangeId()).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.MERGED);
162+
assertThat(changes.id(project.get(), "master", m1.getChangeId()).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.MERGED);
163+
assertThat(changes.id(project.get(), "master", m.getChangeId()).get(CURRENT_REVISION).status).isEqualTo(ChangeStatus.MERGED);
164+
}
165+
133166
@Test
134167
public void multiChange_New_Staged_Integrating_Failed() throws Exception {
135168
// Push 3 independent commits

0 commit comments

Comments
 (0)