@ -46,12 +46,14 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse ;
import static org.junit.Assert.assertNull ;
import static org.junit.Assert.assertTrue ;
import static org.junit.Assert.fail ;
import java.io.BufferedReader ;
import java.io.ByteArrayInputStream ;
import java.io.File ;
import java.io.FileReader ;
import java.io.IOException ;
import java.net.URI ;
import java.nio.charset.StandardCharsets ;
import java.util.HashMap ;
import java.util.Map ;
@ -183,6 +185,107 @@ public class RepoCommandTest extends RepositoryTestCase {
}
}
@Test
public void androidSetup ( ) throws Exception {
Repository child = Git . cloneRepository ( )
. setURI ( groupADb . getDirectory ( ) . toURI ( ) . toString ( ) )
. setDirectory ( createUniqueTestGitDir ( true ) ) . setBare ( true ) . call ( )
. getRepository ( ) ;
Repository dest = Git . cloneRepository ( )
. setURI ( db . getDirectory ( ) . toURI ( ) . toString ( ) )
. setDirectory ( createUniqueTestGitDir ( true ) ) . setBare ( true ) . call ( )
. getRepository ( ) ;
assertTrue ( dest . isBare ( ) ) ;
assertTrue ( child . isBare ( ) ) ;
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=\"base\" name=\"platform/base\" />" )
. append ( "</manifest>" ) ;
RepoCommand cmd = new RepoCommand ( dest ) ;
IndexedRepos repos = new IndexedRepos ( ) ;
repos . put ( "platform/base" , child ) ;
RevCommit commit = cmd
. setInputStream ( new ByteArrayInputStream ( xmlContent . toString ( ) . getBytes ( StandardCharsets . UTF_8 ) ) )
. setRemoteReader ( repos )
. setURI ( "platform/" )
. setTargetURI ( "platform/superproject" )
. setRecordRemoteBranch ( true )
. setRecordSubmoduleLabels ( true )
. call ( ) ;
String idStr = commit . getId ( ) . name ( ) + ":" + ".gitmodules" ;
ObjectId modId = dest . resolve ( idStr ) ;
try ( ObjectReader reader = dest . newObjectReader ( ) ) {
byte [ ] bytes = reader . open ( modId ) . getCachedBytes ( Integer . MAX_VALUE ) ;
Config base = new Config ( ) ;
BlobBasedConfig cfg = new BlobBasedConfig ( base , bytes ) ;
String subUrl = cfg . getString ( "submodule" , "base" , "url" ) ;
assertEquals ( subUrl , "../base" ) ;
}
child . close ( ) ;
dest . close ( ) ;
}
@Test
public void gerritSetup ( ) throws Exception {
Repository child =
Git . cloneRepository ( ) . setURI ( groupADb . getDirectory ( ) . toURI ( ) . toString ( ) )
. setDirectory ( createUniqueTestGitDir ( true ) )
. setBare ( true ) . call ( ) . getRepository ( ) ;
Repository dest = Git . cloneRepository ( )
. setURI ( db . getDirectory ( ) . toURI ( ) . toString ( ) ) . setDirectory ( createUniqueTestGitDir ( true ) )
. setBare ( true ) . call ( ) . getRepository ( ) ;
assertTrue ( dest . isBare ( ) ) ;
assertTrue ( child . isBare ( ) ) ;
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=\"plugins/cookbook\" name=\"plugins/cookbook\" />" )
. append ( "</manifest>" ) ;
RepoCommand cmd = new RepoCommand ( dest ) ;
IndexedRepos repos = new IndexedRepos ( ) ;
repos . put ( "plugins/cookbook" , child ) ;
RevCommit commit = cmd
. setInputStream ( new ByteArrayInputStream ( xmlContent . toString ( ) . getBytes ( StandardCharsets . UTF_8 ) ) )
. setRemoteReader ( repos )
. setURI ( "" )
. setTargetURI ( "gerrit" )
. setRecordRemoteBranch ( true )
. setRecordSubmoduleLabels ( true )
. call ( ) ;
String idStr = commit . getId ( ) . name ( ) + ":" + ".gitmodules" ;
ObjectId modId = dest . resolve ( idStr ) ;
try ( ObjectReader reader = dest . newObjectReader ( ) ) {
byte [ ] bytes = reader . open ( modId ) . getCachedBytes ( Integer . MAX_VALUE ) ;
Config base = new Config ( ) ;
BlobBasedConfig cfg = new BlobBasedConfig ( base , bytes ) ;
String subUrl = cfg . getString ( "submodule" , "plugins/cookbook" , "url" ) ;
assertEquals ( subUrl , "../plugins/cookbook" ) ;
}
child . close ( ) ;
dest . close ( ) ;
}
@Test
public void absoluteRemoteURL ( ) throws Exception {
Repository child =
@ -217,6 +320,7 @@ public class RepoCommandTest extends RepositoryTestCase {
. setInputStream ( new ByteArrayInputStream ( xmlContent . toString ( ) . getBytes ( StandardCharsets . UTF_8 ) ) )
. setRemoteReader ( repos )
. setURI ( baseUrl )
. setTargetURI ( "gerrit" )
. setRecordRemoteBranch ( true )
. setRecordSubmoduleLabels ( true )
. call ( ) ;
@ -997,4 +1101,27 @@ public class RepoCommandTest extends RepositoryTestCase {
start = newStart ;
}
}
void testRelative ( String a , String b , String want ) {
String got = RepoCommand . relativize ( URI . create ( a ) , URI . create ( b ) ) . toString ( ) ;
if ( ! got . equals ( want ) ) {
fail ( String . format ( "relative('%s', '%s') = '%s', want '%s'" , a , b , got , want ) ) ;
}
}
@Test
public void relative ( ) {
testRelative ( "a/b/" , "a/" , "../" ) ;
// Normalization:
testRelative ( "a/p/..//b/" , "a/" , "../" ) ;
testRelative ( "a/b" , "a/" , "" ) ;
testRelative ( "a/" , "a/b/" , "b/" ) ;
testRelative ( "a/" , "a/b" , "b" ) ;
testRelative ( "/a/b/c" , "/b/c" , "../../b/c" ) ;
testRelative ( "/abc" , "bcd" , "bcd" ) ;
testRelative ( "abc" , "/bcd" , "/bcd" ) ;
testRelative ( "http://a" , "a/b" , "a/b" ) ;
testRelative ( "http://base.com/a/" , "http://child.com/a/b" , "http://child.com/a/b" ) ;
}
}