@@ -220,6 +220,37 @@ public void CanListAllBranchesIncludingRemoteRefs()
220
220
}
221
221
}
222
222
223
+ [ Fact ]
224
+ public void CanResolveRemote ( )
225
+ {
226
+ using ( var repo = new Repository ( StandardTestRepoPath ) )
227
+ {
228
+ Branch master = repo . Branches [ "master" ] ;
229
+ Assert . Equal ( repo . Remotes [ "origin" ] , master . Remote ) ;
230
+ }
231
+ }
232
+
233
+ [ Fact ]
234
+ public void RemoteForNonTrackingBranchIsNull ( )
235
+ {
236
+ using ( var repo = new Repository ( StandardTestRepoPath ) )
237
+ {
238
+ Branch test = repo . Branches [ "i-do-numbers" ] ;
239
+ Assert . Null ( test . Remote ) ;
240
+ }
241
+ }
242
+
243
+ [ Fact ]
244
+ public void QueryRemoteForLocalTrackingBranch ( )
245
+ {
246
+ // There is not a Remote to resolve for a local tracking branch.
247
+ using ( var repo = new Repository ( StandardTestRepoPath ) )
248
+ {
249
+ Branch trackLocal = repo . Branches [ "track-local" ] ;
250
+ Assert . Null ( trackLocal . Remote ) ;
251
+ }
252
+ }
253
+
223
254
[ Fact ]
224
255
public void CanLookupABranchByItsCanonicalName ( )
225
256
{
@@ -280,6 +311,44 @@ public void LookingOutABranchByNameWithBadParamsThrows()
280
311
}
281
312
}
282
313
314
+ public void CanGetInformationFromUnbornBranch ( )
315
+ {
316
+ SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
317
+ using ( var repo = Repository . Init ( scd . DirectoryPath , true ) )
318
+ {
319
+ var head = repo . Head ;
320
+
321
+ Assert . Equal ( "refs/heads/master" , head . CanonicalName ) ;
322
+ Assert . Equal ( 0 , head . Commits . Count ( ) ) ;
323
+ Assert . True ( head . IsCurrentRepositoryHead ) ;
324
+ Assert . False ( head . IsRemote ) ;
325
+ Assert . Equal ( "master" , head . Name ) ;
326
+ Assert . Null ( head . Tip ) ;
327
+ Assert . Null ( head [ "huh?" ] ) ;
328
+
329
+ Assert . Null ( head . AheadBy ) ;
330
+ Assert . Null ( head . BehindBy ) ;
331
+ Assert . False ( head . IsTracking ) ;
332
+ Assert . Null ( head . TrackedBranch ) ;
333
+ }
334
+ }
335
+
336
+ [ Fact ]
337
+ public void CanGetTrackingInformationFromBranchSharingNoHistoryWithItsTrackedBranch ( )
338
+ {
339
+ TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
340
+ using ( var repo = new Repository ( path . RepositoryPath ) )
341
+ {
342
+ Branch master = repo . Branches [ "master" ] ;
343
+ repo . Refs . UpdateTarget ( "refs/remotes/origin/master" , "origin/test" ) ;
344
+
345
+ Assert . True ( master . IsTracking ) ;
346
+ Assert . Null ( master . AheadBy ) ;
347
+ Assert . Null ( master . BehindBy ) ;
348
+ Assert . NotNull ( master . TrackedBranch ) ;
349
+ }
350
+ }
351
+
283
352
[ Fact ]
284
353
public void TrackingInformationIsEmptyForNonTrackingBranch ( )
285
354
{
@@ -288,8 +357,8 @@ public void TrackingInformationIsEmptyForNonTrackingBranch()
288
357
Branch branch = repo . Branches [ "test" ] ;
289
358
Assert . False ( branch . IsTracking ) ;
290
359
Assert . Null ( branch . TrackedBranch ) ;
291
- Assert . Equal ( 0 , branch . AheadBy ) ;
292
- Assert . Equal ( 0 , branch . BehindBy ) ;
360
+ Assert . Null ( branch . AheadBy ) ;
361
+ Assert . Null ( branch . BehindBy ) ;
293
362
}
294
363
}
295
364
@@ -351,101 +420,6 @@ public void CanWalkCommitsFromBranch()
351
420
}
352
421
}
353
422
354
- [ Theory ]
355
- [ InlineData ( "test" ) ]
356
- [ InlineData ( "refs/heads/test" ) ]
357
- public void CanCheckoutAnExistingBranch ( string name )
358
- {
359
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( ) ;
360
- using ( var repo = new Repository ( path . RepositoryPath ) )
361
- {
362
- Branch master = repo . Branches [ "master" ] ;
363
- Assert . True ( master . IsCurrentRepositoryHead ) ;
364
-
365
- Branch branch = repo . Branches [ name ] ;
366
- Assert . NotNull ( branch ) ;
367
-
368
- Branch test = repo . Checkout ( branch ) ;
369
- Assert . False ( repo . Info . IsHeadDetached ) ;
370
-
371
- Assert . False ( test . IsRemote ) ;
372
- Assert . True ( test . IsCurrentRepositoryHead ) ;
373
- Assert . Equal ( repo . Head , test ) ;
374
-
375
- Assert . False ( master . IsCurrentRepositoryHead ) ;
376
- }
377
- }
378
-
379
- [ Theory ]
380
- [ InlineData ( "test" ) ]
381
- [ InlineData ( "refs/heads/test" ) ]
382
- public void CanCheckoutAnExistingBranchByName ( string name )
383
- {
384
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( ) ;
385
- using ( var repo = new Repository ( path . RepositoryPath ) )
386
- {
387
- Branch master = repo . Branches [ "master" ] ;
388
- Assert . True ( master . IsCurrentRepositoryHead ) ;
389
-
390
- Branch test = repo . Checkout ( name ) ;
391
- Assert . False ( repo . Info . IsHeadDetached ) ;
392
-
393
- Assert . False ( test . IsRemote ) ;
394
- Assert . True ( test . IsCurrentRepositoryHead ) ;
395
- Assert . Equal ( repo . Head , test ) ;
396
-
397
- Assert . False ( master . IsCurrentRepositoryHead ) ;
398
- }
399
- }
400
-
401
- [ Theory ]
402
- [ InlineData ( "6dcf9bf" ) ]
403
- [ InlineData ( "refs/tags/lw" ) ]
404
- public void CanCheckoutAnArbitraryCommit ( string commitPointer )
405
- {
406
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( ) ;
407
- using ( var repo = new Repository ( path . RepositoryPath ) )
408
- {
409
- Branch master = repo . Branches [ "master" ] ;
410
- Assert . True ( master . IsCurrentRepositoryHead ) ;
411
-
412
- Branch detachedHead = repo . Checkout ( commitPointer ) ;
413
-
414
- Assert . True ( repo . Info . IsHeadDetached ) ;
415
-
416
- Assert . False ( detachedHead . IsRemote ) ;
417
- Assert . Equal ( detachedHead . Name , detachedHead . CanonicalName ) ;
418
- Assert . Equal ( "(no branch)" , detachedHead . CanonicalName ) ;
419
- Assert . Equal ( repo . Lookup ( commitPointer ) . Sha , detachedHead . Tip . Sha ) ;
420
-
421
- Assert . Equal ( repo . Head , detachedHead ) ;
422
-
423
- Assert . False ( master . IsCurrentRepositoryHead ) ;
424
- Assert . True ( detachedHead . IsCurrentRepositoryHead ) ;
425
- Assert . True ( repo . Head . IsCurrentRepositoryHead ) ;
426
- }
427
- }
428
-
429
- [ Fact ]
430
- public void CheckingOutANonExistingBranchThrows ( )
431
- {
432
- using ( var repo = new Repository ( BareTestRepoPath ) )
433
- {
434
- Assert . Throws < LibGit2SharpException > ( ( ) => repo . Checkout ( "i-do-not-exist" ) ) ;
435
- }
436
- }
437
-
438
- [ Fact ]
439
- public void CheckingOutABranchWithBadParamsThrows ( )
440
- {
441
- using ( var repo = new Repository ( BareTestRepoPath ) )
442
- {
443
- Assert . Throws < ArgumentException > ( ( ) => repo . Checkout ( string . Empty ) ) ;
444
- Assert . Throws < ArgumentNullException > ( ( ) => repo . Checkout ( default ( Branch ) ) ) ;
445
- Assert . Throws < ArgumentNullException > ( ( ) => repo . Checkout ( default ( string ) ) ) ;
446
- }
447
- }
448
-
449
423
private void AssertRemoval ( string branchName , bool isRemote , bool shouldPreviouslyAssertExistence )
450
424
{
451
425
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoPath ) ;
0 commit comments