use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickToExistingChangeUpdatesCherryPickOf.
@Test
public void cherryPickToExistingChangeUpdatesCherryPickOf() throws Exception {
PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "a").to("refs/for/master");
String t1 = project.get() + "~master~" + r1.getChangeId();
ChangeApi orig = gApi.changes().id(project.get() + "~master~" + r1.getChangeId());
BranchInput bin = new BranchInput();
bin.revision = r1.getCommit().getParent(0).name();
gApi.projects().name(project.get()).branch("foo").create(bin);
PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "b", r1.getChangeId()).to("refs/for/foo");
String t2 = project.get() + "~foo~" + r2.getChangeId();
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.message = r1.getCommit().getFullMessage();
ChangeApi cherry = gApi.changes().id(t1).current().cherryPick(in);
assertThat(get(t2, ALL_REVISIONS).revisions).hasSize(2);
assertThat(cherry.get().cherryPickOfChange).isEqualTo(orig.get()._number);
assertThat(cherry.get().cherryPickOfPatchSet).isEqualTo(1);
PushOneCommit.Result r3 = amendChange(r1.getChangeId(), SUBJECT, "b.txt", "b");
in = new CherryPickInput();
in.destination = "foo";
in.message = r3.getCommit().getFullMessage();
cherry = gApi.changes().id(t1).current().cherryPick(in);
assertThat(cherry.get()._number).isEqualTo(info(t2)._number);
assertThat(cherry.get().cherryPickOfChange).isEqualTo(orig.get()._number);
assertThat(cherry.get().cherryPickOfPatchSet).isEqualTo(2);
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickMergeRelativeToDefaultParent.
@Test
public void cherryPickMergeRelativeToDefaultParent() throws Exception {
String parent1FileName = "a.txt";
String parent2FileName = "b.txt";
PushOneCommit.Result mergeChangeResult = createCherryPickableMerge(parent1FileName, parent2FileName);
String cherryPickBranchName = "branch_for_cherry_pick";
createBranch(BranchNameKey.create(project, cherryPickBranchName));
CherryPickInput cherryPickInput = new CherryPickInput();
cherryPickInput.destination = cherryPickBranchName;
cherryPickInput.message = "Cherry-pick a merge commit to another branch";
ChangeInfo cherryPickedChangeInfo = gApi.changes().id(mergeChangeResult.getChangeId()).current().cherryPick(cherryPickInput).get();
Map<String, FileInfo> cherryPickedFilesByName = cherryPickedChangeInfo.revisions.get(cherryPickedChangeInfo.currentRevision).files;
assertThat(cherryPickedFilesByName).containsKey(parent2FileName);
assertThat(cherryPickedFilesByName).doesNotContainKey(parent1FileName);
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickIdenticalTree.
@Test
public void cherryPickIdenticalTree() throws Exception {
PushOneCommit.Result r = createChange();
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());
assertThat(orig.get().messages).hasSize(1);
ChangeApi cherry = orig.revision(r.getCommit().name()).cherryPick(in);
assertThat(cherry.get().subject).contains(in.message);
cherry.current().review(ReviewInput.approve());
cherry.current().submit();
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> orig.revision(r.getCommit().name()).cherryPick(in));
assertThat(thrown).hasMessageThat().contains("Cherry pick failed: identical tree");
in.allowEmpty = true;
ChangeInfo cherryPickChange = orig.revision(r.getCommit().name()).cherryPick(in).get();
assertThat(cherryPickChange.cherryPickOfChange).isEqualTo(r.getChange().change().getChangeId());
// An empty commit is created
assertThat(cherryPickChange.insertions).isEqualTo(0);
assertThat(cherryPickChange.deletions).isEqualTo(0);
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickToAbandonedChange.
@Test
public void cherryPickToAbandonedChange() throws Exception {
PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "a").to("refs/for/master");
String t1 = project.get() + "~master~" + r1.getChangeId();
BranchInput bin = new BranchInput();
bin.revision = r1.getCommit().getParent(0).name();
gApi.projects().name(project.get()).branch("foo").create(bin);
PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "b", r1.getChangeId()).to("refs/for/foo");
String t2 = project.get() + "~foo~" + r2.getChangeId();
gApi.changes().id(t2).abandon();
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
in.message = r1.getCommit().getFullMessage();
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(t1).current().cherryPick(in));
assertThat(thrown).hasMessageThat().isEqualTo(String.format("Cherry-pick with Change-Id %s could not update the existing change %d in " + "destination branch refs/heads/foo of project %s, because " + "the change was closed (ABANDONED)", r1.getChangeId(), info(t2)._number, project.get()));
gApi.changes().id(t2).restore();
gApi.changes().id(t1).current().cherryPick(in);
assertThat(get(t2, ALL_REVISIONS).revisions).hasSize(2);
assertThat(gApi.changes().id(t2).current().file(FILE_NAME).content().asString()).isEqualTo("a");
}
use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.
the class RevisionIT method cherryPickWithInvalidBaseFails.
@Test
public void cherryPickWithInvalidBaseFails() throws Exception {
PushOneCommit.Result change1 = createChange();
CherryPickInput input = new CherryPickInput();
input.destination = "master";
input.base = "invalid-sha1";
input.message = change1.getCommit().getFullMessage();
BadRequestException thrown = assertThrows(BadRequestException.class, () -> gApi.changes().id(change1.getChangeId()).current().cherryPick(input));
assertThat(thrown).hasMessageThat().contains(String.format("Base %s doesn't represent a valid SHA-1", input.base));
}
Aggregations