use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class DeleteBranchIT method deleteUserBranch_Conflict.
@Test
public void deleteUserBranch_Conflict() throws Exception {
projectOperations.project(allUsers).forUpdate().add(allow(Permission.CREATE).ref(RefNames.REFS_USERS + "*").group(REGISTERED_USERS)).add(allow(Permission.PUSH).ref(RefNames.REFS_USERS + "*").group(REGISTERED_USERS)).update();
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> branch(BranchNameKey.create(allUsers, RefNames.refsUsers(admin.id()))).delete());
assertThat(thrown).hasMessageThat().contains("Not allowed to delete user branch.");
}
use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class DeleteBranchIT method deleteGroupBranch_Conflict.
@Test
public void deleteGroupBranch_Conflict() throws Exception {
projectOperations.project(allUsers).forUpdate().add(allow(Permission.CREATE).ref(RefNames.REFS_GROUPS + "*").group(REGISTERED_USERS)).add(allow(Permission.PUSH).ref(RefNames.REFS_GROUPS + "*").group(REGISTERED_USERS)).update();
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> branch(BranchNameKey.create(allUsers, RefNames.refsGroups(adminGroupUuid()))).delete());
assertThat(thrown).hasMessageThat().contains("Not allowed to delete group branch.");
}
use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class SetParentCommand method run.
@Override
protected void run() throws Failure {
enableGracefulStop();
if (oldParent == null && children.isEmpty()) {
throw die("child projects have to be specified as " + "arguments or the --children-of option has to be set");
}
if (oldParent == null && !excludedChildren.isEmpty()) {
throw die("--exclude can only be used together with --children-of");
}
final StringBuilder err = new StringBuilder();
if (newParent != null) {
newParentKey = newParent.getProject().getNameKey();
}
final List<Project.NameKey> childProjects = children.stream().map(ProjectState::getNameKey).collect(toList());
if (oldParent != null) {
try {
childProjects.addAll(getChildrenForReparenting(oldParent));
} catch (PermissionBackendException e) {
throw new Failure(1, "permissions unavailable", e);
} catch (Exception e) {
throw new Failure(1, "failure in request", e);
}
}
for (Project.NameKey nameKey : childProjects) {
final String name = nameKey.get();
ProjectState project = projectCache.get(nameKey).orElseThrow(illegalState(nameKey));
try {
setParent.apply(new ProjectResource(project, user), parentInput(newParentKey.get()));
} catch (AuthException e) {
err.append("error: insuffient access rights to change parent of '").append(name).append("'\n");
} catch (ResourceConflictException | ResourceNotFoundException | BadRequestException e) {
err.append("error: ").append(e.getMessage()).append("'\n");
} catch (UnprocessableEntityException | IOException e) {
throw new Failure(1, "failure in request", e);
} catch (PermissionBackendException e) {
throw new Failure(1, "permissions unavailable", e);
}
}
if (err.length() > 0) {
while (err.charAt(err.length() - 1) == '\n') {
err.setLength(err.length() - 1);
}
throw die(err.toString());
}
}
use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class KillCommand method run.
@Override
protected void run() {
enableGracefulStop();
ConfigResource cfgRsrc = new ConfigResource();
for (String id : taskIds) {
try {
TaskResource taskRsrc = tasksCollection.parse(cfgRsrc, IdString.fromDecoded(id));
deleteTask.apply(taskRsrc, null);
} catch (AuthException | ResourceNotFoundException | ResourceConflictException | PermissionBackendException e) {
stderr.print("kill: " + id + ": No such task\n");
}
}
}
use of com.google.gerrit.extensions.restapi.ResourceConflictException in project gerrit by GerritCodeReview.
the class RebaseUtil method findBaseRevision.
/**
* Find the commit onto which a patch set should be rebased.
*
* <p>This is defined as the latest patch set of the change corresponding to this commit's parent,
* or the destination branch tip in the case where the parent's change is merged.
*
* @param patchSet patch set for which the new base commit should be found.
* @param destBranch the destination branch.
* @param git the repository.
* @param rw the RevWalk.
* @return the commit onto which the patch set should be rebased.
* @throws RestApiException if rebase is not possible.
* @throws IOException if accessing the repository fails.
*/
public ObjectId findBaseRevision(PatchSet patchSet, BranchNameKey destBranch, Repository git, RevWalk rw) throws RestApiException, IOException {
ObjectId baseId = null;
RevCommit commit = rw.parseCommit(patchSet.commitId());
if (commit.getParentCount() > 1) {
throw new UnprocessableEntityException("Cannot rebase a change with multiple parents.");
} else if (commit.getParentCount() == 0) {
throw new UnprocessableEntityException("Cannot rebase a change without any parents (is this the initial commit?).");
}
ObjectId parentId = commit.getParent(0);
CHANGES: for (ChangeData cd : queryProvider.get().byBranchCommit(destBranch, parentId.name())) {
for (PatchSet depPatchSet : cd.patchSets()) {
if (!depPatchSet.commitId().equals(parentId)) {
continue;
}
Change depChange = cd.change();
if (depChange.isAbandoned()) {
throw new ResourceConflictException("Cannot rebase a change with an abandoned parent: " + depChange.getKey());
}
if (depChange.isNew()) {
if (depPatchSet.id().equals(depChange.currentPatchSetId())) {
throw new ResourceConflictException("Change is already based on the latest patch set of the dependent change.");
}
baseId = cd.currentPatchSet().commitId();
}
break CHANGES;
}
}
if (baseId == null) {
// We are dependent on a merged PatchSet or have no PatchSet
// dependencies at all.
Ref destRef = git.getRefDatabase().exactRef(destBranch.branch());
if (destRef == null) {
throw new UnprocessableEntityException("The destination branch does not exist: " + destBranch.branch());
}
baseId = destRef.getObjectId();
if (baseId.equals(parentId)) {
throw new ResourceConflictException("Change is already up to date.");
}
}
return baseId;
}
Aggregations