CherryPick: do not append new branch to empty topic

This is a bugfix for I195774b7f594553018e13101a6b3ce904249eed6.
When there is no topic set, we should not set a topic on cherry-picking.

Users reported changes with no topic set, which were cherry-picked to have
the topic "null-${new-branch}" afterwards, which is annoying specially with
the new submit whole topic feature enabled as lots of unrelated changes
end up in the new topic.

Change-Id: Ice42d1e6cfbbf12dc3936bb2a0295df8b9e0907c
This commit is contained in:
Stefan Beller
2015-05-21 10:07:11 -07:00
committed by Dave Borowitz
parent c30195009f
commit c48851eb4c
2 changed files with 26 additions and 1 deletions

View File

@@ -179,6 +179,26 @@ public class RevisionIT extends AbstractDaemonTest {
cherry.current().submit();
}
@Test
public void cherryPickwithNoTopic() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master");
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.message = "it goes to stable branch";
gApi.projects()
.name(project.get())
.branch(in.destination)
.create(new BranchInput());
ChangeApi orig = gApi.changes()
.id(project.get() + "~master~" + r.getChangeId());
ChangeApi cherry = orig.revision(r.getCommit().name())
.cherryPick(in);
assertThat(cherry.get().topic).isNull();
cherry.current().review(ReviewInput.approve());
cherry.current().submit();
}
@Test
public void cherryPickToSameBranch() throws Exception {
PushOneCommit.Result r = createChange();

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.server.change;
import com.google.common.base.Strings;
import com.google.gerrit.common.FooterConstants;
import com.google.gerrit.common.TimeUtil;
import com.google.gerrit.reviewdb.client.Branch;
@@ -182,9 +183,13 @@ public class CherryPickChange {
} else {
// Change key not found on destination branch. We can create a new
// change.
String newTopic = null;
if (!Strings.isNullOrEmpty(change.getTopic())) {
newTopic = change.getTopic() + "-" + newDest.getShortName();
}
Change newChange = createNewChange(git, revWalk, changeKey, project,
destRef, cherryPickCommit, refControl,
identifiedUser, change.getTopic() + "-" + newDest.getShortName());
identifiedUser, newTopic);
addMessageToSourceChange(change, patch.getId(), destinationBranch,
cherryPickCommit, identifiedUser, refControl);