diff options
author | Yuxuan 'fishy' Wang <fishywang@google.com> | 2014-05-01 11:50:00 -0700 |
---|---|---|
committer | Yuxuan 'fishy' Wang <fishywang@google.com> | 2014-05-07 11:03:51 -0700 |
commit | 056135a1482a9d56ee5055d6bc2df5bea032b5e5 (patch) | |
tree | 6708f4aeeb3057fbc7cbdfa0884856936331a824 /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | 7f394cf16222f4066fe93e495ea682c2348039ca (diff) | |
download | jgit-056135a1482a9d56ee5055d6bc2df5bea032b5e5.tar.gz jgit-056135a1482a9d56ee5055d6bc2df5bea032b5e5.zip |
Handle repo submodules for bare repositories.
Change-Id: Id028a7bc9600baf0f3e2316a1f4b99e53ccc746a
Signed-off-by: Yuxuan 'fishy' Wang <fishywang@google.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index 27d3220797..b75738c905 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -50,9 +50,11 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; +import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Repository; import org.junit.Test; @@ -213,6 +215,45 @@ public class RepoCommandTest extends RepositoryTestCase { assertEquals("The destination file has expected content", "world", content); } + @Test + public void testBareRepo() throws Exception { + Repository remoteDb = createBareRepository(); + Repository tempDb = createWorkRepository(); + StringBuilder xmlContent = new StringBuilder(); + xmlContent.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") + .append("<manifest>") + .append("<remote name=\"remote1\" fetch=\".\" />") + .append("<default revision=\"master\" remote=\"remote1\" />") + .append("<project path=\"foo\" name=\"") + .append(defaultUri) + .append("\" />") + .append("</manifest>"); + JGitTestUtil.writeTrashFile(tempDb, "manifest.xml", xmlContent.toString()); + RepoCommand command = new RepoCommand(remoteDb); + command.setPath(tempDb.getWorkTree().getAbsolutePath() + "/manifest.xml") + .setURI(rootUri) + .call(); + // Clone it + File directory = createTempDirectory("testBareRepo"); + CloneCommand clone = Git.cloneRepository(); + clone.setDirectory(directory); + clone.setURI(remoteDb.getDirectory().toURI().toString()); + Repository localDb = clone.call().getRepository(); + // The .gitmodules file should exist + File gitmodules = new File(localDb.getWorkTree(), ".gitmodules"); + assertTrue("The .gitmodules file exists", gitmodules.exists()); + // The first line of .gitmodules file should be expected + BufferedReader reader = new BufferedReader(new FileReader(gitmodules)); + String content = reader.readLine(); + reader.close(); + assertEquals("The first line of .gitmodules file is as expected.", + "[submodule \"foo\"]", content); + // The gitlink should be the same of remote head sha1 + String gitlink = localDb.resolve(Constants.HEAD + ":foo").name(); + String remote = defaultDb.resolve(Constants.HEAD).name(); + assertEquals("The gitlink is same as remote head", remote, gitlink); + } + private void resolveRelativeUris() { // Find the longest common prefix ends with "/" as rootUri. defaultUri = defaultDb.getDirectory().toURI().toString(); |