@ -248,46 +248,42 @@ public class RepoCommandTest extends RepositoryTestCase {
@Test
@Test
public void testBareRepo ( ) throws Exception {
public void testBareRepo ( ) throws Exception {
try (
Repository remoteDb = createBareRepository ( ) ;
Repository remoteDb = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "\" />" ) . append ( "</manifest>" ) ;
. append ( "\" />" ) . append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
xmlContent . toString ( ) ) ;
xmlContent . toString ( ) ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
command . setPath (
command . setPath (
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setURI ( rootUri ) . call ( ) ;
. setURI ( rootUri ) . call ( ) ;
// Clone it
// Clone it
File directory = createTempDirectory ( "testBareRepo" ) ;
File directory = createTempDirectory ( "testBareRepo" ) ;
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. getRepository ( ) ;
. getRepository ( ) ;
// The .gitmodules file should exist
// The .gitmodules file should exist
File gitmodules = new File ( localDb . getWorkTree ( ) , ".gitmodules" ) ;
File gitmodules = new File ( localDb . getWorkTree ( ) , ".gitmodules" ) ;
assertTrue ( "The .gitmodules file should exist" , gitmodules . exists ( ) ) ;
assertTrue ( "The .gitmodules file should exist" , gitmodules . exists ( ) ) ;
// The first line of .gitmodules file should be expected
// The first line of .gitmodules file should be expected
BufferedReader reader = new BufferedReader ( new FileReader ( gitmodules ) ) ;
BufferedReader reader = new BufferedReader ( new FileReader (
String content = reader . readLine ( ) ;
gitmodules ) ) ;
reader . close ( ) ;
String content = reader . readLine ( ) ;
assertEquals ( "The first line of .gitmodules file should be as expected" ,
reader . close ( ) ;
"[submodule \"foo\"]" , content ) ;
assertEquals (
// The gitlink should be the same as remote head sha1
"The first line of .gitmodules file should be as expected" ,
String gitlink = localDb . resolve ( Constants . HEAD + ":foo" ) . name ( ) ;
"[submodule \"foo\"]" , content ) ;
localDb . close ( ) ;
// The gitlink should be the same as remote head sha1
String remote = defaultDb . resolve ( Constants . HEAD ) . name ( ) ;
String gitlink = localDb . resolve ( Constants . HEAD + ":foo" ) . name ( ) ;
assertEquals ( "The gitlink should be the same as remote head" , remote ,
localDb . close ( ) ;
gitlink ) ;
String remote = defaultDb . resolve ( Constants . HEAD ) . name ( ) ;
assertEquals ( "The gitlink should be the same as remote head" ,
remote , gitlink ) ;
}
}
}
@Test
@Test
@ -370,208 +366,192 @@ public class RepoCommandTest extends RepositoryTestCase {
@Test
@Test
public void testRevisionBare ( ) throws Exception {
public void testRevisionBare ( ) throws Exception {
try (
Repository remoteDb = createBareRepository ( ) ;
Repository remoteDb = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"" ) . append ( BRANCH )
. append ( "<default revision=\"" ) . append ( BRANCH )
. append ( "\" remote=\"remote1\" />" )
. append ( "\" remote=\"remote1\" />" )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "\" />" ) . append ( "</manifest>" ) ;
. append ( "\" />" ) . append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
xmlContent . toString ( ) ) ;
xmlContent . toString ( ) ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
command . setPath (
command . setPath (
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setURI ( rootUri ) . call ( ) ;
. setURI ( rootUri ) . call ( ) ;
// Clone it
// Clone it
File directory = createTempDirectory ( "testRevisionBare" ) ;
File directory = createTempDirectory ( "testRevisionBare" ) ;
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. getRepository ( ) ;
. getRepository ( ) ;
// The gitlink should be the same as oldCommitId
// The gitlink should be the same as oldCommitId
String gitlink = localDb . resolve ( Constants . HEAD + ":foo" ) . name ( ) ;
String gitlink = localDb . resolve ( Constants . HEAD + ":foo" ) . name ( ) ;
localDb . close ( ) ;
localDb . close ( ) ;
assertEquals ( "The gitlink is same as remote head" ,
assertEquals ( "The gitlink is same as remote head" , oldCommitId . name ( ) ,
oldCommitId . name ( ) , gitlink ) ;
gitlink ) ;
}
}
}
@Test
@Test
public void testCopyFileBare ( ) throws Exception {
public void testCopyFileBare ( ) throws Exception {
try (
Repository remoteDb = createBareRepository ( ) ;
Repository remoteDb = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "\" revision=\"" ) . append ( BRANCH ) . append ( "\" >" )
. append ( "\" revision=\"" ) . append ( BRANCH ) . append ( "\" >" )
. append ( "<copyfile src=\"hello.txt\" dest=\"Hello\" />" )
. append ( "<copyfile src=\"hello.txt\" dest=\"Hello\" />" )
. append ( "<copyfile src=\"hello.txt\" dest=\"foo/Hello\" />" )
. append ( "<copyfile src=\"hello.txt\" dest=\"foo/Hello\" />" )
. append ( "</project>" ) . append ( "</manifest>" ) ;
. append ( "</project>" ) . append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
xmlContent . toString ( ) ) ;
xmlContent . toString ( ) ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
command . setPath (
command . setPath (
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setURI ( rootUri ) . call ( ) ;
. setURI ( rootUri ) . call ( ) ;
// Clone it
// Clone it
File directory = createTempDirectory ( "testCopyFileBare" ) ;
File directory = createTempDirectory ( "testCopyFileBare" ) ;
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. getRepository ( ) ;
. getRepository ( ) ;
// The Hello file should exist
// The Hello file should exist
File hello = new File ( localDb . getWorkTree ( ) , "Hello" ) ;
File hello = new File ( localDb . getWorkTree ( ) , "Hello" ) ;
assertTrue ( "The Hello file should exist" , hello . exists ( ) ) ;
assertTrue ( "The Hello file should exist" , hello . exists ( ) ) ;
// The foo/Hello file should be skipped.
// The foo/Hello file should be skipped.
File foohello = new File ( localDb . getWorkTree ( ) , "foo/Hello" ) ;
File foohello = new File ( localDb . getWorkTree ( ) , "foo/Hello" ) ;
assertFalse ( "The foo/Hello file should be skipped" , foohello . exists ( ) ) ;
assertFalse (
localDb . close ( ) ;
"The foo/Hello file should be skipped" , foohello . exists ( ) ) ;
// The content of Hello file should be expected
localDb . close ( ) ;
BufferedReader reader = new BufferedReader ( new FileReader ( hello ) ) ;
// The content of Hello file should be expected
String content = reader . readLine ( ) ;
BufferedReader reader = new BufferedReader ( new FileReader ( hello ) ) ;
reader . close ( ) ;
String content = reader . readLine ( ) ;
assertEquals ( "The Hello file should have expected content" ,
reader . close ( ) ;
"branch world" , content ) ;
assertEquals ( "The Hello file should have expected content" ,
"branch world" , content ) ;
}
}
}
@Test
@Test
public void testReplaceManifestBare ( ) throws Exception {
public void testReplaceManifestBare ( ) throws Exception {
try (
Repository remoteDb = createBareRepository ( ) ;
Repository remoteDb = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "\" revision=\"" ) . append ( BRANCH ) . append ( "\" >" )
. append ( "\" revision=\"" ) . append ( BRANCH ) . append ( "\" >" )
. append ( "<copyfile src=\"hello.txt\" dest=\"Hello\" />" )
. append ( "<copyfile src=\"hello.txt\" dest=\"Hello\" />" )
. append ( "</project>" ) . append ( "</manifest>" ) ;
. append ( "</project>" ) . append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "old.xml" , xmlContent . toString ( ) ) ;
JGitTestUtil . writeTrashFile ( tempDb , "old.xml" ,
RepoCommand command = new RepoCommand ( remoteDb ) ;
xmlContent . toString ( ) ) ;
command . setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/old.xml" )
RepoCommand command = new RepoCommand ( remoteDb ) ;
. setURI ( rootUri ) . call ( ) ;
command . setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/old.xml" )
xmlContent = new StringBuilder ( ) ;
. setURI ( rootUri ) . call ( ) ;
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
xmlContent = new StringBuilder ( ) ;
. append ( "<manifest>" )
xmlContent
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<manifest>" )
. append ( "<project path=\"bar\" name=\"" ) . append ( defaultUri )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "\" revision=\"" ) . append ( BRANCH ) . append ( "\" >" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<copyfile src=\"hello.txt\" dest=\"Hello.txt\" />" )
. append ( "<project path=\"bar\" name=\"" )
. append ( "</project>" ) . append ( "</manifest>" ) ;
. append ( defaultUri )
JGitTestUtil . writeTrashFile ( tempDb , "new.xml" , xmlContent . toString ( ) ) ;
. append ( "\" revision=\"" )
command = new RepoCommand ( remoteDb ) ;
. append ( BRANCH )
command . setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/new.xml" )
. append ( "\" >" )
. setURI ( rootUri ) . call ( ) ;
. append ( "<copyfile src=\"hello.txt\" dest=\"Hello.txt\" />" )
// Clone it
. append ( "</project>" ) . append ( "</manifest>" ) ;
File directory = createTempDirectory ( "testReplaceManifestBare" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "new.xml" ,
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
xmlContent . toString ( ) ) ;
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
command = new RepoCommand ( remoteDb ) ;
. getRepository ( ) ;
command . setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/new.xml" )
// The Hello file should not exist
. setURI ( rootUri ) . call ( ) ;
File hello = new File ( localDb . getWorkTree ( ) , "Hello" ) ;
// Clone it
assertFalse ( "The Hello file shouldn't exist" , hello . exists ( ) ) ;
File directory = createTempDirectory ( "testReplaceManifestBare" ) ;
// The Hello.txt file should exist
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
File hellotxt = new File ( localDb . getWorkTree ( ) , "Hello.txt" ) ;
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
assertTrue ( "The Hello.txt file should exist" , hellotxt . exists ( ) ) ;
. getRepository ( ) ;
// The .gitmodules file should have 'submodule "bar"' and shouldn't
// The Hello file should not exist
// have
File hello = new File ( localDb . getWorkTree ( ) , "Hello" ) ;
// 'submodule "foo"' lines.
assertFalse ( "The Hello file shouldn't exist" , hello . exists ( ) ) ;
File dotmodules = new File ( localDb . getWorkTree ( ) ,
// The Hello.txt file should exist
Constants . DOT_GIT_MODULES ) ;
File hellotxt = new File ( localDb . getWorkTree ( ) , "Hello.txt" ) ;
localDb . close ( ) ;
assertTrue ( "The Hello.txt file should exist" , hellotxt . exists ( ) ) ;
BufferedReader reader = new BufferedReader ( new FileReader ( dotmodules ) ) ;
// The .gitmodules file should have 'submodule "bar"' and shouldn't
boolean foo = false ;
// have
boolean bar = false ;
// 'submodule "foo"' lines.
while ( true ) {
File dotmodules = new File ( localDb . getWorkTree ( ) ,
String line = reader . readLine ( ) ;
Constants . DOT_GIT_MODULES ) ;
if ( line = = null )
localDb . close ( ) ;
break ;
BufferedReader reader = new BufferedReader ( new FileReader (
if ( line . contains ( "submodule \"foo\"" ) )
dotmodules ) ) ;
foo = true ;
boolean foo = false ;
if ( line . contains ( "submodule \"bar\"" ) )
boolean bar = false ;
bar = true ;
while ( true ) {
String line = reader . readLine ( ) ;
if ( line = = null )
break ;
if ( line . contains ( "submodule \"foo\"" ) )
foo = true ;
if ( line . contains ( "submodule \"bar\"" ) )
bar = true ;
}
reader . close ( ) ;
assertTrue ( "The bar submodule should exist" , bar ) ;
assertFalse ( "The foo submodule shouldn't exist" , foo ) ;
}
}
reader . close ( ) ;
assertTrue ( "The bar submodule should exist" , bar ) ;
assertFalse ( "The foo submodule shouldn't exist" , foo ) ;
}
}
@Test
@Test
public void testRemoveOverlappingBare ( ) throws Exception {
public void testRemoveOverlappingBare ( ) throws Exception {
try (
Repository remoteDb = createBareRepository ( ) ;
Repository remoteDb = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<project path=\"foo/bar\" name=\"" ) . append ( groupBUri )
. append ( "<project path=\"foo/bar\" name=\"" )
. append ( "\" />" ) . append ( "<project path=\"a\" name=\"" )
. append ( groupBUri ) . append ( "\" />" )
. append ( groupAUri ) . append ( "\" />" )
. append ( "<project path=\"a\" name=\"" ) . append ( groupAUri )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "\" />" ) . append ( "<project path=\"foo\" name=\"" )
. append ( "\" />" ) . append ( "</manifest>" ) ;
. append ( defaultUri ) . append ( "\" />" ) . append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
xmlContent . toString ( ) ) ;
xmlContent . toString ( ) ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
command . setPath (
command . setPath (
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setURI ( rootUri ) . call ( ) ;
. setURI ( rootUri ) . call ( ) ;
// Clone it
// Clone it
File directory = createTempDirectory ( "testRemoveOverlappingBare" ) ;
File directory = createTempDirectory ( "testRemoveOverlappingBare" ) ;
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. getRepository ( ) ;
. getRepository ( ) ;
// The .gitmodules file should have 'submodule "foo"' and shouldn't
// The .gitmodules file should have 'submodule "foo"' and shouldn't
// have
// have
// 'submodule "foo/bar"' lines.
// 'submodule "foo/bar"' lines.
File dotmodules = new File ( localDb . getWorkTree ( ) ,
File dotmodules = new File ( localDb . getWorkTree ( ) ,
Constants . DOT_GIT_MODULES ) ;
Constants . DOT_GIT_MODULES ) ;
localDb . close ( ) ;
localDb . close ( ) ;
BufferedReader reader = new BufferedReader ( new FileReader ( dotmodules ) ) ;
BufferedReader reader = new BufferedReader ( new FileReader (
boolean foo = false ;
dotmodules ) ) ;
boolean foobar = false ;
boolean foo = false ;
boolean a = false ;
boolean foobar = false ;
while ( true ) {
boolean a = false ;
String line = reader . readLine ( ) ;
while ( true ) {
if ( line = = null )
String line = reader . readLine ( ) ;
break ;
if ( line = = null )
if ( line . contains ( "submodule \"foo\"" ) )
break ;
foo = true ;
if ( line . contains ( "submodule \"foo\"" ) )
if ( line . contains ( "submodule \"foo/bar\"" ) )
foo = true ;
foobar = true ;
if ( line . contains ( "submodule \"foo/bar\"" ) )
if ( line . contains ( "submodule \"a\"" ) )
foobar = true ;
a = true ;
if ( line . contains ( "submodule \"a\"" ) )
a = true ;
}
reader . close ( ) ;
assertTrue ( "The foo submodule should exist" , foo ) ;
assertFalse ( "The foo/bar submodule shouldn't exist" , foobar ) ;
assertTrue ( "The a submodule should exist" , a ) ;
}
}
reader . close ( ) ;
assertTrue ( "The foo submodule should exist" , foo ) ;
assertFalse ( "The foo/bar submodule shouldn't exist" , foobar ) ;
assertTrue ( "The a submodule should exist" , a ) ;
}
}
@Test
@Test
@ -670,178 +650,157 @@ public class RepoCommandTest extends RepositoryTestCase {
@Test
@Test
public void testTargetBranch ( ) throws Exception {
public void testTargetBranch ( ) throws Exception {
try (
Repository remoteDb1 = createBareRepository ( ) ;
Repository remoteDb1 = createBareRepository ( ) ;
Repository remoteDb2 = createBareRepository ( ) ;
Repository remoteDb2 = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "<project path=\"foo\" name=\"" ) . append ( defaultUri )
. append ( "\" />" ) . append ( "</manifest>" ) ;
. append ( "\" />" ) . append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
xmlContent . toString ( ) ) ;
xmlContent . toString ( ) ) ;
RepoCommand command = new RepoCommand ( remoteDb1 ) ;
RepoCommand command = new RepoCommand ( remoteDb1 ) ;
command . setPath (
command
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setURI ( rootUri ) . setTargetBranch ( "test" ) . call ( ) ;
. setURI ( rootUri )
ObjectId branchId = remoteDb1
. setTargetBranch ( "test" )
. resolve ( Constants . R_HEADS + "test^{tree}" ) ;
. call ( ) ;
command = new RepoCommand ( remoteDb2 ) ;
ObjectId branchId = remoteDb1 . resolve (
command . setPath (
Constants . R_HEADS + "test^{tree}" ) ;
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
command = new RepoCommand ( remoteDb2 ) ;
. setURI ( rootUri ) . call ( ) ;
command
ObjectId defaultId = remoteDb2 . resolve ( Constants . HEAD + "^{tree}" ) ;
. setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
assertEquals (
. setURI ( rootUri )
. call ( ) ;
ObjectId defaultId = remoteDb2 . resolve ( Constants . HEAD + "^{tree}" ) ;
assertEquals (
"The tree id of branch db and default db should be the same" ,
"The tree id of branch db and default db should be the same" ,
branchId , defaultId ) ;
branchId , defaultId ) ;
}
}
}
@Test
@Test
public void testRecordRemoteBranch ( ) throws Exception {
public void testRecordRemoteBranch ( ) throws Exception {
try (
Repository remoteDb = createBareRepository ( ) ;
Repository remoteDb = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<project path=\"with-branch\" " )
. append ( "<project path=\"with-branch\" " )
. append ( "revision=\"master\" " )
. append ( "revision=\"master\" " ) . append ( "name=\" " )
. append ( "name=\"" ) . append ( notDefaultUri ) . append ( "\" />" )
. append ( notDefaultUri ) . append ( "\" />" )
. append ( "<project path=\"with-long-branch\" " )
. append ( "<project path=\"with-long-branch\" " )
. append ( "revision=\"refs/heads/master\" " )
. append ( "revision=\"refs/heads/master\" " ) . append ( "name=\"" )
. append ( "name=\"" ) . append ( defaultUri ) . append ( "\" />" )
. append ( defaultUri ) . append ( "\" />" ) . append ( "</manifest>" ) ;
. append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
xmlContent . toString ( ) ) ;
xmlContent . toString ( ) ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
command . setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
command . setPath (
. setURI ( rootUri )
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setRecordRemoteBranch ( true )
. setURI ( rootUri ) . setRecordRemoteBranch ( true ) . call ( ) ;
. call ( ) ;
// Clone it
// Clone it
File directory = createTempDirectory ( "testBareRepo" ) ;
File directory = createTempDirectory ( "testBareRepo" ) ;
try ( Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
try ( Repository localDb = Git . cloneRepository ( )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. setDirectory ( directory )
. getRepository ( ) ; ) {
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
// The .gitmodules file should exist
. getRepository ( ) ; ) {
File gitmodules = new File ( localDb . getWorkTree ( ) , ".gitmodules" ) ;
// The .gitmodules file should exist
assertTrue ( "The .gitmodules file should exist" ,
File gitmodules = new File ( localDb . getWorkTree ( ) ,
gitmodules . exists ( ) ) ;
".gitmodules" ) ;
FileBasedConfig c = new FileBasedConfig ( gitmodules , FS . DETECTED ) ;
assertTrue ( "The .gitmodules file should exist" ,
c . load ( ) ;
gitmodules . exists ( ) ) ;
assertEquals (
FileBasedConfig c = new FileBasedConfig ( gitmodules ,
"Recording remote branches should work for short branch descriptions" ,
FS . DETECTED ) ;
"master" ,
c . load ( ) ;
c . getString ( "submodule" , "with-branch" , "branch" ) ) ;
assertEquals ( "Recording remote branches should work for short branch descriptions" , "master" ,
assertEquals (
c . getString ( "submodule" , "with-branch" , "branch" ) ) ;
"Recording remote branches should work for full ref specs" ,
assertEquals ( "Recording remote branches should work for full ref specs" , "refs/heads/master" ,
"refs/heads/master" ,
c . getString ( "submodule" , "with-long-branch" , "branch" ) ) ;
c . getString ( "submodule" , "with-long-branch" , "branch" ) ) ;
}
}
}
}
}
@Test
@Test
public void testRecordSubmoduleLabels ( ) throws Exception {
public void testRecordSubmoduleLabels ( ) throws Exception {
try (
Repository remoteDb = createBareRepository ( ) ;
Repository remoteDb = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<project path=\"test\" " )
. append ( "<project path=\"test\" " )
. append ( "revision=\"master\" " )
. append ( "revision=\"master\" " ) . append ( "name=\"" )
. append ( "name=\"" ) . append ( notDefaultUri ) . append ( "\" " )
. append ( notDefaultUri ) . append ( "\" " )
. append ( "groups=\"a1,a2\" />" )
. append ( "groups=\"a1,a2\" />" ) . append ( "</manifest>" ) ;
. append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
xmlContent . toString ( ) ) ;
xmlContent . toString ( ) ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
command . setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
command . setPath (
. setURI ( rootUri )
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setRecordSubmoduleLabels ( true )
. setURI ( rootUri ) . setRecordSubmoduleLabels ( true ) . call ( ) ;
. call ( ) ;
// Clone it
// Clone it
File directory = createTempDirectory ( "testBareRepo" ) ;
File directory = createTempDirectory ( "testBareRepo" ) ;
try ( Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
try ( Repository localDb = Git . cloneRepository ( )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. setDirectory ( directory )
. getRepository ( ) ; ) {
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
// The .gitattributes file should exist
. getRepository ( ) ; ) {
File gitattributes = new File ( localDb . getWorkTree ( ) ,
// The .gitattributes file should exist
File gitattributes = new File ( localDb . getWorkTree ( ) ,
".gitattributes" ) ;
".gitattributes" ) ;
assertTrue ( "The .gitattributes file should exist" ,
assertTrue ( "The .gitattributes file should exist" ,
gitattributes . exists ( ) ) ;
gitattributes . exists ( ) ) ;
try ( BufferedReader reader = new BufferedReader (
try ( BufferedReader reader = new BufferedReader (
new FileReader ( gitattributes ) ) ; ) {
new FileReader ( gitattributes ) ) ; ) {
String content = reader . readLine ( ) ;
String content = reader . readLine ( ) ;
assertEquals ( ".gitattributes content should be as expected" ,
assertEquals ( ".gitattributes content should be as expected" ,
"/test a1 a2" , content ) ;
"/test a1 a2" , content ) ;
}
}
}
}
}
}
}
@Test
@Test
public void testRecordShallowRecommendation ( ) throws Exception {
public void testRecordShallowRecommendation ( ) throws Exception {
try (
Repository remoteDb = createBareRepository ( ) ;
Repository remoteDb = createBareRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ;
Repository tempDb = createWorkRepository ( ) ) {
StringBuilder xmlContent = new StringBuilder ( ) ;
StringBuilder xmlContent = new StringBuilder ( ) ;
xmlContent
xmlContent . append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" )
. append ( "<manifest>" )
. append ( "<manifest>" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<remote name=\"remote1\" fetch=\".\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<default revision=\"master\" remote=\"remote1\" />" )
. append ( "<project path=\"shallow-please\" " )
. append ( "<project path=\"shallow-please\" " ) . append ( "name=\"" )
. append ( "name=\"" ) . append ( defaultUri ) . append ( "\" " )
. append ( defaultUri ) . append ( "\" " ) . append ( "clone-depth=\"1\" />" )
. append ( "clone-depth=\"1\" />" )
. append ( "<project path=\"non-shallow\" " ) . append ( "name=\"" )
. append ( "<project path=\"non-shallow\" " )
. append ( defaultUri ) . append ( "\" />" ) . append ( "</manifest>" ) ;
. append ( "name=\"" ) . append ( defaultUri ) . append ( "\" />" )
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
. append ( "</manifest>" ) ;
JGitTestUtil . writeTrashFile ( tempDb , "manifest.xml" ,
xmlContent . toString ( ) ) ;
xmlContent . toString ( ) ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
RepoCommand command = new RepoCommand ( remoteDb ) ;
command . setPath ( tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
command . setPath (
. setURI ( rootUri )
tempDb . getWorkTree ( ) . getAbsolutePath ( ) + "/manifest.xml" )
. setRecommendShallow ( true )
. setURI ( rootUri ) . setRecommendShallow ( true ) . call ( ) ;
. call ( ) ;
// Clone it
// Clone it
File directory = createTempDirectory ( "testBareRepo" ) ;
File directory = createTempDirectory ( "testBareRepo" ) ;
try ( Repository localDb = Git . cloneRepository ( ) . setDirectory ( directory )
try ( Repository localDb = Git . cloneRepository ( )
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
. setDirectory ( directory )
. getRepository ( ) ; ) {
. setURI ( remoteDb . getDirectory ( ) . toURI ( ) . toString ( ) ) . call ( )
// The .gitmodules file should exist
. getRepository ( ) ; ) {
File gitmodules = new File ( localDb . getWorkTree ( ) , ".gitmodules" ) ;
// The .gitmodules file should exist
assertTrue ( "The .gitmodules file should exist" ,
File gitmodules = new File ( localDb . getWorkTree ( ) ,
gitmodules . exists ( ) ) ;
".gitmodules" ) ;
FileBasedConfig c = new FileBasedConfig ( gitmodules , FS . DETECTED ) ;
assertTrue ( "The .gitmodules file should exist" ,
c . load ( ) ;
gitmodules . exists ( ) ) ;
assertEquals ( "Recording shallow configuration should work" , "true" ,
FileBasedConfig c = new FileBasedConfig ( gitmodules ,
c . getString ( "submodule" , "shallow-please" , "shallow" ) ) ;
FS . DETECTED ) ;
assertNull ( "Recording non shallow configuration should work" ,
c . load ( ) ;
c . getString ( "submodule" , "non-shallow" , "shallow" ) ) ;
assertEquals ( "Recording shallow configuration should work" , "true" ,
c . getString ( "submodule" , "shallow-please" , "shallow" ) ) ;
assertNull ( "Recording non shallow configuration should work" ,
c . getString ( "submodule" , "non-shallow" , "shallow" ) ) ;
}
}
}
}
}