Search in sources :

Example 1 with Status

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

the class ProjectCreator method createProject.

public ProjectState 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);
        Status status = repoManager.getRepositoryStatus(nameKey);
        if (!status.equals(Status.NON_EXISTENT)) {
            throw new RepositoryExistsException(nameKey, "Repository status: " + status);
        }
        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).orElseThrow(illegalState(nameKey));
        }
    } catch (RepositoryExistsException e) {
        throw new ResourceConflictException("Cannot create " + nameKey.get() + " because the name is already occupied by another project.", e);
    } catch (RepositoryNotFoundException badName) {
        throw new BadRequestException("invalid project name: " + nameKey, badName);
    }
}
Also used : Status(com.google.gerrit.server.git.GitRepositoryManager.Status) Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RepositoryExistsException(com.google.gerrit.server.git.RepositoryExistsException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Aggregations

Project (com.google.gerrit.entities.Project)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 Status (com.google.gerrit.server.git.GitRepositoryManager.Status)1 RepositoryExistsException (com.google.gerrit.server.git.RepositoryExistsException)1 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)1 RefUpdate (org.eclipse.jgit.lib.RefUpdate)1 Repository (org.eclipse.jgit.lib.Repository)1