Search in sources :

Example 6 with SubmoduleSubscription

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

the class SubmoduleSectionParserTest method withMoreSections.

@Test
public void withMoreSections() throws Exception {
    Project.NameKey p1 = Project.nameKey("a");
    Project.NameKey p2 = Project.nameKey("b");
    Config cfg = new Config();
    cfg.fromText("" + "[submodule \"a\"]\n" + "     path = a\n" + "     url = ssh://localhost/" + p1.get() + "\n" + "     branch = .\n" + "[submodule \"b\"]\n" + "		path = b\n" + "		url = http://localhost:80/" + p2.get() + "\n" + "		branch = master\n");
    BranchNameKey targetBranch = BranchNameKey.create(Project.nameKey("project"), "master");
    Set<SubmoduleSubscription> res = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch).parseAllSections();
    Set<SubmoduleSubscription> expected = Sets.newHashSet(new SubmoduleSubscription(targetBranch, BranchNameKey.create(p1, "master"), "a"), new SubmoduleSubscription(targetBranch, BranchNameKey.create(p2, "master"), "b"));
    assertThat(res).containsExactlyElementsIn(expected);
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Config(org.eclipse.jgit.lib.Config) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) Test(org.junit.Test)

Example 7 with SubmoduleSubscription

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

the class SubmoduleSectionParserTest method withDeepRelativeURI.

@Test
public void withDeepRelativeURI() throws Exception {
    Project.NameKey p1 = Project.nameKey("a");
    Config cfg = new Config();
    cfg.fromText("" + "[submodule \"a\"]\n" + "path = a\n" + "url = ../../" + p1.get() + "\n" + "branch = master\n");
    BranchNameKey targetBranch = BranchNameKey.create(Project.nameKey("nested/project"), "master");
    Set<SubmoduleSubscription> res = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch).parseAllSections();
    Set<SubmoduleSubscription> expected = Sets.newHashSet(new SubmoduleSubscription(targetBranch, BranchNameKey.create(p1, "master"), "a"));
    assertThat(res).containsExactlyElementsIn(expected);
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Config(org.eclipse.jgit.lib.Config) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) Test(org.junit.Test)

Example 8 with SubmoduleSubscription

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

the class SubmoduleSectionParserTest method followMatchingBranch.

@Test
public void followMatchingBranch() throws Exception {
    Project.NameKey p = Project.nameKey("a");
    Config cfg = new Config();
    cfg.fromText("" + "[submodule \"a\"]\n" + "path = a\n" + "url = ssh://localhost/" + p.get() + "\n" + "branch = .\n");
    BranchNameKey targetBranch1 = BranchNameKey.create(Project.nameKey("project"), "master");
    Set<SubmoduleSubscription> res1 = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch1).parseAllSections();
    Set<SubmoduleSubscription> expected1 = Sets.newHashSet(new SubmoduleSubscription(targetBranch1, BranchNameKey.create(p, "master"), "a"));
    assertThat(res1).containsExactlyElementsIn(expected1);
    BranchNameKey targetBranch2 = BranchNameKey.create(Project.nameKey("project"), "somebranch");
    Set<SubmoduleSubscription> res2 = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch2).parseAllSections();
    Set<SubmoduleSubscription> expected2 = Sets.newHashSet(new SubmoduleSubscription(targetBranch2, BranchNameKey.create(p, "somebranch"), "a"));
    assertThat(res2).containsExactlyElementsIn(expected2);
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Config(org.eclipse.jgit.lib.Config) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) Test(org.junit.Test)

Example 9 with SubmoduleSubscription

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

the class SubmoduleCommits method amendGitlinksCommit.

/**
 * Amend an existing commit with gitlink updates
 */
CodeReviewCommit amendGitlinksCommit(BranchNameKey subscriber, CodeReviewCommit currentCommit, Collection<SubmoduleSubscription> subscriptions) throws IOException, SubmoduleConflictException {
    OpenRepo or;
    try {
        or = orm.getRepo(subscriber.project());
    } catch (NoSuchProjectException | IOException e) {
        throw new StorageException("Cannot access superproject", e);
    }
    StringBuilder msgbuf = new StringBuilder();
    DirCache dc = readTree(or.rw, currentCommit);
    DirCacheEditor ed = dc.editor();
    for (SubmoduleSubscription s : sortByPath(subscriptions)) {
        updateSubmodule(dc, ed, msgbuf, s);
    }
    ed.finish();
    ObjectId newTreeId = dc.writeTree(or.ins);
    // Gitlinks are already updated, just return the commit
    if (newTreeId.equals(currentCommit.getTree())) {
        return currentCommit;
    }
    or.rw.parseBody(currentCommit);
    CommitBuilder commit = new CommitBuilder();
    commit.setTreeId(newTreeId);
    commit.setParentIds(currentCommit.getParents());
    if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
        // TODO(czhen): handle cherrypick footer
        commit.setMessage(currentCommit.getFullMessage() + "\n\n* submodules:\n" + msgbuf.toString());
    } else {
        commit.setMessage(currentCommit.getFullMessage());
    }
    commit.setAuthor(currentCommit.getAuthorIdent());
    commit.setCommitter(myIdent);
    ObjectId id = or.ins.insert(commit);
    CodeReviewCommit newCommit = or.getCodeReviewRevWalk().parseCommit(id);
    newCommit.copyFrom(currentCommit);
    return newCommit;
}
Also used : DirCache(org.eclipse.jgit.dircache.DirCache) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ObjectId(org.eclipse.jgit.lib.ObjectId) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) IOException(java.io.IOException) DirCacheEditor(org.eclipse.jgit.dircache.DirCacheEditor) StorageException(com.google.gerrit.exceptions.StorageException) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit)

