Search in sources :

Example 46 with RefSpec

use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.

the class Schema_120 method allowSubmoduleSubscription.

private void allowSubmoduleSubscription(Branch.NameKey subbranch, Branch.NameKey superBranch) throws OrmException {
    try (Repository git = mgr.openRepository(subbranch.getParentKey());
        RevWalk rw = new RevWalk(git)) {
        BatchRefUpdate bru = git.getRefDatabase().newBatchUpdate();
        try (MetaDataUpdate md = new MetaDataUpdate(GitReferenceUpdated.DISABLED, subbranch.getParentKey(), git, bru)) {
            md.getCommitBuilder().setAuthor(serverUser);
            md.getCommitBuilder().setCommitter(serverUser);
            md.setMessage("Added superproject subscription during upgrade");
            ProjectConfig pc = ProjectConfig.read(md);
            SubscribeSection s = null;
            for (SubscribeSection s1 : pc.getSubscribeSections(subbranch)) {
                if (s1.getProject().equals(superBranch.getParentKey())) {
                    s = s1;
                }
            }
            if (s == null) {
                s = new SubscribeSection(superBranch.getParentKey());
                pc.addSubscribeSection(s);
            }
            RefSpec newRefSpec = new RefSpec(subbranch.get() + ":" + superBranch.get());
            if (!s.getMatchingRefSpecs().contains(newRefSpec)) {
                // For the migration we use only exact RefSpecs, we're not trying to
                // generalize it.
                s.addMatchingRefSpec(newRefSpec);
            }
            pc.commit(md);
        }
        bru.execute(rw, NullProgressMonitor.INSTANCE);
    } catch (ConfigInvalidException | IOException e) {
        throw new OrmException(e);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Repository(org.eclipse.jgit.lib.Repository) RefSpec(org.eclipse.jgit.transport.RefSpec) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) OrmException(com.google.gwtorm.server.OrmException) SubscribeSection(com.google.gerrit.common.data.SubscribeSection) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

RefSpec (org.eclipse.jgit.transport.RefSpec)46 Test (org.junit.Test)17 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)9 Git (org.eclipse.jgit.api.Git)8 PushCommand (org.eclipse.jgit.api.PushCommand)8 File (java.io.File)7 PushResult (org.eclipse.jgit.transport.PushResult)7 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)6 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)5 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)5 ArrayList (java.util.ArrayList)5 FetchCommand (org.eclipse.jgit.api.FetchCommand)5 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)4 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)4 GitException (org.eclipse.che.api.git.exception.GitException)4