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
This commit is contained in:
Janice Agustin
2015-07-28 10:59:31 -04:00
committed by David Pursehouse
parent 77d5a0a7fb
commit 0573f65bff
2 changed files with 26 additions and 4 deletions

View File

@@ -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()));