Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick2014-12-10 16:54:28 +0000
committerMatthias Sohn2014-12-14 23:22:51 +0000
commit53ff0529988ae8ec6f75a1f3d1b7b75de7dc304f (patch)
tree996b5851777632e5f3170589364eb078262b0a25
parent6e05d98cce318056f95700e562cec6b68fcf7475 (diff)
downloadjgit-53ff0529988ae8ec6f75a1f3d1b7b75de7dc304f.tar.gz
jgit-53ff0529988ae8ec6f75a1f3d1b7b75de7dc304f.tar.xz
jgit-53ff0529988ae8ec6f75a1f3d1b7b75de7dc304f.zip
Support the new repository layout for submodules
When updating a submodule (e.g. during recursive clone) the repository for the submodule should be located at <gitdir>/modules/<submodule-path> whereas the working tree of the submodule should be located at <working-tree>/<submodule-path> (<gitdir> and <working-tree> are associated to the containing repository). Since CloneCommand has learned about specifying a separate gitdir this is easy to implement in SubmoduleUpdateCommand. Change-Id: I9b56a3dfa50f97f6975c2bb7c97b36296f331b64
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java18
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleUpdateCommand.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java7
3 files changed, 28 insertions, 0 deletions
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 06829fa4db..ece1b324b0 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 class CloneCommandTest extends RepositoryTestCase {
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 class CloneCommandTest extends RepositoryTestCase {
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 de1a3e9fd0..81a30156a6 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 class SubmoduleUpdateCommand extends
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 32ccc7c335..f149749843 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java
@@ -373,6 +373,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.
*
* @return a new digest object.

Back to the top