Search in sources :

Example 66 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class PermissionBackendConditionIT method projectPermissions_differentResourceSameUserDoesNotEqual.

@Test
public void projectPermissions_differentResourceSameUserDoesNotEqual() throws Exception {
    Project.NameKey project2 = projectOperations.newProject().create();
    BooleanCondition cond1 = pb.user(user()).project(project).testCond(ProjectPermission.READ);
    BooleanCondition cond2 = pb.user(user()).project(project2).testCond(ProjectPermission.READ);
    assertNotEquals(cond1, cond2);
    assertNotEquals(cond1.hashCode(), cond2.hashCode());
}
Also used : Project(com.google.gerrit.entities.Project) BooleanCondition(com.google.gerrit.extensions.conditions.BooleanCondition) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 67 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class CherryPickCommit method apply.

@Override
public Response<ChangeInfo> apply(CommitResource rsrc, CherryPickInput input) throws IOException, UpdateException, RestApiException, PermissionBackendException, ConfigInvalidException, NoSuchProjectException {
    String destination = Strings.nullToEmpty(input.destination).trim();
    input.parent = input.parent == null ? 1 : input.parent;
    Project.NameKey projectName = rsrc.getProjectState().getNameKey();
    if (destination.isEmpty()) {
        throw new BadRequestException("destination must be non-empty");
    }
    String refName = RefNames.fullName(destination);
    contributorAgreements.check(projectName, user.get());
    permissionBackend.currentUser().project(projectName).ref(refName).check(RefPermission.CREATE_CHANGE);
    rsrc.getProjectState().checkStatePermitsWrite();
    try {
        CherryPickChange.Result cherryPickResult = cherryPickChange.cherryPick(null, projectName, rsrc.getCommit(), input, BranchNameKey.create(rsrc.getProjectState().getNameKey(), refName));
        ChangeInfo changeInfo = json.noOptions().format(projectName, cherryPickResult.changeId());
        changeInfo.containsGitConflicts = !cherryPickResult.filesWithGitConflicts().isEmpty() ? true : null;
        return Response.ok(changeInfo);
    } catch (InvalidChangeOperationException e) {
        throw new BadRequestException(e.getMessage());
    }
}
Also used : Project(com.google.gerrit.entities.Project) InvalidChangeOperationException(com.google.gerrit.server.project.InvalidChangeOperationException) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException)

Example 68 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class ProjectResetterTest method projectEvictionIfRefsMetaConfigIsReset.

@Test
public void projectEvictionIfRefsMetaConfigIsReset() throws Exception {
    Project.NameKey project2 = Project.nameKey("bar");
    Repository repo2 = repoManager.createRepository(project2);
    Ref metaConfig = createRef(repo2, RefNames.REFS_CONFIG);
    ProjectCache projectCache = mock(ProjectCache.class);
    Ref nonMetaConfig = createRef("refs/heads/master");
    try (ProjectResetter resetProject = builder(null, null, null, null, null, null, projectCache).build(new ProjectResetter.Config().reset(project).reset(project2))) {
        updateRef(nonMetaConfig);
        updateRef(repo2, metaConfig);
    }
    verify(projectCache, only()).evictAndReindex(project2);
}
Also used : Project(com.google.gerrit.entities.Project) ProjectCache(com.google.gerrit.server.project.ProjectCache) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) Test(org.junit.Test)

Example 69 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class ProjectResetterTest method onlyDeleteNewlyCreatedMatchingRefsMultipleProjects.

@Test
public void onlyDeleteNewlyCreatedMatchingRefsMultipleProjects() throws Exception {
    Project.NameKey project2 = Project.nameKey("bar");
    Repository repo2 = repoManager.createRepository(project2);
    Ref matchingRefProject1;
    Ref nonMatchingRefProject1;
    Ref matchingRefProject2;
    Ref nonMatchingRefProject2;
    try (ProjectResetter resetProject = builder().build(new ProjectResetter.Config().reset(project, "refs/foo/*").reset(project2, "refs/bar/*"))) {
        matchingRefProject1 = createRef("refs/foo/test");
        nonMatchingRefProject1 = createRef("refs/bar/test");
        matchingRefProject2 = createRef(repo2, "refs/bar/test");
        nonMatchingRefProject2 = createRef(repo2, "refs/foo/test");
    }
    // The matching refs are deleted since they didn't exist before.
    assertDeletedRef(matchingRefProject1);
    assertDeletedRef(repo2, matchingRefProject2);
    // The non-matching ref is not deleted.
    assertRef(nonMatchingRefProject1);
    assertRef(repo2, nonMatchingRefProject2);
}
Also used : Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) Test(org.junit.Test)

Example 70 with Project

use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.

the class ConfigChangeIT method rejectDoubleInheritance.

@Test
public void rejectDoubleInheritance() throws Exception {
    requestScopeOperations.setApiUser(admin.id());
    // Create separate projects to test the config
    Project.NameKey parent = createProjectOverAPI("projectToInheritFrom", null, true, null);
    Project.NameKey child = createProjectOverAPI("projectWithMalformedConfig", null, true, null);
    String config = gApi.projects().name(child.get()).branch(RefNames.REFS_CONFIG).file("project.config").asString();
    // Append and push malformed project config
    String pattern = "[access]\n\tinheritFrom = " + allProjects.get() + "\n";
    String doubleInherit = pattern + "\tinheritFrom = " + parent.get() + "\n";
    config = config.replace(pattern, doubleInherit);
    TestRepository<InMemoryRepository> childRepo = cloneProject(child, admin);
    // Fetch meta ref
    GitUtil.fetch(childRepo, RefNames.REFS_CONFIG + ":cfg");
    childRepo.reset("cfg");
    PushOneCommit push = pushFactory.create(admin.newIdent(), childRepo, "Subject", "project.config", config);
    PushOneCommit.Result res = push.to(RefNames.REFS_CONFIG);
    res.assertErrorStatus();
    res.assertMessage("cannot inherit from multiple projects");
}
Also used : Project(com.google.gerrit.entities.Project) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Project (com.google.gerrit.entities.Project)184 Test (org.junit.Test)109 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)67 Change (com.google.gerrit.entities.Change)43 Repository (org.eclipse.jgit.lib.Repository)34 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)33 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)32 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)31 BranchNameKey (com.google.gerrit.entities.BranchNameKey)30 Config (org.eclipse.jgit.lib.Config)26 ObjectId (org.eclipse.jgit.lib.ObjectId)26 IOException (java.io.IOException)25 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)24 ProjectState (com.google.gerrit.server.project.ProjectState)23 Inject (com.google.inject.Inject)23 List (java.util.List)23 AuthException (com.google.gerrit.extensions.restapi.AuthException)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)22 PatchSet (com.google.gerrit.entities.PatchSet)20