diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2012-04-03 18:42:03 -0400 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org <gerrit@eclipse.org> | 2012-04-03 18:42:03 -0400 |
commit | 6a1a80aa4ce54a862056c0379b459115b298409d (patch) | |
tree | 2afb22b893ec79e84ef25804e5696b7ac7f06f68 /org.eclipse.jgit.test | |
parent | 0a84ad2d2ac8153d06564895279ab4fd11ef0e80 (diff) | |
parent | 543c5238ae3578f37cb9ada36b95775fa564e41d (diff) | |
download | jgit-6a1a80aa4ce54a862056c0379b459115b298409d.tar.gz jgit-6a1a80aa4ce54a862056c0379b459115b298409d.zip |
Merge "Recurse into cloned submodules"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CloneCommandTest.java | 87 |
1 files changed, 87 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 b63a4158f9..906a8966fa 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 @@ -69,6 +69,7 @@ import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.submodule.SubmoduleStatus; import org.eclipse.jgit.submodule.SubmoduleStatusType; +import org.eclipse.jgit.submodule.SubmoduleWalk; import org.eclipse.jgit.util.SystemReader; import org.junit.Test; @@ -304,6 +305,92 @@ public class CloneCommandTest extends RepositoryTestCase { } @Test + public void testCloneRepositoryWithNestedSubmodules() throws Exception { + git.checkout().setName(Constants.MASTER).call(); + + // Create submodule 1 + File submodule1 = createTempDirectory("testCloneRepositoryWithNestedSubmodules1"); + Git sub1Git = Git.init().setDirectory(submodule1).call(); + assertNotNull(sub1Git); + Repository sub1 = sub1Git.getRepository(); + assertNotNull(sub1); + addRepoToClose(sub1); + + String file = "file.txt"; + String path = "sub"; + + write(new File(sub1.getWorkTree(), file), "content"); + sub1Git.add().addFilepattern(file).call(); + RevCommit commit = sub1Git.commit().setMessage("create file").call(); + assertNotNull(commit); + + // Create submodule 2 + File submodule2 = createTempDirectory("testCloneRepositoryWithNestedSubmodules2"); + Git sub2Git = Git.init().setDirectory(submodule2).call(); + assertNotNull(sub2Git); + Repository sub2 = sub2Git.getRepository(); + assertNotNull(sub2); + addRepoToClose(sub2); + + write(new File(sub2.getWorkTree(), file), "content"); + sub2Git.add().addFilepattern(file).call(); + RevCommit sub2Head = sub2Git.commit().setMessage("create file").call(); + assertNotNull(sub2Head); + + // Add submodule 2 to submodule 1 + assertNotNull(sub1Git.submoduleAdd().setPath(path) + .setURI(sub2.getDirectory().toURI().toString()).call()); + RevCommit sub1Head = sub1Git.commit().setAll(true) + .setMessage("Adding submodule").call(); + assertNotNull(sub1Head); + + // Add submodule 1 to default repository + assertNotNull(git.submoduleAdd().setPath(path) + .setURI(sub1.getDirectory().toURI().toString()).call()); + assertNotNull(git.commit().setAll(true).setMessage("Adding submodule") + .call()); + + // Clone default repository and include submodules + File directory = createTempDirectory("testCloneRepositoryWithNestedSubmodules"); + CloneCommand clone = Git.cloneRepository(); + clone.setDirectory(directory); + clone.setCloneSubmodules(true); + clone.setURI(git.getRepository().getDirectory().toURI().toString()); + Git git2 = clone.call(); + addRepoToClose(git2.getRepository()); + assertNotNull(git2); + + assertEquals(Constants.MASTER, git2.getRepository().getBranch()); + assertTrue(new File(git2.getRepository().getWorkTree(), path + + File.separatorChar + file).exists()); + assertTrue(new File(git2.getRepository().getWorkTree(), path + + File.separatorChar + path + File.separatorChar + file) + .exists()); + + SubmoduleStatusCommand status = new SubmoduleStatusCommand( + git2.getRepository()); + Map<String, SubmoduleStatus> statuses = status.call(); + SubmoduleStatus pathStatus = statuses.get(path); + assertNotNull(pathStatus); + assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType()); + assertEquals(sub1Head, pathStatus.getHeadId()); + assertEquals(sub1Head, pathStatus.getIndexId()); + + SubmoduleWalk walk = SubmoduleWalk.forIndex(git2.getRepository()); + assertTrue(walk.next()); + Repository clonedSub1 = walk.getRepository(); + assertNotNull(clonedSub1); + status = new SubmoduleStatusCommand(clonedSub1); + statuses = status.call(); + pathStatus = statuses.get(path); + assertNotNull(pathStatus); + assertEquals(SubmoduleStatusType.INITIALIZED, pathStatus.getType()); + assertEquals(sub2Head, pathStatus.getHeadId()); + assertEquals(sub2Head, pathStatus.getIndexId()); + assertFalse(walk.next()); + } + + @Test public void testCloneWithAutoSetupRebase() throws Exception { File directory = createTempDirectory("testCloneRepository1"); CloneCommand command = Git.cloneRepository(); |