Skip to content

Commit 37bc077

Browse files
committed
Status changed back to NEW, if build cannot be updated to target branch
When a passed build cannot be updated to target branch, related changes updated back to NEW status. Change-Id: I3a8cc34e24bf0d52aa94c5d937c422b4c8050c4a Fixes: QTQAINFRA-3110 Reviewed-by: Paul Wicking <[email protected]> Reviewed-by: Frederik Gladhorn <[email protected]>
1 parent b0a49a5 commit 37bc077

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ private void approveBuildChanges() throws QtUtil.MergeConflictException, NoSuchR
212212

213213
ObjectId oldId = git.resolve(destBranchKey.get());
214214

215-
QtUtil.mergeBranches(user.asIdentifiedUser(), git, buildBranchKey, destBranchKey);
215+
Result result = QtUtil.mergeBranches(user.asIdentifiedUser(), git, buildBranchKey, destBranchKey);
216+
217+
if (result != Result.FAST_FORWARD) {
218+
message = "Branch update failed, changed back to NEW. Either the destination branch was changed externally, or this is an issue in the Qt plugin.";
219+
rejectBuildChanges();
220+
return;
221+
}
216222

217223
updateChanges(affectedChanges, Change.Status.MERGED, null,
218224
message, ChangeMessagesUtil.TAG_MERGED, true);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ private static RefUpdate.Result mergeObjectToBranch(IdentifiedUser user,
589589
RefUpdate refUpdate = git.updateRef(destination.get());
590590
refUpdate.setNewObjectId(mergeCommit);
591591
return refUpdate.update();
592+
} catch (Exception e) {
593+
logger.atWarning().log("qtcodereview: merge failed, %s", e);
594+
return null;
592595
} finally {
593596
revWalk.dispose();
594597
}

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,45 @@ public void errorApproveBuild_NonExistingBuild() throws Exception {
195195
assertThat(resultStr).contains("build not found");
196196
}
197197

198+
@Test
199+
public void errorApproveBuild_FastForwardFail() throws Exception {
200+
RevCommit initialHead = getRemoteHead();
201+
PushOneCommit.Result c = pushCommit("master", "commitmsg1", "file1", "content1");
202+
approve(c.getChangeId());
203+
QtStage(c);
204+
QtNewBuild("master", "test-build-605");
205+
206+
// direct push that causes fast forward failure
207+
testRepo.reset(initialHead);
208+
PushOneCommit.Result d = pushCommit("master", "commitmsg2", "file2", "content2");
209+
approve(d.getChangeId());
210+
gApi.changes().id(d.getChangeId()).current().submit();
211+
RevCommit branchHead = getRemoteHead();
212+
213+
214+
String stagingRef = R_STAGING + "master";
215+
String branchRef = R_HEADS + "master";
216+
String commandStr;
217+
commandStr ="gerrit-plugin-qt-workflow staging-approve";
218+
commandStr += " --project " + project.get();
219+
commandStr += " --branch master";
220+
commandStr += " --build-id test-build-605";
221+
commandStr += " --result pass";
222+
commandStr += " --message " + MERGED_MSG;
223+
adminSshSession.exec(commandStr);
224+
assertThat(adminSshSession.getError()).isNull();
225+
226+
RevCommit updatedHead = getRemoteHead(project, branchRef);
227+
assertThat(updatedHead).isEqualTo(branchHead); // master is not updated
228+
RevCommit stagingHead = getRemoteHead(project, stagingRef);
229+
assertThat(stagingHead).isEqualTo(branchHead); // staging is updated to branch head
230+
231+
Change change = c.getChange().change();
232+
assertThat(change.getStatus()).isEqualTo(Change.Status.NEW);
233+
change = d.getChange().change();
234+
assertThat(change.getStatus()).isEqualTo(Change.Status.MERGED);
235+
}
236+
198237
@Test
199238
public void approveBuild_MultiLineMessage() throws Exception {
200239
PushOneCommit.Result c = pushCommit("master", "commitmsg1", "file1", "content1");

0 commit comments

Comments
 (0)