Clarify and test Change-Id behavior for cherry-pick
Change-Id: Ib5302ad4b97dd799d725bd94ae3b53835c6eaa32
diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt
index e316671..85fcfd9 100644
--- a/Documentation/rest-api-changes.txt
+++ b/Documentation/rest-api-changes.txt
@@ -4786,7 +4786,8 @@
Cherry picks a revision to a destination branch.
The commit message and destination branch must be provided in the request body inside a
-link:#cherrypick-input[CherryPickInput] entity.
+link:#cherrypick-input[CherryPickInput] entity. If the commit message
+does not specify a Change-Id, a new one is picked for the destination change.
.Request
----
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/revision/RevisionIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/revision/RevisionIT.java
index 577634e..7be0b024 100644
--- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/revision/RevisionIT.java
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/revision/RevisionIT.java
@@ -326,6 +326,28 @@
}
@Test
+ public void cherryPickSetChangeId() throws Exception {
+ PushOneCommit.Result r = pushTo("refs/for/master");
+ CherryPickInput in = new CherryPickInput();
+ in.destination = "foo";
+ String id = "Ideadbeefdeadbeefdeadbeefdeadbeefdeadbe3f";
+ in.message = "it goes to foo branch\n\nChange-Id: " + id;
+
+ gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
+ ChangeApi orig = gApi.changes().id(project.get() + "~master~" + r.getChangeId());
+
+ assertThat(orig.get().messages).hasSize(1);
+ ChangeApi cherry = orig.revision(r.getCommit().name()).cherryPick(in);
+
+ ChangeInfo changeInfo = cherry.get();
+
+ // The cherry-pick honors the ChangeId specified in the input message:
+ RevisionInfo revInfo = changeInfo.revisions.get(changeInfo.currentRevision);
+ assertThat(revInfo).isNotNull();
+ assertThat(revInfo.commit.message).endsWith(id + "\n");
+ }
+
+ @Test
public void cherryPickwithNoTopic() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master");
CherryPickInput in = new CherryPickInput();