|
|
|
@ -51,6 +51,7 @@ import java.io.File;
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
import org.eclipse.jgit.api.ListBranchCommand.ListMode; |
|
|
|
|
import org.eclipse.jgit.api.errors.JGitInternalException; |
|
|
|
@ -63,6 +64,9 @@ import org.eclipse.jgit.lib.RefUpdate;
|
|
|
|
|
import org.eclipse.jgit.lib.Repository; |
|
|
|
|
import org.eclipse.jgit.lib.RepositoryTestCase; |
|
|
|
|
import org.eclipse.jgit.revwalk.RevBlob; |
|
|
|
|
import org.eclipse.jgit.revwalk.RevCommit; |
|
|
|
|
import org.eclipse.jgit.submodule.SubmoduleStatus; |
|
|
|
|
import org.eclipse.jgit.submodule.SubmoduleStatusType; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
public class CloneCommandTest extends RepositoryTestCase { |
|
|
|
@ -252,4 +256,47 @@ public class CloneCommandTest extends RepositoryTestCase {
|
|
|
|
|
|
|
|
|
|
assertEquals(Constants.MASTER, git2.getRepository().getBranch()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCloneRepositoryWithSubmodules() throws Exception { |
|
|
|
|
git.checkout().setName(Constants.MASTER).call(); |
|
|
|
|
|
|
|
|
|
String file = "file.txt"; |
|
|
|
|
writeTrashFile(file, "content"); |
|
|
|
|
git.add().addFilepattern(file).call(); |
|
|
|
|
RevCommit commit = git.commit().setMessage("create file").call(); |
|
|
|
|
|
|
|
|
|
SubmoduleAddCommand command = new SubmoduleAddCommand(db); |
|
|
|
|
String path = "sub"; |
|
|
|
|
command.setPath(path); |
|
|
|
|
String uri = db.getDirectory().toURI().toString(); |
|
|
|
|
command.setURI(uri); |
|
|
|
|
Repository repo = command.call(); |
|
|
|
|
assertNotNull(repo); |
|
|
|
|
git.add().addFilepattern(path) |
|
|
|
|
.addFilepattern(Constants.DOT_GIT_MODULES).call(); |
|
|
|
|
git.commit().setMessage("adding submodule").call(); |
|
|
|
|
|
|
|
|
|
File directory = createTempDirectory("testCloneRepositoryWithSubmodules"); |
|
|
|
|
CloneCommand clone = Git.cloneRepository(); |
|
|
|
|
clone.setDirectory(directory); |
|
|
|
|
clone.setCloneSubmodules(true); |
|
|
|
|
clone.setURI("file://" + git.getRepository().getWorkTree().getPath()); |
|
|
|
|
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()); |
|
|
|
|
|
|
|
|
|
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(commit, pathStatus.getHeadId()); |
|
|
|
|
assertEquals(commit, pathStatus.getIndexId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|