@ -69,6 +69,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig ;
import org.eclipse.jgit.storage.file.FileBasedConfig ;
import org.eclipse.jgit.submodule.SubmoduleStatus ;
import org.eclipse.jgit.submodule.SubmoduleStatus ;
import org.eclipse.jgit.submodule.SubmoduleStatusType ;
import org.eclipse.jgit.submodule.SubmoduleStatusType ;
import org.eclipse.jgit.submodule.SubmoduleWalk ;
import org.eclipse.jgit.util.SystemReader ;
import org.eclipse.jgit.util.SystemReader ;
import org.junit.Test ;
import org.junit.Test ;
@ -303,6 +304,92 @@ public class CloneCommandTest extends RepositoryTestCase {
assertEquals ( commit , pathStatus . getIndexId ( ) ) ;
assertEquals ( commit , pathStatus . getIndexId ( ) ) ;
}
}
@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
@Test
public void testCloneWithAutoSetupRebase ( ) throws Exception {
public void testCloneWithAutoSetupRebase ( ) throws Exception {
File directory = createTempDirectory ( "testCloneRepository1" ) ;
File directory = createTempDirectory ( "testCloneRepository1" ) ;