Search in sources :

Example 1 with RepositoryCaseMismatchException

use of com.google.gerrit.server.git.RepositoryCaseMismatchException in project gerrit by GerritCodeReview.

the class CreateProject method createProject.

private Project createProject(CreateProjectArgs args) throws BadRequestException, ResourceConflictException, IOException, ConfigInvalidException {
    final Project.NameKey nameKey = args.getProject();
    try {
        final String head = args.permissionsOnly ? RefNames.REFS_CONFIG : args.branch.get(0);
        try (Repository repo = repoManager.openRepository(nameKey)) {
            if (repo.getObjectDatabase().exists()) {
                throw new ResourceConflictException("project \"" + nameKey + "\" exists");
            }
        } catch (RepositoryNotFoundException e) {
        // It does not exist, safe to ignore.
        }
        try (Repository repo = repoManager.createRepository(nameKey)) {
            RefUpdate u = repo.updateRef(Constants.HEAD);
            u.disableRefLog();
            u.link(head);
            createProjectConfig(args);
            if (!args.permissionsOnly && args.createEmptyCommit) {
                createEmptyCommits(repo, nameKey, args.branch);
            }
            fire(nameKey, head);
            return projectCache.get(nameKey).getProject();
        }
    } catch (RepositoryCaseMismatchException e) {
        throw new ResourceConflictException("Cannot create " + nameKey.get() + " because the name is already occupied by another project." + " The other project has the same name, only spelled in a" + " different case.");
    } catch (RepositoryNotFoundException badName) {
        throw new BadRequestException("invalid project name: " + nameKey);
    } catch (ConfigInvalidException e) {
        String msg = "Cannot create " + nameKey;
        log.error(msg, e);
        throw e;
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) RepositoryCaseMismatchException(com.google.gerrit.server.git.RepositoryCaseMismatchException) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Aggregations

BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 Project (com.google.gerrit.reviewdb.client.Project)1 RepositoryCaseMismatchException (com.google.gerrit.server.git.RepositoryCaseMismatchException)1 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)1 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)1 RefUpdate (org.eclipse.jgit.lib.RefUpdate)1 Repository (org.eclipse.jgit.lib.Repository)1