Search in sources :

Example 36 with CherryPickInput

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);
}
Also used : ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 37 with CherryPickInput

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);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) FileInfo(com.google.gerrit.extensions.common.FileInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 38 with CherryPickInput

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);
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 39 with CherryPickInput

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");
}
Also used : CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 40 with CherryPickInput

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));
}
Also used : CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)57 Test (org.junit.Test)53 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)50 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)49 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)30 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)27 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)11 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)11 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)8 Result (com.google.gerrit.acceptance.PushOneCommit.Result)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)6 RefSpec (org.eclipse.jgit.transport.RefSpec)5 CommitInfo (com.google.gerrit.extensions.common.CommitInfo)3 FileInfo (com.google.gerrit.extensions.common.FileInfo)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)3 Iterables (com.google.common.collect.Iterables)2 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)2