@ -103,38 +103,25 @@ public class CheckoutCommandTest extends RepositoryTestCase {
}
}
@Test
@Test
public void testSimpleCheckout ( ) {
public void testSimpleCheckout ( ) throws Exception {
try {
git . checkout ( ) . setName ( "test" ) . call ( ) ;
git . checkout ( ) . setName ( "test" ) . call ( ) ;
} catch ( Exception e ) {
fail ( e . getMessage ( ) ) ;
}
}
}
@Test
@Test
public void testCheckout ( ) {
public void testCheckout ( ) throws Exception {
try {
git . checkout ( ) . setName ( "test" ) . call ( ) ;
git . checkout ( ) . setName ( "test" ) . call ( ) ;
assertEquals ( "[Test.txt, mode:100644, content:Some change]" ,
assertEquals ( "[Test.txt, mode:100644, content:Some change]" ,
indexState ( CONTENT ) ) ;
indexState ( CONTENT ) ) ;
Ref result = git . checkout ( ) . setName ( "master" ) . call ( ) ;
Ref result = git . checkout ( ) . setName ( "master" ) . call ( ) ;
assertEquals ( "[Test.txt, mode:100644, content:Hello world]" ,
assertEquals ( "[Test.txt, mode:100644, content:Hello world]" ,
indexState ( CONTENT ) ) ;
indexState ( CONTENT ) ) ;
assertEquals ( "refs/heads/master" , result . getName ( ) ) ;
assertEquals ( "refs/heads/master" , result . getName ( ) ) ;
assertEquals ( "refs/heads/master" , git . getRepository ( ) . getFullBranch ( ) ) ;
assertEquals ( "refs/heads/master" , git . getRepository ( )
. getFullBranch ( ) ) ;
} catch ( Exception e ) {
fail ( e . getMessage ( ) ) ;
}
}
}
@Test
@Test
public void testCreateBranchOnCheckout ( ) throws IOException {
public void testCreateBranchOnCheckout ( ) throws Exception {
try {
git . checkout ( ) . setCreateBranch ( true ) . setName ( "test2" ) . call ( ) ;
git . checkout ( ) . setCreateBranch ( true ) . setName ( "test2" ) . call ( ) ;
} catch ( Exception e ) {
fail ( e . getMessage ( ) ) ;
}
assertNotNull ( db . getRef ( "test2" ) ) ;
assertNotNull ( db . getRef ( "test2" ) ) ;
}
}
@ -200,45 +187,36 @@ public class CheckoutCommandTest extends RepositoryTestCase {
}
}
@Test
@Test
public void testCheckoutCommit ( ) {
public void testCheckoutCommit ( ) throws Exception {
try {
Ref result = git . checkout ( ) . setName ( initialCommit . name ( ) ) . call ( ) ;
Ref result = git . checkout ( ) . setName ( initialCommit . name ( ) ) . call ( ) ;
assertEquals ( "[Test.txt, mode:100644, content:Hello world]" ,
assertEquals ( "[Test.txt, mode:100644, content:Hello world]" ,
indexState ( CONTENT ) ) ;
indexState ( CONTENT ) ) ;
assertNull ( result ) ;
assertNull ( result ) ;
assertEquals ( initialCommit . name ( ) , git . getRepository ( ) . getFullBranch ( ) ) ;
assertEquals ( initialCommit . name ( ) , git . getRepository ( )
. getFullBranch ( ) ) ;
} catch ( Exception e ) {
fail ( e . getMessage ( ) ) ;
}
}
}
@Test
@Test
public void testCheckoutRemoteTrackingWithoutLocalBranch ( ) {
public void testCheckoutRemoteTrackingWithoutLocalBranch ( ) throws Exception {
try {
// create second repository
// create second repository
Repository db2 = createWorkRepository ( ) ;
Repository db2 = createWorkRepository ( ) ;
Git git2 = new Git ( db2 ) ;
Git git2 = new Git ( db2 ) ;
// setup the second repository to fetch from the first repository
// setup the second repository to fetch from the first repository
final StoredConfig config = db2 . getConfig ( ) ;
final StoredConfig config = db2 . getConfig ( ) ;
RemoteConfig remoteConfig = new RemoteConfig ( config , "origin" ) ;
RemoteConfig remoteConfig = new RemoteConfig ( config , "origin" ) ;
URIish uri = new URIish ( db . getDirectory ( ) . toURI ( ) . toURL ( ) ) ;
URIish uri = new URIish ( db . getDirectory ( ) . toURI ( ) . toURL ( ) ) ;
remoteConfig . addURI ( uri ) ;
remoteConfig . addURI ( uri ) ;
remoteConfig . update ( config ) ;
remoteConfig . update ( config ) ;
config . save ( ) ;
config . save ( ) ;
// fetch from first repository
// fetch from first repository
RefSpec spec = new RefSpec ( "+refs/heads/*:refs/remotes/origin/*" ) ;
RefSpec spec = new RefSpec ( "+refs/heads/*:refs/remotes/origin/*" ) ;
git2 . fetch ( ) . setRemote ( "origin" ) . setRefSpecs ( spec ) . call ( ) ;
git2 . fetch ( ) . setRemote ( "origin" ) . setRefSpecs ( spec ) . call ( ) ;
// checkout remote tracking branch in second repository
// checkout remote tracking branch in second repository
// (no local branches exist yet in second repository)
// (no local branches exist yet in second repository)
git2 . checkout ( ) . setName ( "remotes/origin/test" ) . call ( ) ;
git2 . checkout ( ) . setName ( "remotes/origin/test" ) . call ( ) ;
assertEquals ( "[Test.txt, mode:100644, content:Some change]" ,
assertEquals ( "[Test.txt, mode:100644, content:Some change]" ,
indexState ( db2 , CONTENT ) ) ;
indexState ( db2 , CONTENT ) ) ;
} catch ( Exception e ) {
fail ( e . getMessage ( ) ) ;
}
}
}
@Test
@Test