Search in sources :

Example 1 with ProjectResetter

use of com.google.gerrit.acceptance.ProjectResetter in project gerrit by GerritCodeReview.

the class GroupsIT method cannotCreateGroupNamesBranch.

@Test
@IgnoreGroupInconsistencies
public void cannotCreateGroupNamesBranch() throws Exception {
    // Use ProjectResetter to restore the group names ref
    try (ProjectResetter resetter = projectResetter.builder().build(new ProjectResetter.Config().reset(allUsers, RefNames.REFS_GROUPNAMES))) {
        // Manually delete group names ref
        try (Repository repo = repoManager.openRepository(allUsers);
            RevWalk rw = new RevWalk(repo)) {
            RevCommit commit = rw.parseCommit(repo.exactRef(RefNames.REFS_GROUPNAMES).getObjectId());
            RefUpdate updateRef = repo.updateRef(RefNames.REFS_GROUPNAMES);
            updateRef.setExpectedOldObjectId(commit.toObjectId());
            updateRef.setNewObjectId(ObjectId.zeroId());
            updateRef.setForceUpdate(true);
            assertThat(updateRef.delete()).isEqualTo(RefUpdate.Result.FORCED);
        }
        // refs/meta/group-names is only visible with ACCESS_DATABASE
        projectOperations.allProjectsForUpdate().add(allowCapability(GlobalCapability.ACCESS_DATABASE).group(REGISTERED_USERS)).update();
        testCannotCreateGroupBranch(RefNames.REFS_GROUPNAMES, RefNames.REFS_GROUPNAMES);
    }
}
Also used : TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ProjectResetter(com.google.gerrit.acceptance.ProjectResetter) Config(org.eclipse.jgit.lib.Config) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RefUpdate(org.eclipse.jgit.lib.RefUpdate) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 ProjectResetter (com.google.gerrit.acceptance.ProjectResetter)1 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)1 TestRepository (org.eclipse.jgit.junit.TestRepository)1 Config (org.eclipse.jgit.lib.Config)1 RefUpdate (org.eclipse.jgit.lib.RefUpdate)1 Repository (org.eclipse.jgit.lib.Repository)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)1 Test (org.junit.Test)1