use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class MoveChangeIT method moveChangeWithFullRef.
@Test
public void moveChangeWithFullRef() throws Exception {
// Move change to a different branch using full ref name
PushOneCommit.Result r = createChange();
BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
createBranch(newBranch);
move(r.getChangeId(), newBranch.branch());
assertThat(r.getChange().change().getDest()).isEqualTo(newBranch);
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class MoveChangeIT method moveChangeToSameChangeId.
@Test
public void moveChangeToSameChangeId() throws Exception {
// Move change to a branch with existing change with same change ID
PushOneCommit.Result r = createChange();
BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
createBranch(newBranch);
int changeNum = r.getChange().change().getChangeId();
createChange(newBranch.branch(), r.getChangeId());
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> move(changeNum, newBranch.branch()));
assertThat(thrown).hasMessageThat().contains("Destination " + newBranch.shortName() + " has a different change with same change key " + r.getChangeId());
}
use of com.google.gerrit.entities.BranchNameKey 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();
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class BranchNameKeyProtoConverterTest method allValuesConvertedToProtoAndBackAgain.
@Test
public void allValuesConvertedToProtoAndBackAgain() {
BranchNameKey nameKey = BranchNameKey.create(Project.nameKey("project-52"), "branch 14");
BranchNameKey convertedNameKey = branchNameKeyProtoConverter.fromProto(branchNameKeyProtoConverter.toProto(nameKey));
assertThat(convertedNameKey).isEqualTo(nameKey);
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class ChangeNotesTest method branchChangeNotes.
@Test
public void branchChangeNotes() throws Exception {
Change c = newChange();
ChangeNotes notes = newNotes(c);
BranchNameKey expectedBranch = BranchNameKey.create(project, "refs/heads/master");
assertThat(notes.getChange().getDest()).isEqualTo(expectedBranch);
// An update doesn't affect the branch
ChangeUpdate update = newUpdate(c, changeOwner);
// Change something to get a new commit.
update.setTopic("topic");
update.commit();
assertThat(newNotes(c).getChange().getDest()).isEqualTo(expectedBranch);
// Set another branch
String otherBranch = "refs/heads/stable";
update = newUpdate(c, changeOwner);
update.setBranch(otherBranch);
update.commit();
assertThat(newNotes(c).getChange().getDest()).isEqualTo(BranchNameKey.create(project, otherBranch));
}
Aggregations