diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java index 06829fa4d..ece1b324b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java @@ -410,6 +410,18 @@ public void testCloneRepositoryWithSubmodules() throws Exception { assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType()); assertEquals(commit, pathStatus.getHeadId()); assertEquals(commit, pathStatus.getIndexId()); + + SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository()); + assertTrue(walk.next()); + Repository clonedSub1 = walk.getRepository(); + addRepoToClose(clonedSub1); + assertNotNull(clonedSub1); + assertEquals( + new File(git2.getRepository().getWorkTree(), walk.getPath()), + clonedSub1.getWorkTree()); + assertEquals(new File(new File(git2.getRepository().getDirectory(), + "modules"), walk.getPath()), clonedSub1.getDirectory()); + walk.release(); } @Test @@ -492,6 +504,12 @@ public void testCloneRepositoryWithNestedSubmodules() throws Exception { assertTrue(walk.next()); Repository clonedSub1 = walk.getRepository(); assertNotNull(clonedSub1); + assertEquals( + new File(git2.getRepository().getWorkTree(), walk.getPath()), + clonedSub1.getWorkTree()); + assertEquals(new File(new File(git2.getRepository().getDirectory(), + "modules"), walk.getPath()), + clonedSub1.getDirectory()); status = new SubmoduleStatusCommand(clonedSub1); statuses = status.call(); clonedSub1.close(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java index de1a3e9fd..81a30156a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java @@ -42,6 +42,7 @@ */ package org.eclipse.jgit.api; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; @@ -163,6 +164,8 @@ public Collection call() throws InvalidConfigurationException, configure(clone); clone.setURI(url); clone.setDirectory(generator.getDirectory()); + clone.setGitDir(new File(new File(repo.getDirectory(), + Constants.MODULES), generator.getPath())); if (monitor != null) clone.setProgressMonitor(monitor); submoduleRepo = clone.call().getRepository(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java index 32ccc7c33..f14974984 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -372,6 +372,13 @@ public final class Constants { */ public static final String GITDIR = "gitdir: "; + /** + * Name of the folder (inside gitDir) where submodules are stored + * + * @since 3.6 + */ + public static final String MODULES = "modules"; + /** * Create a new digest function for objects. *