summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanice Agustin <janice.agustin@ericsson.com>2015-07-28 10:59:31 -0400
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2015-07-30 12:16:52 +0000
commit0573f65bff60e2c00032911fcd768fd5969dbc43 (patch)
treef2bb1088cf74f4b1d091b58370a53084b1ad5f65
parent77d5a0a7fb81e3d625dd03422f48133928c48a95 (diff)
Subscribe to proper project when nested projects exist
Submodule subscription would parse from the end of the url and return a subscription to the first project it would find. Now, continue to parse the url and subscribe to the project found with the most complete name. Example: Project "a/b" exists Project "b" exists Submodule subscription url = ../a/b Old behaviour: Would subscribe to project "b" Expected: Subscription to project "a/b" Change-Id: I284b681d3098ff6ec2915fc90a047e2f329babfd
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/util/SubmoduleSectionParser.java5
-rw-r--r--gerrit-server/src/test/java/com/google/gerrit/server/util/SubmoduleSectionParserTest.java25
2 files changed, 26 insertions, 4 deletions
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<SubmoduleSubscription>());
}
+ @Test
+ public void testSubmodulesParseWithSubProjectFound() throws Exception {
+ Map<String, SubmoduleSection> sectionsToReturn = new TreeMap<>();
+ sectionsToReturn.put("a/b", new SubmoduleSection(
+ "ssh://localhost/a/b", "a/b", "."));
+
+ Map<String, String> 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<SubmoduleSubscription> 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<String, SubmoduleSection> sectionsToReturn,
final Map<String, String> 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.<Project.NameKey> emptyList()));