Search in sources :

Example 6 with MetaDataUpdate

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

the class AgreementsIT method setUseContributorAgreements.

protected void setUseContributorAgreements(InheritableBoolean value) throws Exception {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(project)) {
        ProjectConfig config = projectConfigFactory.read(md);
        config.updateProject(p -> p.setBooleanConfig(BooleanProjectConfig.USE_CONTRIBUTOR_AGREEMENTS, value));
        config.commit(md);
        projectCache.evictAndReindex(config.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 7 with MetaDataUpdate

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

the class GroupsUpdate method commit.

private void commit(Repository allUsersRepo, GroupConfig groupConfig, @Nullable GroupNameNotes groupNameNotes) throws IOException {
    BatchRefUpdate batchRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
    try (MetaDataUpdate metaDataUpdate = metaDataUpdateFactory.create(allUsersName, allUsersRepo, batchRefUpdate)) {
        groupConfig.commit(metaDataUpdate);
    }
    if (groupNameNotes != null) {
        // MetaDataUpdates unfortunately can't be reused. -> Create a new one.
        try (MetaDataUpdate metaDataUpdate = metaDataUpdateFactory.create(allUsersName, allUsersRepo, batchRefUpdate)) {
            groupNameNotes.commit(metaDataUpdate);
        }
    }
    RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
    gitRefUpdated.fire(allUsersName, batchRefUpdate, currentUser.map(user -> user.state()).orElse(null));
}
Also used : BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 8 with MetaDataUpdate

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

the class Schema_184 method commit.

private void commit(AllUsersName allUsersName, PersonIdent serverUser, Repository allUsersRepo, GroupConfig groupConfig, GroupNameNotes groupNameNotes) throws IOException {
    BatchRefUpdate batchRefUpdate = allUsersRepo.getRefDatabase().newBatchUpdate();
    try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate(allUsersName, serverUser, allUsersRepo, batchRefUpdate)) {
        groupConfig.commit(metaDataUpdate);
    }
    // MetaDataUpdates unfortunately can't be reused. -> Create a new one.
    try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate(allUsersName, serverUser, allUsersRepo, batchRefUpdate)) {
        groupNameNotes.commit(metaDataUpdate);
    }
    RefUpdateUtil.executeChecked(batchRefUpdate, allUsersRepo);
}
Also used : BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 9 with MetaDataUpdate

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

the class AbstractSubmoduleSubscription method allowSubmoduleSubscription.

protected void allowSubmoduleSubscription(Project.NameKey submodule, String subBranch, Project.NameKey superproject, String superBranch, boolean match) throws Exception {
    try (MetaDataUpdate md = metaDataUpdateFactory.create(submodule)) {
        md.setMessage("Added superproject subscription");
        SubscribeSection.Builder s;
        ProjectConfig pc = projectConfigFactory.read(md);
        if (pc.getSubscribeSections().containsKey(superproject)) {
            s = pc.getSubscribeSections().get(superproject).toBuilder();
        } else {
            s = SubscribeSection.builder(superproject);
        }
        String refspec;
        if (superBranch == null) {
            refspec = subBranch;
        } else {
            refspec = subBranch + ":" + superBranch;
        }
        if (match) {
            s.addMatchingRefSpec(refspec);
        } else {
            s.addMultiMatchRefSpec(refspec);
        }
        pc.addSubscribeSection(s.build());
        ObjectId oldId = pc.getRevision();
        ObjectId newId = pc.commit(md);
        assertThat(newId).isNotEqualTo(oldId);
        projectCache.evictAndReindex(pc.getProject());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) ObjectId(org.eclipse.jgit.lib.ObjectId) SubscribeSection(com.google.gerrit.entities.SubscribeSection) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 10 with MetaDataUpdate

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

the class AbstractGroupTest method createMetaDataUpdate.

protected MetaDataUpdate createMetaDataUpdate(PersonIdent authorIdent) {
    MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, allUsersName, allUsersRepo);
    md.getCommitBuilder().setAuthor(authorIdent);
    // Committer is always the server identity.
    md.getCommitBuilder().setCommitter(serverIdent);
    return md;
}
Also used : MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Aggregations

MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)84 Test (org.junit.Test)39 Repository (org.eclipse.jgit.lib.Repository)36 ExternalIdNotes (com.google.gerrit.server.account.externalids.ExternalIdNotes)28 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)22 TestRepository (org.eclipse.jgit.junit.TestRepository)17 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)15 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)15 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)14 Account (com.google.gerrit.entities.Account)13 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)12 PersonIdent (org.eclipse.jgit.lib.PersonIdent)11 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)7 Project (com.google.gerrit.entities.Project)6 LightweightPluginDaemonTest (com.google.gerrit.acceptance.LightweightPluginDaemonTest)5 TestAccount (com.google.gerrit.acceptance.TestAccount)5 AccessSection (com.google.gerrit.entities.AccessSection)5 GroupReference (com.google.gerrit.entities.GroupReference)5 LabelType (com.google.gerrit.entities.LabelType)5