diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/util/SubmoduleSectionParser.java b/gerrit-server/src/main/java/com/google/gerrit/server/util/SubmoduleSectionParser.java index 8970425c02..c6a67db900 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/util/SubmoduleSectionParser.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/util/SubmoduleSectionParser.java @@ -74,6 +74,7 @@ public class SubmoduleSectionParser { final String url = bbc.getString("submodule", id, "url"); final String path = bbc.getString("submodule", id, "path"); String branch = bbc.getString("submodule", id, "branch"); + SubmoduleSubscription ss = null; try { if (url != null && url.length() > 0 && path != null && path.length() > 0 @@ -108,7 +109,7 @@ public class SubmoduleSectionParser { } if (repoManager.list().contains(new Project.NameKey(projectName))) { - return new SubmoduleSubscription( + ss = new SubmoduleSubscription( superProjectBranch, new Branch.NameKey(new Project.NameKey(projectName), branch), path); @@ -120,6 +121,6 @@ public class SubmoduleSectionParser { // Error in url syntax (in fact it is uri syntax) } - return null; + return ss; } } diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/util/SubmoduleSectionParserTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/util/SubmoduleSectionParserTest.java index d87888f212..67f56fc884 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/server/util/SubmoduleSectionParserTest.java +++ b/gerrit-server/src/test/java/com/google/gerrit/server/util/SubmoduleSectionParserTest.java @@ -186,6 +186,28 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase { new ArrayList()); } + @Test + public void testSubmodulesParseWithSubProjectFound() throws Exception { + Map sectionsToReturn = new TreeMap<>(); + sectionsToReturn.put("a/b", new SubmoduleSection( + "ssh://localhost/a/b", "a/b", ".")); + + Map reposToBeFound = new HashMap<>(); + reposToBeFound.put("a/b", "a/b"); + reposToBeFound.put("b", "b"); + + Branch.NameKey superBranchNameKey = + new Branch.NameKey(new Project.NameKey("super-project"), + "refs/heads/master"); + + List expectedSubscriptions = new ArrayList<>(); + expectedSubscriptions + .add(new SubmoduleSubscription(superBranchNameKey, new Branch.NameKey( + new Project.NameKey("a/b"), "refs/heads/master"), "a/b")); + execute(superBranchNameKey, sectionsToReturn, reposToBeFound, + expectedSubscriptions); + } + private void execute(final Branch.NameKey superProjectBranch, final Map sectionsToReturn, final Map reposToBeFound, @@ -213,11 +235,10 @@ public class SubmoduleSectionParserTest extends LocalDiskRepositoryTestCase { projectNameCandidate = projectNameCandidate.substring(0, // projectNameCandidate.length() - Constants.DOT_GIT_EXT.length()); } - if (projectNameCandidate.equals(reposToBeFound.get(id))) { + if (reposToBeFound.containsValue(projectNameCandidate)) { expect(repoManager.list()).andReturn( new TreeSet<>(Collections.singletonList( new Project.NameKey(projectNameCandidate)))); - break; } else { expect(repoManager.list()).andReturn( new TreeSet<>(Collections. emptyList()));