From 056135a1482a9d56ee5055d6bc2df5bea032b5e5 Mon Sep 17 00:00:00 2001 From: Yuxuan 'fishy' Wang Date: Thu, 1 May 2014 11:50:00 -0700 Subject: Handle repo submodules for bare repositories. Change-Id: Id028a7bc9600baf0f3e2316a1f4b99e53ccc746a Signed-off-by: Yuxuan 'fishy' Wang --- .../org/eclipse/jgit/gitrepo/RepoCommandTest.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit') 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("\n") + .append("") + .append("") + .append("") + .append("") + .append(""); + 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(); -- cgit v1.2.3