Merge "Add topic to CherryPickInput"
This commit is contained in:
commit
de3a454d31
@ -6177,6 +6177,12 @@ Callers can find out if there were conflicts by checking the
|
|||||||
`contains_git_conflicts` field in the link:#change-info[ChangeInfo]. If
|
`contains_git_conflicts` field in the link:#change-info[ChangeInfo]. If
|
||||||
there are conflicts the cherry-pick change is marked as
|
there are conflicts the cherry-pick change is marked as
|
||||||
work-in-progress.
|
work-in-progress.
|
||||||
|
|`topic` |optional|
|
||||||
|
The topic of the created cherry-picked change. If not set, the default depends
|
||||||
|
on the source. If the source is a change with a topic, the resulting topic
|
||||||
|
of the cherry-picked change will be {source_change_topic}-{destination_branch}.
|
||||||
|
Otherwise, if the source change has no topic, or the source is a commit,
|
||||||
|
the created change will have no topic.
|
||||||
|===========================
|
|===========================
|
||||||
|
|
||||||
[[comment-info]]
|
[[comment-info]]
|
||||||
|
@ -29,4 +29,5 @@ public class CherryPickInput {
|
|||||||
|
|
||||||
public boolean keepReviewers;
|
public boolean keepReviewers;
|
||||||
public boolean allowConflicts;
|
public boolean allowConflicts;
|
||||||
|
public String topic;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,6 @@ public class CherryPickChange {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +216,6 @@ public class CherryPickChange {
|
|||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +233,6 @@ public class CherryPickChange {
|
|||||||
* @param ignoreIdenticalTree When false, we throw an error when trying to cherry-pick creates an
|
* @param ignoreIdenticalTree When false, we throw an error when trying to cherry-pick creates an
|
||||||
* empty commit. When true, we allow creation of an empty commit.
|
* empty commit. When true, we allow creation of an empty commit.
|
||||||
* @param timestamp the current timestamp.
|
* @param timestamp the current timestamp.
|
||||||
* @param topic Topic name for the change created.
|
|
||||||
* @param revertedChange The id of the change that is reverted. This is used for the "revertOf"
|
* @param revertedChange The id of the change that is reverted. This is used for the "revertOf"
|
||||||
* field to mark the created cherry pick change as "revertOf" the original change that was
|
* field to mark the created cherry pick change as "revertOf" the original change that was
|
||||||
* reverted.
|
* reverted.
|
||||||
@ -263,7 +260,6 @@ public class CherryPickChange {
|
|||||||
BranchNameKey dest,
|
BranchNameKey dest,
|
||||||
boolean ignoreIdenticalTree,
|
boolean ignoreIdenticalTree,
|
||||||
Timestamp timestamp,
|
Timestamp timestamp,
|
||||||
@Nullable String topic,
|
|
||||||
@Nullable Change.Id revertedChange,
|
@Nullable Change.Id revertedChange,
|
||||||
@Nullable ObjectId changeIdForNewChange,
|
@Nullable ObjectId changeIdForNewChange,
|
||||||
@Nullable Change.Id idForNewChange,
|
@Nullable Change.Id idForNewChange,
|
||||||
@ -381,8 +377,11 @@ public class CherryPickChange {
|
|||||||
} else {
|
} else {
|
||||||
// Change key not found on destination branch. We can create a new
|
// Change key not found on destination branch. We can create a new
|
||||||
// change.
|
// change.
|
||||||
String newTopic = topic;
|
String newTopic = null;
|
||||||
if (topic == null
|
if (input.topic != null) {
|
||||||
|
newTopic = Strings.emptyToNull(input.topic.trim());
|
||||||
|
}
|
||||||
|
if (newTopic == null
|
||||||
&& sourceChange != null
|
&& sourceChange != null
|
||||||
&& !Strings.isNullOrEmpty(sourceChange.getTopic())) {
|
&& !Strings.isNullOrEmpty(sourceChange.getTopic())) {
|
||||||
newTopic = sourceChange.getTopic() + "-" + newDest.shortName();
|
newTopic = sourceChange.getTopic() + "-" + newDest.shortName();
|
||||||
|
@ -20,6 +20,7 @@ import static com.google.gerrit.server.permissions.RefPermission.CREATE_CHANGE;
|
|||||||
import static com.google.gerrit.server.project.ProjectCache.illegalState;
|
import static com.google.gerrit.server.project.ProjectCache.illegalState;
|
||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ArrayListMultimap;
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.flogger.FluentLogger;
|
import com.google.common.flogger.FluentLogger;
|
||||||
@ -195,6 +196,9 @@ public class RevertSubmission
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String createTopic(String topic, String submissionId) {
|
private String createTopic(String topic, String submissionId) {
|
||||||
|
if (topic != null) {
|
||||||
|
topic = Strings.emptyToNull(topic.trim());
|
||||||
|
}
|
||||||
if (topic == null) {
|
if (topic == null) {
|
||||||
return String.format(
|
return String.format(
|
||||||
"revert-%s-%s", submissionId, RandomStringUtils.randomAlphabetic(10).toUpperCase());
|
"revert-%s-%s", submissionId, RandomStringUtils.randomAlphabetic(10).toUpperCase());
|
||||||
@ -321,12 +325,7 @@ public class RevertSubmission
|
|||||||
bu.addOp(
|
bu.addOp(
|
||||||
changeNotes.getChange().getId(),
|
changeNotes.getChange().getId(),
|
||||||
new CreateCherryPickOp(
|
new CreateCherryPickOp(
|
||||||
revCommitId,
|
revCommitId, generatedChangeId, cherryPickRevertChangeId, groupName, timestamp));
|
||||||
revertInput.topic,
|
|
||||||
generatedChangeId,
|
|
||||||
cherryPickRevertChangeId,
|
|
||||||
groupName,
|
|
||||||
timestamp));
|
|
||||||
bu.addOp(changeNotes.getChange().getId(), new PostRevertedMessageOp(generatedChangeId));
|
bu.addOp(changeNotes.getChange().getId(), new PostRevertedMessageOp(generatedChangeId));
|
||||||
bu.addOp(
|
bu.addOp(
|
||||||
cherryPickRevertChangeId,
|
cherryPickRevertChangeId,
|
||||||
@ -356,6 +355,7 @@ public class RevertSubmission
|
|||||||
cherryPickInput.notifyDetails = revertInput.notifyDetails;
|
cherryPickInput.notifyDetails = revertInput.notifyDetails;
|
||||||
cherryPickInput.parent = 1;
|
cherryPickInput.parent = 1;
|
||||||
cherryPickInput.keepReviewers = true;
|
cherryPickInput.keepReviewers = true;
|
||||||
|
cherryPickInput.topic = revertInput.topic;
|
||||||
return cherryPickInput;
|
return cherryPickInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,7 +570,6 @@ public class RevertSubmission
|
|||||||
|
|
||||||
private class CreateCherryPickOp implements BatchUpdateOp {
|
private class CreateCherryPickOp implements BatchUpdateOp {
|
||||||
private final ObjectId revCommitId;
|
private final ObjectId revCommitId;
|
||||||
private final String topic;
|
|
||||||
private final ObjectId computedChangeId;
|
private final ObjectId computedChangeId;
|
||||||
private final Change.Id cherryPickRevertChangeId;
|
private final Change.Id cherryPickRevertChangeId;
|
||||||
private final String groupName;
|
private final String groupName;
|
||||||
@ -578,13 +577,11 @@ public class RevertSubmission
|
|||||||
|
|
||||||
CreateCherryPickOp(
|
CreateCherryPickOp(
|
||||||
ObjectId revCommitId,
|
ObjectId revCommitId,
|
||||||
String topic,
|
|
||||||
ObjectId computedChangeId,
|
ObjectId computedChangeId,
|
||||||
Change.Id cherryPickRevertChangeId,
|
Change.Id cherryPickRevertChangeId,
|
||||||
String groupName,
|
String groupName,
|
||||||
Timestamp timestamp) {
|
Timestamp timestamp) {
|
||||||
this.revCommitId = revCommitId;
|
this.revCommitId = revCommitId;
|
||||||
this.topic = topic;
|
|
||||||
this.computedChangeId = computedChangeId;
|
this.computedChangeId = computedChangeId;
|
||||||
this.cherryPickRevertChangeId = cherryPickRevertChangeId;
|
this.cherryPickRevertChangeId = cherryPickRevertChangeId;
|
||||||
this.groupName = groupName;
|
this.groupName = groupName;
|
||||||
@ -604,7 +601,6 @@ public class RevertSubmission
|
|||||||
change.getProject(), RefNames.fullName(cherryPickInput.destination)),
|
change.getProject(), RefNames.fullName(cherryPickInput.destination)),
|
||||||
true,
|
true,
|
||||||
timestamp,
|
timestamp,
|
||||||
topic,
|
|
||||||
change.getId(),
|
change.getId(),
|
||||||
computedChangeId,
|
computedChangeId,
|
||||||
cherryPickRevertChangeId,
|
cherryPickRevertChangeId,
|
||||||
|
@ -169,6 +169,21 @@ public class CommitIT extends AbstractDaemonTest {
|
|||||||
assertThat(revInfo.commit.message).isEqualTo(input.message + "\n");
|
assertThat(revInfo.commit.message).isEqualTo(input.message + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cherryPickCommitWithSetTopic() throws Exception {
|
||||||
|
String branch = "foo";
|
||||||
|
RevCommit revCommit = createChange().getCommit();
|
||||||
|
gApi.projects().name(project.get()).branch(branch).create(new BranchInput());
|
||||||
|
CherryPickInput input = new CherryPickInput();
|
||||||
|
input.destination = branch;
|
||||||
|
input.topic = "topic";
|
||||||
|
String changeId =
|
||||||
|
gApi.projects().name(project.get()).commit(revCommit.name()).cherryPick(input).get().id;
|
||||||
|
|
||||||
|
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
|
||||||
|
assertThat(changeInfo.topic).isEqualTo(input.topic);
|
||||||
|
}
|
||||||
|
|
||||||
private IncludedInInfo getIncludedIn(ObjectId id) throws Exception {
|
private IncludedInInfo getIncludedIn(ObjectId id) throws Exception {
|
||||||
return gApi.projects().name(project.get()).commit(id.name()).includedIn();
|
return gApi.projects().name(project.get()).commit(id.name()).includedIn();
|
||||||
}
|
}
|
||||||
|
@ -402,6 +402,19 @@ public class RevisionIT extends AbstractDaemonTest {
|
|||||||
cherry.current().submit();
|
cherry.current().submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cherryPickWithSetTopic() throws Exception {
|
||||||
|
PushOneCommit.Result r = pushTo("refs/for/master");
|
||||||
|
CherryPickInput in = new CherryPickInput();
|
||||||
|
in.destination = "foo";
|
||||||
|
in.topic = "topic";
|
||||||
|
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).isEqualTo("topic");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cherryPickWorkInProgressChange() throws Exception {
|
public void cherryPickWorkInProgressChange() throws Exception {
|
||||||
PushOneCommit.Result r = pushTo("refs/for/master%wip");
|
PushOneCommit.Result r = pushTo("refs/for/master%wip");
|
||||||
|
Loading…
Reference in New Issue
Block a user