Example 10 with SubmoduleSubscription

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

the class SubmoduleCommits method composeGitlinksCommit.

/**
 * Create a separate gitlink commit
 *
 * @param subscriber superproject (and branch)
 * @param subscriptions subprojects the superproject is subscribed to
 * @return a new commit on top of subscriber with gitlinks update to the tips of the subprojects;
 *     empty if nothing has changed. Subproject tips are read from the cached branched tips
 *     (defaulting to the mergeOpRepoManager).
 */
Optional<CodeReviewCommit> composeGitlinksCommit(BranchNameKey subscriber, Collection<SubmoduleSubscription> subscriptions) throws IOException, SubmoduleConflictException {
    OpenRepo or;
    try {
        or = orm.getRepo(subscriber.project());
    } catch (NoSuchProjectException | IOException e) {
        throw new StorageException("Cannot access superproject", e);
    }
    CodeReviewCommit currentCommit = branchTips.getTip(subscriber, or).orElseThrow(() -> new SubmoduleConflictException("The branch was probably deleted from the subscriber repository"));
    StringBuilder msgbuf = new StringBuilder();
    PersonIdent author = null;
    DirCache dc = readTree(or.getCodeReviewRevWalk(), currentCommit);
    DirCacheEditor ed = dc.editor();
    int count = 0;
    for (SubmoduleSubscription s : sortByPath(subscriptions)) {
        if (count > 0) {
            msgbuf.append("\n\n");
        }
        RevCommit newCommit = updateSubmodule(dc, ed, msgbuf, s);
        count++;
        if (newCommit != null) {
            PersonIdent newCommitAuthor = newCommit.getAuthorIdent();
            if (author == null) {
                author = new PersonIdent(newCommitAuthor, myIdent.getWhen());
            } else if (!author.getName().equals(newCommitAuthor.getName()) || !author.getEmailAddress().equals(newCommitAuthor.getEmailAddress())) {
                author = myIdent;
            }
        }
    }
    ed.finish();
    ObjectId newTreeId = dc.writeTree(or.ins);
    // Gitlinks are already in the branch, return null
    if (newTreeId.equals(currentCommit.getTree())) {
        return Optional.empty();
    }
    CommitBuilder commit = new CommitBuilder();
    commit.setTreeId(newTreeId);
    commit.setParentId(currentCommit);
    StringBuilder commitMsg = new StringBuilder("Update git submodules\n\n");
    if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
        commitMsg.append(msgbuf);
    }
    commit.setMessage(commitMsg.toString());
    commit.setAuthor(author);
    commit.setCommitter(myIdent);
    ObjectId id = or.ins.insert(commit);
    return Optional.of(or.getCodeReviewRevWalk().parseCommit(id));
}
Also used : NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ObjectId(org.eclipse.jgit.lib.ObjectId) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) IOException(java.io.IOException) DirCacheEditor(org.eclipse.jgit.dircache.DirCacheEditor) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit) DirCache(org.eclipse.jgit.dircache.DirCache) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) OpenRepo(com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) StorageException(com.google.gerrit.exceptions.StorageException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

SubmoduleSubscription (com.google.gerrit.entities.SubmoduleSubscription)22 BranchNameKey (com.google.gerrit.entities.BranchNameKey)18 Test (org.junit.Test)18 Project (com.google.gerrit.entities.Project)16 Config (org.eclipse.jgit.lib.Config)16 CodeReviewCommit (com.google.gerrit.server.git.CodeReviewCommit)4 ObjectId (org.eclipse.jgit.lib.ObjectId)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 StorageException (com.google.gerrit.exceptions.StorageException)2 NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)2 OpenRepo (com.google.gerrit.server.submit.MergeOpRepoManager.OpenRepo)2 DefaultFactory (com.google.gerrit.server.submit.SubscriptionGraph.DefaultFactory)2 IOException (java.io.IOException)2 DirCache (org.eclipse.jgit.dircache.DirCache)2 DirCacheEditor (org.eclipse.jgit.dircache.DirCacheEditor)2 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)2 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)2 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1