use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class MoveChangeIT method moveMergeCommitChange.
@Test
public void moveMergeCommitChange() throws Exception {
// Move a change which has a merge commit as the current PS
// Create a merge commit and push for review
PushOneCommit.Result r1 = createChange();
PushOneCommit.Result r2 = createChange();
TestRepository<?>.CommitBuilder commitBuilder = testRepo.branch("HEAD").commit().insertChangeId();
commitBuilder.parent(r1.getCommit()).parent(r2.getCommit()).message("Move change Merge Commit").author(admin.newIdent()).committer(new PersonIdent(admin.newIdent(), testRepo.getDate()));
RevCommit c = commitBuilder.create();
pushHead(testRepo, "refs/for/master", false, false);
// Try to move the merge commit to another branch
BranchNameKey newBranch = BranchNameKey.create(r1.getChange().change().getProject(), "moveTest");
createBranch(newBranch);
String changeId = GitUtil.getChangeId(testRepo, c).get();
move(changeId, newBranch.branch());
assertThat(gApi.changes().id(changeId).get().branch).isEqualTo("moveTest");
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class MoveChangeIT method moveChangeKeepAllVotesOnlyAllowedForAdmins.
@Test
public void moveChangeKeepAllVotesOnlyAllowedForAdmins() throws Exception {
// Keep all votes options is only permitted for admins.
BranchNameKey destinationBranch = BranchNameKey.create(project, "dest");
createBranch(destinationBranch);
BranchNameKey sourceBranch = BranchNameKey.create(project, "source");
createBranch(sourceBranch);
String changeId = createChangeInBranch(sourceBranch.branch()).getChangeId();
// Grant change permissions to the registered users.
projectOperations.project(project).forUpdate().add(allow(Permission.PUSH).ref(destinationBranch.branch()).group(REGISTERED_USERS)).update();
projectOperations.project(project).forUpdate().add(allow(Permission.ABANDON).ref(sourceBranch.branch()).group(REGISTERED_USERS)).update();
requestScopeOperations.setApiUser(user.id());
AuthException thrown = assertThrows(AuthException.class, () -> move(changeId, destinationBranch.shortName(), true));
assertThat(thrown).hasMessageThat().isEqualTo("move is not permitted with keepAllVotes option");
requestScopeOperations.setApiUser(admin.id());
move(changeId, destinationBranch.branch(), true);
assertThat(info(changeId).branch).isEqualTo(destinationBranch.shortName());
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class CreateChangeIT method canCreateChangeOnRefsMetaDashboards.
@Test
public void canCreateChangeOnRefsMetaDashboards() throws Exception {
String branchName = "refs/meta/dashboards/project_1";
requestScopeOperations.setApiUser(admin.id());
projectOperations.project(project).forUpdate().add(allow(CREATE).ref(branchName).group(REGISTERED_USERS)).add(allow(READ).ref(branchName).group(REGISTERED_USERS)).update();
BranchNameKey branchNameKey = BranchNameKey.create(project, branchName);
createBranch(branchNameKey);
requestScopeOperations.setApiUser(user.id());
ChangeInput ci = newChangeInput(ChangeStatus.NEW);
ci.subject = "Subject";
ci.branch = branchName;
assertThat(gApi.changes().create(ci).info().branch).isEqualTo(branchName);
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class Submit method unmergeableChanges.
public Collection<ChangeData> unmergeableChanges(ChangeSet cs) throws IOException {
Set<ChangeData> mergeabilityMap = new HashSet<>();
Set<ObjectId> outDatedPatchsets = new HashSet<>();
for (ChangeData change : cs.changes()) {
mergeabilityMap.add(change);
// Add all the patchsets commit ids except the current patchset.
outDatedPatchsets.addAll(change.notes().getPatchSets().values().stream().map(p -> p.commitId()).collect(Collectors.toSet()));
outDatedPatchsets.remove(change.currentPatchSet().commitId());
}
ListMultimap<BranchNameKey, ChangeData> cbb = cs.changesByBranch();
for (BranchNameKey branch : cbb.keySet()) {
Collection<ChangeData> targetBranch = cbb.get(branch);
HashMap<Change.Id, RevCommit> commits = findCommits(targetBranch, branch.project());
Set<ObjectId> allParents = Sets.newHashSetWithExpectedSize(cs.size());
for (RevCommit commit : commits.values()) {
for (RevCommit parent : commit.getParents()) {
allParents.add(parent.getId());
}
}
for (ChangeData change : targetBranch) {
RevCommit commit = commits.get(change.getId());
boolean isMergeCommit = commit.getParentCount() > 1;
boolean isLastInChain = !allParents.contains(commit.getId());
if (Arrays.stream(commit.getParents()).anyMatch(c -> outDatedPatchsets.contains(c.getId())) && !isCherryPickSubmit(change)) {
// cherry-pick.
continue;
}
// Recheck mergeability rather than using value stored in the index,
// which may be stale.
// TODO(dborowitz): This is ugly; consider providing a way to not read
// stored fields from the index in the first place.
change.setMergeable(null);
Boolean mergeable = change.isMergeable();
if (mergeable == null) {
// Skip whole check, cannot determine if mergeable
return null;
}
if (mergeable) {
mergeabilityMap.remove(change);
}
if (isLastInChain && isMergeCommit && mergeable) {
for (ChangeData c : targetBranch) {
mergeabilityMap.remove(c);
}
break;
}
}
}
return mergeabilityMap;
}
use of com.google.gerrit.entities.BranchNameKey in project gerrit by GerritCodeReview.
the class SubmoduleCommitsTest method createGitlinksCommit_subprojectMoved.
@Test
public void createGitlinksCommit_subprojectMoved() throws Exception {
createRepo(subProject, MASTER);
createRepo(superProject, MASTER);
when(mockProjectCache.get(any())).thenReturn(Optional.of(mockProjectState));
mergeOpRepoManager = new MergeOpRepoManager(repoManager, mockProjectCache, null, null);
ObjectId subprojectCommit = getTip(subProject, MASTER);
RevCommit superprojectTip = directUpdateSubmodule(superProject, MASTER, Project.nameKey("dir-x"), subprojectCommit);
assertThat(readGitLink(superProject, superprojectTip, "dir-x")).isEqualTo(subprojectCommit);
RevCommit newSubprojectCommit = addCommit(subProject, MASTER);
BranchNameKey superBranch = BranchNameKey.create(superProject, MASTER);
BranchNameKey subBranch = BranchNameKey.create(subProject, MASTER);
SubmoduleSubscription ss = new SubmoduleSubscription(superBranch, subBranch, "dir-x");
SubmoduleCommits helper = new SubmoduleCommits(mergeOpRepoManager, ident, new Config());
Optional<CodeReviewCommit> newGitLinksCommit = helper.composeGitlinksCommit(BranchNameKey.create(superProject, MASTER), ImmutableList.of(ss));
assertThat(newGitLinksCommit).isPresent();
assertThat(newGitLinksCommit.get().getParent(0)).isEqualTo(superprojectTip);
assertThat(readGitLink(superProject, newGitLinksCommit.get(), "dir-x")).isEqualTo(newSubprojectCommit);
}
Aggregations