aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2017-08-29 09:37:30 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2017-09-04 09:19:03 +0200
commit06ea633c1837e48934be62714ff40be149887301 (patch)
tree30bb730aa534e9453f5c42ccabb5057463b24849 /org.eclipse.jgit.test/tst/org/eclipse/jgit
parent7317432c313f10a26e92eea50bcbf87d46a53bf7 (diff)
downloadjgit-06ea633c1837e48934be62714ff40be149887301.tar.gz
jgit-06ea633c1837e48934be62714ff40be149887301.zip
Don't assume name = path in .gitmodules
While parsing .gitmodules, the name of the submodule subsection is purely arbitrary: it frequently is the path of the submodule, but there's no requirement for it to be. By building a map of paths to the section name in .gitmodules, we can more accurately return the submodule URL. Bug: 508801 Change-Id: I8399ccada1834d4cc5d023344b97dcf8d5869b16 Also-by: Doug Kelly <dougk.ff7@gmail.com> Signed-off-by: Doug Kelly <dougk.ff7@gmail.com> Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch> Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
index 8998a85462..fed22c0262 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
@@ -444,4 +444,44 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
assertNull(gen.getRepository());
assertFalse(gen.next());
}
+
+ @Test
+ public void testTreeIteratorWithGitmodulesNameNotPath() throws Exception {
+ final ObjectId subId = ObjectId
+ .fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
+ final String path = "sub";
+ final String arbitraryName = "x";
+
+ final Config gitmodules = new Config();
+ gitmodules.setString(CONFIG_SUBMODULE_SECTION, arbitraryName,
+ CONFIG_KEY_PATH, "sub");
+ gitmodules.setString(CONFIG_SUBMODULE_SECTION, arbitraryName,
+ CONFIG_KEY_URL, "git://example.com/sub");
+
+ RevCommit commit = testDb.getRevWalk()
+ .parseCommit(testDb.commit().noParents()
+ .add(DOT_GIT_MODULES, gitmodules.toText())
+ .edit(new PathEdit(path) {
+
+ @Override
+ public void apply(DirCacheEntry ent) {
+ ent.setFileMode(FileMode.GITLINK);
+ ent.setObjectId(subId);
+ }
+ }).create());
+
+ final CanonicalTreeParser p = new CanonicalTreeParser();
+ p.reset(testDb.getRevWalk().getObjectReader(), commit.getTree());
+ SubmoduleWalk gen = SubmoduleWalk.forPath(db, p, "sub");
+ assertEquals(path, gen.getPath());
+ assertEquals(subId, gen.getObjectId());
+ assertEquals(new File(db.getWorkTree(), path), gen.getDirectory());
+ assertNull(gen.getConfigUpdate());
+ assertNull(gen.getConfigUrl());
+ assertEquals("sub", gen.getModulesPath());
+ assertNull(gen.getModulesUpdate());
+ assertEquals("git://example.com/sub", gen.getModulesUrl());
+ assertNull(gen.getRepository());
+ assertFalse(gen.next());
+ }
}