From a65b695ee5232309f01304a1694dd5eacd04caf4 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 13 Dec 2012 19:28:34 +0900 Subject: [PATCH] Fix: SSH abandon or restore adds the cover message twice When a change is abandoned or restored over SSH, and a cover message is included with the --message option, the message is added on the review twice. First it is added with the review comment: Patch Set 1: Message And then again with the abandon/restore comment: Abandoned/Restored Message The review comment is added regardless of whether or not any review labels have been applied at the same time. Fix it so that the message is only added once. If review labels are applied, the message will be added with the regular review comment: Patch Set 1: Message And then the abandon/restore comment will be added without any message: Abandoned/Restored If there are no review labels applied, there will be no review comment, and the message will be added with the abandon/restore comment: Abandoned/Restored Message Bug: Issue 1721 Change-Id: I9c7e81599854a5d12656e41a29341e2938620a00 --- .../gerrit/sshd/commands/ReviewCommand.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java index 8b6ef08a06..9f4fcb72a6 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ReviewCommand.java @@ -195,9 +195,11 @@ public class ReviewCommand extends SshCommand { private void applyReview(final ChangeControl ctl, final PatchSet.Id patchSetId, final PostReview.Input review) throws Exception { - reviewProvider.get().apply(new RevisionResource( - new ChangeResource(ctl), - db.patchSets().get(patchSetId)), review); + if (!review.labels.isEmpty()) { + reviewProvider.get().apply(new RevisionResource( + new ChangeResource(ctl), + db.patchSets().get(patchSetId)), review); + } } private void approveOne(final PatchSet.Id patchSetId) throws Exception { @@ -218,6 +220,13 @@ public class ReviewCommand extends SshCommand { } } + // If review labels are being applied, the comment will be included + // on the review note. We don't need to add it again on the abandon + // or restore comment. + if (!review.labels.isEmpty()) { + changeComment = null; + } + try { ChangeControl ctl = changeControlFactory.controlFor(patchSetId.getParentKey());