Search in sources :

Example 26 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class SubmoduleSubscriptionsIT method blockSubmissionForChangesModifyingSpecifiedSubmodule.

@Test
public void blockSubmissionForChangesModifyingSpecifiedSubmodule() throws Exception {
    ObjectId commitId = getCommitWithSubmoduleUpdate();
    CherryPickInput cherryPickInput = new CherryPickInput();
    cherryPickInput.destination = "branch";
    cherryPickInput.allowConflicts = true;
    // The rule will fail if the next change has a submodule file modification with subKey.
    modifySubmitRulesToBlockSubmoduleChanges(String.format("file('%s','M','SUBMODULE')", subKey));
    // Cherry-pick the newly created commit which contains a submodule update, to branch "branch".
    ChangeApi changeApi = gApi.projects().name(superKey.get()).commit(commitId.getName()).cherryPick(cherryPickInput);
    // Add another file to this change for good measure.
    PushOneCommit.Result result = amendChange(changeApi.get().changeId, "subject", "newFile", "content");
    assertThat(getStatus(result.getChange())).isEqualTo("NOT_READY");
    assertThat(gApi.changes().id(result.getChangeId()).get().submittable).isFalse();
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test)

Example 27 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class SubmoduleSubscriptionsIT method blockSubmissionWithSubmodules.

@Test
public void blockSubmissionWithSubmodules() throws Exception {
    ObjectId commitId = getCommitWithSubmoduleUpdate();
    CherryPickInput cherryPickInput = new CherryPickInput();
    cherryPickInput.destination = "branch";
    cherryPickInput.allowConflicts = true;
    // The rule will fail if the next change has any submodule file.
    modifySubmitRulesToBlockSubmoduleChanges("file(_,_,'SUBMODULE')");
    // Cherry-pick the newly created commit which contains a submodule update, to branch "branch".
    ChangeApi changeApi = gApi.projects().name(superKey.get()).commit(commitId.getName()).cherryPick(cherryPickInput);
    // Add another file to this change for good measure.
    PushOneCommit.Result result = amendChange(changeApi.get().changeId, "subject", "newFile", "content");
    assertThat(getStatus(result.getChange())).isEqualTo("NOT_READY");
    assertThat(gApi.changes().id(result.getChangeId()).get().submittable).isFalse();
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test)

Example 28 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class CheckMergeabilityIT method checkContentMergedCommit.

@Test
public void checkContentMergedCommit() throws Exception {
    testRepo.branch("HEAD").commit().insertChangeId().message("first commit").add("a.txt", "a contents ").create();
    testRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec("HEAD:refs/heads/master")).call();
    // create a change, and cherrypick into master
    PushOneCommit.Result cId = createChange();
    RevCommit commitId = cId.getCommit();
    CherryPickInput cpi = new CherryPickInput();
    cpi.destination = "master";
    cpi.message = "cherry pick the commit";
    ChangeApi orig = gApi.changes().id(cId.getChangeId());
    ChangeApi cherry = orig.current().cherryPick(cpi);
    cherry.current().review(ReviewInput.approve());
    cherry.current().submit();
    ObjectId remoteId = projectOperations.project(project).getHead("master");
    assertThat(remoteId).isNotEqualTo(commitId);
    assertContentMerged("master", commitId.getName(), "recursive");
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) ObjectId(org.eclipse.jgit.lib.ObjectId) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 29 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class CommitIT method cherryPickCommitToExistingChange.

@Test
public void cherryPickCommitToExistingChange() throws Exception {
    String destBranch = "foo";
    createBranch(BranchNameKey.create(project, destBranch));
    PushOneCommit.Result r = createChange("refs/for/" + destBranch);
    ChangeInfo existingDestChange = info(r.getChangeId());
    String commitToCherryPick = createChange().getCommit().getName();
    CherryPickInput input = new CherryPickInput();
    input.destination = destBranch;
    input.message = String.format("it goes to foo branch\n\nChange-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef\n\nChange-Id: %s\n", existingDestChange.changeId);
    input.allowConflicts = true;
    input.allowEmpty = true;
    ChangeInfo cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick).cherryPick(input).get();
    // New patch-set to existing change was uploaded.
    assertThat(cherryPickResult._number).isEqualTo(existingDestChange._number);
    assertThat(cherryPickResult.changeId).isEqualTo(existingDestChange.changeId);
    assertThat(cherryPickResult.messages).hasSize(2);
    assertThat(cherryPickResult.revisions).hasSize(2);
    Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
    assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 1.");
    assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 2.");
    // Cherry-pick of is not set, because the source change was not provided.
    assertThat(cherryPickResult.cherryPickOfChange).isNull();
    assertThat(cherryPickResult.cherryPickOfPatchSet).isNull();
    RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
    assertThat(revInfo).isNotNull();
    assertThat(revInfo.commit.message).isEqualTo(input.message);
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 30 with CherryPickInput

use of com.google.gerrit.extensions.api.changes.CherryPickInput in project gerrit by GerritCodeReview.

the class CommitIT method cherryPickWithoutMessageOtherBranch.

@Test
public void cherryPickWithoutMessageOtherBranch() throws Exception {
    String destBranch = "foo";
    createBranch(BranchNameKey.create(project, destBranch));
    // Create change to cherry-pick
    PushOneCommit.Result r = createChange();
    ChangeInfo changeToCherryPick = info(r.getChangeId());
    RevCommit commitToCherryPick = r.getCommit();
    // Cherry-pick without message.
    CherryPickInput input = new CherryPickInput();
    input.destination = destBranch;
    ChangeInfo cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.name()).cherryPick(input).get();
    // Expect that the Change-Id of the cherry-picked commit was used for the cherry-pick change.
    // New change in destination branch was created.
    assertThat(cherryPickResult._number).isGreaterThan(changeToCherryPick._number);
    assertThat(cherryPickResult.revisions).hasSize(1);
    assertThat(cherryPickResult.changeId).isEqualTo(changeToCherryPick.changeId);
    assertThat(cherryPickResult.messages).hasSize(1);
    // Cherry-pick of is not set, because the source change was not provided.
    assertThat(cherryPickResult.cherryPickOfChange).isNull();
    assertThat(cherryPickResult.cherryPickOfPatchSet).isNull();
    // Expect that the message of the cherry-picked commit was used for the cherry-pick change.
    RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
    assertThat(revInfo).isNotNull();
    assertThat(revInfo.commit.message).isEqualTo(commitToCherryPick.getFullMessage());
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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