@@ -421,17 +421,17 @@ public void CanWalkCommitsFromBranch()
421
421
}
422
422
423
423
[ Theory ]
424
- [ InlineData ( "test " ) ]
425
- [ InlineData ( "refs/heads/ test" ) ]
426
- public void CanCheckoutAnExistingBranch ( string name )
424
+ [ InlineData ( "i-do-numbers " ) ]
425
+ [ InlineData ( "diff- test-cases " ) ]
426
+ public void CanCheckoutAnExistingBranch ( string branchName )
427
427
{
428
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( ) ;
428
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
429
429
using ( var repo = new Repository ( path . RepositoryPath ) )
430
430
{
431
431
Branch master = repo . Branches [ "master" ] ;
432
432
Assert . True ( master . IsCurrentRepositoryHead ) ;
433
433
434
- Branch branch = repo . Branches [ name ] ;
434
+ Branch branch = repo . Branches [ branchName ] ;
435
435
Assert . NotNull ( branch ) ;
436
436
437
437
Branch test = repo . Checkout ( branch ) ;
@@ -446,17 +446,17 @@ public void CanCheckoutAnExistingBranch(string name)
446
446
}
447
447
448
448
[ Theory ]
449
- [ InlineData ( "test " ) ]
450
- [ InlineData ( "refs/heads/ test" ) ]
451
- public void CanCheckoutAnExistingBranchByName ( string name )
449
+ [ InlineData ( "i-do-numbers " ) ]
450
+ [ InlineData ( "diff- test-cases " ) ]
451
+ public void CanCheckoutAnExistingBranchByName ( string branchName )
452
452
{
453
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( ) ;
453
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
454
454
using ( var repo = new Repository ( path . RepositoryPath ) )
455
455
{
456
456
Branch master = repo . Branches [ "master" ] ;
457
457
Assert . True ( master . IsCurrentRepositoryHead ) ;
458
458
459
- Branch test = repo . Checkout ( name ) ;
459
+ Branch test = repo . Checkout ( branchName ) ;
460
460
Assert . False ( repo . Info . IsHeadDetached ) ;
461
461
462
462
Assert . False ( test . IsRemote ) ;
@@ -472,33 +472,43 @@ public void CanCheckoutAnExistingBranchByName(string name)
472
472
[ InlineData ( "refs/tags/lw" ) ]
473
473
public void CanCheckoutAnArbitraryCommit ( string commitPointer )
474
474
{
475
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( ) ;
475
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
476
476
using ( var repo = new Repository ( path . RepositoryPath ) )
477
477
{
478
478
Branch master = repo . Branches [ "master" ] ;
479
479
Assert . True ( master . IsCurrentRepositoryHead ) ;
480
480
481
481
Branch detachedHead = repo . Checkout ( commitPointer ) ;
482
482
483
+ Assert . Equal ( repo . Head , detachedHead ) ;
484
+ Assert . Equal ( repo . Lookup ( commitPointer ) . Sha , detachedHead . Tip . Sha ) ;
485
+ Assert . True ( repo . Head . IsCurrentRepositoryHead ) ;
483
486
Assert . True ( repo . Info . IsHeadDetached ) ;
484
487
488
+ Assert . True ( detachedHead . IsCurrentRepositoryHead ) ;
485
489
Assert . False ( detachedHead . IsRemote ) ;
486
490
Assert . Equal ( detachedHead . Name , detachedHead . CanonicalName ) ;
487
- Assert . Equal ( "(no branch)" , detachedHead . CanonicalName ) ;
488
- Assert . Equal ( repo . Lookup ( commitPointer ) . Sha , detachedHead . Tip . Sha ) ;
489
491
490
- Assert . Equal ( repo . Head , detachedHead ) ;
492
+ Assert . Equal ( "(no branch)" , detachedHead . CanonicalName ) ;
491
493
492
494
Assert . False ( master . IsCurrentRepositoryHead ) ;
493
- Assert . True ( detachedHead . IsCurrentRepositoryHead ) ;
494
- Assert . True ( repo . Head . IsCurrentRepositoryHead ) ;
495
495
}
496
496
}
497
497
498
498
[ Fact ]
499
- public void CheckingOutANonExistingBranchThrows ( )
499
+ public void CheckingOutInABareRepoThrows ( )
500
500
{
501
501
using ( var repo = new Repository ( BareTestRepoPath ) )
502
+ {
503
+ Assert . Throws < InvalidOperationException > ( ( ) => repo . Checkout ( repo . Branches [ "refs/heads/test" ] ) ) ;
504
+ Assert . Throws < InvalidOperationException > ( ( ) => repo . Checkout ( "refs/heads/test" ) ) ;
505
+ }
506
+ }
507
+
508
+ [ Fact ]
509
+ public void CheckingOutANonExistingBranchThrows ( )
510
+ {
511
+ using ( var repo = new Repository ( StandardTestRepoWorkingDirPath ) )
502
512
{
503
513
Assert . Throws < LibGit2SharpException > ( ( ) => repo . Checkout ( "i-do-not-exist" ) ) ;
504
514
}
@@ -507,7 +517,7 @@ public void CheckingOutANonExistingBranchThrows()
507
517
[ Fact ]
508
518
public void CheckingOutABranchWithBadParamsThrows ( )
509
519
{
510
- using ( var repo = new Repository ( BareTestRepoPath ) )
520
+ using ( var repo = new Repository ( StandardTestRepoWorkingDirPath ) )
511
521
{
512
522
Assert . Throws < ArgumentException > ( ( ) => repo . Checkout ( string . Empty ) ) ;
513
523
Assert . Throws < ArgumentNullException > ( ( ) => repo . Checkout ( default ( Branch ) ) ) ;
0 commit comments