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();
}
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();
}
Aggregations