Search in sources :

Example 11 with SubmoduleSubscription

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

the class UpdateOrderCalculator method addAllSubmoduleProjects.

private void addAllSubmoduleProjects(Project.NameKey project, LinkedHashSet<Project.NameKey> current, LinkedHashSet<Project.NameKey> projects) throws SubmoduleConflictException {
    if (current.contains(project)) {
        throw new SubmoduleConflictException("Project level circular subscriptions detected:  " + CircularPathFinder.printCircularPath(current, project));
    }
    if (projects.contains(project)) {
        return;
    }
    current.add(project);
    Set<Project.NameKey> subprojects = new HashSet<>();
    for (BranchNameKey branch : subscriptionGraph.getAffectedSuperBranches(project)) {
        Collection<SubmoduleSubscription> subscriptions = subscriptionGraph.getSubscriptions(branch);
        for (SubmoduleSubscription s : subscriptions) {
            subprojects.add(s.getSubmodule().project());
        }
    }
    for (Project.NameKey p : subprojects) {
        addAllSubmoduleProjects(p, current, projects);
    }
    current.remove(project);
    projects.add(project);
}
Also used : Project(com.google.gerrit.entities.Project) BranchNameKey(com.google.gerrit.entities.BranchNameKey) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) BranchNameKey(com.google.gerrit.entities.BranchNameKey) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with SubmoduleSubscription

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

the class SubmoduleCommitsTest method amendGitlinksCommit_subprojectMoved.

@Test
public void amendGitlinksCommit_subprojectMoved() throws Exception {
    createRepo(subProject, MASTER);
    createRepo(superProject, MASTER);
    when(mockProjectCache.get(any())).thenReturn(Optional.of(mockProjectState));
    mergeOpRepoManager = new MergeOpRepoManager(repoManager, mockProjectCache, null, null);
    ObjectId subprojectCommit = getTip(subProject, MASTER);
    CodeReviewCommit superprojectTip = directUpdateSubmodule(superProject, MASTER, Project.nameKey("dir-x"), subprojectCommit);
    assertThat(readGitLink(superProject, superprojectTip, "dir-x")).isEqualTo(subprojectCommit);
    RevCommit newSubprojectCommit = addCommit(subProject, MASTER);
    BranchNameKey superBranch = BranchNameKey.create(superProject, MASTER);
    BranchNameKey subBranch = BranchNameKey.create(subProject, MASTER);
    SubmoduleSubscription ss = new SubmoduleSubscription(superBranch, subBranch, "dir-x");
    SubmoduleCommits helper = new SubmoduleCommits(mergeOpRepoManager, ident, new Config());
    CodeReviewCommit amendedCommit = helper.amendGitlinksCommit(BranchNameKey.create(superProject, MASTER), superprojectTip, ImmutableList.of(ss));
    assertThat(amendedCommit.getParent(0)).isEqualTo(superprojectTip.getParent(0));
    assertThat(readGitLink(superProject, amendedCommit, "dir-x")).isEqualTo(newSubprojectCommit);
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) ObjectId(org.eclipse.jgit.lib.ObjectId) Config(org.eclipse.jgit.lib.Config) SubmoduleSubscription(com.google.gerrit.entities.SubmoduleSubscription) CodeReviewCommit(com.google.gerrit.server.git.CodeReviewCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 13 with SubmoduleSubscription

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

the class SubmoduleSectionParserTest method followMasterBranch.

@Test
public void followMasterBranch() throws Exception {
    Project.NameKey p = Project.nameKey("proj");
    Config cfg = new Config();
    cfg.fromText("" + "[submodule \"a\"]\n" + "path = localpath-to-a\n" + "url = ssh://localhost/" + p.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(p, "master"), "localpath-to-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 14 with SubmoduleSubscription

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

the class SubmoduleSectionParserTest method withAnInvalidSection.

@Test
public void withAnInvalidSection() throws Exception {
    Project.NameKey p1 = Project.nameKey("a");
    Project.NameKey p2 = Project.nameKey("b");
    Project.NameKey p3 = Project.nameKey("d");
    Project.NameKey p4 = Project.nameKey("e");
    Config cfg = new Config();
    cfg.fromText("\n" + "[submodule \"a\"]\n" + "    path = a\n" + "    url = ssh://localhost/" + p1.get() + "\n" + "    branch = .\n" + "[submodule \"b\"]\n" + // path missing
    "    url = http://localhost:80/" + p2.get() + "\n" + "    branch = master\n" + "[submodule \"c\"]\n" + "    path = c\n" + // url missing
    "    branch = .\n" + "[submodule \"d\"]\n" + "    path = d-parent/the-d-folder\n" + "    url = ssh://localhost/" + p3.get() + "\n" + // branch missing
    "[submodule \"e\"]\n" + "    path = e\n" + "    url = ssh://localhost/" + p4.get() + "\n" + "    branch = refs/heads/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(p4, "master"), "e"));
    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 15 with SubmoduleSubscription

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

the class SubmoduleSectionParserTest method withSectionToOtherServer.

@Test
public void withSectionToOtherServer() throws Exception {
    Project.NameKey p1 = Project.nameKey("a");
    Config cfg = new Config();
    cfg.fromText("" + "[submodule \"a\"]" + "path = a" + "url = ssh://non-localhost/" + p1.get() + "\n" + "branch = .");
    BranchNameKey targetBranch = BranchNameKey.create(Project.nameKey("project"), "master");
    Set<SubmoduleSubscription> res = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch).parseAllSections();
    assertThat(res).isEmpty();
}
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)

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