Don't add "This patchset was cherry picked to ..." for the same change If a patchset is cherry-picked to the same destination branch and ends up on the same change, it does not make sense to add the "This patchset was cherry picked to change ..." message. An example of when this can happen is when the user has a series of dependent changes under review, i.e.: Change 3 Change 2 Change 1 HEAD of master branch where "Change 3" has been code reviewed and accepted, but cannot be submitted because the preceding changes are still under review. The user wants to rebase Change 3 so it does not depend on 1 and 2, but instead of doing an interactive rebase locally and uploading a new patchset, uses the cherry-pick button to cherry-pick the latest patchset of Change 3 onto the HEAD of master. This results in a new patchset being created on the same change, which no longer has dependency on Change 2. In this case, it makes more sense for the message to say "Uploaded patch set N" instead of "This patchset was cherry picked to ... ". Change-Id: Ib512244073285005eb230f2a1ba372e427afd8fd
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPickChange.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPickChange.java index 2c20b03..1e748d9 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPickChange.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/CherryPickChange.java
@@ -193,10 +193,12 @@ PatchSet.Id patchSetId, RevCommit cherryPickCommit, RefControl refControl) throws InvalidChangeOperationException, IOException, OrmException, NoSuchChangeException { - patchSetInserterFactory - .create(git, revWalk, refControl, currentUser, change, cherryPickCommit) - .setMessage(buildChangeMessage(patchSetId, change)) - .insert(); + final PatchSetInserter inserter = patchSetInserterFactory + .create(git, revWalk, refControl, currentUser, change, cherryPickCommit); + final PatchSet.Id newPatchSetId = inserter.getPatchSetId(); + inserter + .setMessage("Uploaded patch set " + newPatchSetId.get() + ".") + .insert(); return change.getId(); }