Search in sources :

Example 81 with BranchInput

use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.

the class SubmitByMergeIfNecessaryIT method openChangeForTargetBranchPreventsMerge.

@Test
public void openChangeForTargetBranchPreventsMerge() throws Throwable {
    gApi.projects().name(project.get()).branch("stable").create(new BranchInput());
    // Propose a change for master, but leave it open for master!
    PushOneCommit change = pushFactory.create(user.newIdent(), testRepo, "small fix", "a.txt", "2");
    PushOneCommit.Result change2result = change.to("refs/for/master");
    // Now cherry pick to stable
    CherryPickInput in = new CherryPickInput();
    in.destination = "stable";
    in.message = "it goes to stable branch";
    ChangeApi orig = gApi.changes().id(change2result.getChangeId());
    ChangeApi cherry = orig.current().cherryPick(in);
    cherry.current().review(ReviewInput.approve());
    cherry.current().submit();
    // Create a commit locally
    testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/stable")).call();
    PushOneCommit.Result change3 = createChange(testRepo, "stable", "test", "a.txt", "3", "");
    submitWithConflict(change3.getChangeId(), "Failed to submit 1 change due to the following problems:\n" + "Change " + change3.getPatchSetId().changeId().get() + ": Depends on change that was not submitted." + " Commit " + change3.getCommit().name() + " depends on commit " + change2result.getCommit().name() + " of change " + change2result.getChange().getId() + " which cannot be merged.");
    assertRefUpdatedEvents();
    assertChangeMergedEvents();
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) 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) Test(org.junit.Test)

Example 82 with BranchInput

use of com.google.gerrit.extensions.api.projects.BranchInput in project gerrit by GerritCodeReview.

the class SubmitByMergeIfNecessaryIT method dependencyOnChangeForNonVisibleBranchPreventsMerge.

@Test
public void dependencyOnChangeForNonVisibleBranchPreventsMerge() throws Throwable {
    projectOperations.project(project).forUpdate().add(allowLabel(LabelId.CODE_REVIEW).ref("refs/heads/*").group(REGISTERED_USERS).range(-2, 2)).add(allow(Permission.SUBMIT).ref("refs/*").group(REGISTERED_USERS)).update();
    // Create a change
    PushOneCommit change = pushFactory.create(admin.newIdent(), testRepo, "fix", "a.txt", "foo");
    PushOneCommit.Result changeResult = change.to("refs/for/master");
    approve(changeResult.getChangeId());
    // Create a successor change.
    PushOneCommit change2 = pushFactory.create(admin.newIdent(), testRepo, "feature", "b.txt", "bar");
    PushOneCommit.Result change2Result = change2.to("refs/for/master");
    // Move the first change to a destination branch that is non-visible to user so that user cannot
    // this change anymore.
    BranchNameKey secretBranch = BranchNameKey.create(project, "secretBranch");
    gApi.projects().name(secretBranch.project().get()).branch(secretBranch.branch()).create(new BranchInput());
    gApi.changes().id(changeResult.getChangeId()).move(secretBranch.branch());
    projectOperations.project(project).forUpdate().add(block(READ).ref(secretBranch.branch()).group(ANONYMOUS_USERS)).update();
    requestScopeOperations.setApiUser(user.id());
    // Verify that user cannot see the first change.
    ResourceNotFoundException thrown = assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(changeResult.getChangeId()).get());
    assertThat(thrown).hasMessageThat().isEqualTo("Not found: " + changeResult.getChangeId());
    // Submit is expected to fail.
    submitWithConflict(change2Result.getChangeId(), "Failed to submit 1 change due to the following problems:\n" + "Change " + change2Result.getChange().getId() + ": Depends on change that was not submitted." + " Commit " + change2Result.getCommit().name() + " depends on commit " + changeResult.getCommit().name() + " which cannot be merged." + " Is the change of this commit not visible to '" + user.username() + "' or was it deleted?");
    assertRefUpdatedEvents();
    assertChangeMergedEvents();
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test)

Aggregations

BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)82 Test (org.junit.Test)65 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)60 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)39 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)26 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)15 BranchInfo (com.google.gerrit.extensions.api.projects.BranchInfo)12 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)12 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)11 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)9 Repository (org.eclipse.jgit.lib.Repository)6 BranchNameKey (com.google.gerrit.entities.BranchNameKey)5 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)5 ObjectId (org.eclipse.jgit.lib.ObjectId)5 RefUpdate (org.eclipse.jgit.lib.RefUpdate)5 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)4 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)4 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)4 TestRepository (org.eclipse.jgit.junit.TestRepository)4