Search in sources :

Example 81 with ResourceConflictException

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.");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 82 with ResourceConflictException

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.");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 83 with ResourceConflictException

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());
    }
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) IOException(java.io.IOException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) IOException(java.io.IOException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Project(com.google.gerrit.entities.Project) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectResource(com.google.gerrit.server.project.ProjectResource) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 84 with ResourceConflictException

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");
        }
    }
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) TaskResource(com.google.gerrit.server.config.TaskResource) AuthException(com.google.gerrit.extensions.restapi.AuthException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) IdString(com.google.gerrit.extensions.restapi.IdString) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ConfigResource(com.google.gerrit.server.config.ConfigResource)

Example 85 with ResourceConflictException

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;
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Ref(org.eclipse.jgit.lib.Ref) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)252 Test (org.junit.Test)106 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)102 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)57 AuthException (com.google.gerrit.extensions.restapi.AuthException)46 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)44 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)42 IOException (java.io.IOException)39 ObjectId (org.eclipse.jgit.lib.ObjectId)36 Repository (org.eclipse.jgit.lib.Repository)34 Change (com.google.gerrit.entities.Change)29 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)28 RevCommit (org.eclipse.jgit.revwalk.RevCommit)27 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)26 RevWalk (org.eclipse.jgit.revwalk.RevWalk)25 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)23 ArrayList (java.util.ArrayList)21 PatchSet (com.google.gerrit.entities.PatchSet)20 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)20 ProjectState (com.google.gerrit.server.project.ProjectState)19