@@ -443,11 +443,55 @@ def test_creation_and_removal(self, bare_rw_repo):
443
443
444
444
def test_fetch_info (self ):
445
445
# assure we can handle remote-tracking branches
446
- fi = FetchInfo ._from_line (self .rorepo ,
447
- "* [new branch] master -> local/master" ,
448
- "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge remote-tracking branch '0.3' of git://github.com/gitpython-developers/GitPython" )
446
+ fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of git://github.com/gitpython-developers/GitPython"
447
+ remote_info_line_fmt = "* [new branch] nomatter -> %s"
448
+ fi = FetchInfo ._from_line (self .rorepo ,
449
+ remote_info_line_fmt % "local/master" ,
450
+ fetch_info_line_fmt % 'remote-tracking branch' )
449
451
assert fi .ref .is_valid ()
450
452
assert fi .ref .commit
451
453
454
+ # handles non-default refspecs: One can specify a different path in refs/remotes
455
+ # or a special path just in refs/something for instance
452
456
453
-
457
+ fi = FetchInfo ._from_line (self .rorepo ,
458
+ remote_info_line_fmt % "subdir/tagname" ,
459
+ fetch_info_line_fmt % 'tag' )
460
+
461
+ assert isinstance (fi .ref , TagReference )
462
+ assert fi .ref .path .startswith ('refs/tags' )
463
+
464
+ # it could be in a remote direcftory though
465
+ fi = FetchInfo ._from_line (self .rorepo ,
466
+ remote_info_line_fmt % "remotename/tags/tagname" ,
467
+ fetch_info_line_fmt % 'tag' )
468
+
469
+ assert isinstance (fi .ref , TagReference )
470
+ assert fi .ref .path .startswith ('refs/remotes/' )
471
+
472
+ # it can also be anywhere !
473
+ tag_path = "refs/something/remotename/tags/tagname"
474
+ fi = FetchInfo ._from_line (self .rorepo ,
475
+ remote_info_line_fmt % tag_path ,
476
+ fetch_info_line_fmt % 'tag' )
477
+
478
+ assert isinstance (fi .ref , TagReference )
479
+ assert fi .ref .path == tag_path
480
+
481
+ # branches default to refs/remotes
482
+ fi = FetchInfo ._from_line (self .rorepo ,
483
+ remote_info_line_fmt % "remotename/branch" ,
484
+ fetch_info_line_fmt % 'branch' )
485
+
486
+ assert isinstance (fi .ref , RemoteReference )
487
+ assert fi .ref .remote_name == 'remotename'
488
+
489
+ # but you can force it anywhere, in which case we only have a references
490
+ fi = FetchInfo ._from_line (self .rorepo ,
491
+ remote_info_line_fmt % "refs/something/branch" ,
492
+ fetch_info_line_fmt % 'branch' )
493
+
494
+ assert type (fi .ref ) is Reference
495
+ assert fi .ref .path == "refs/something/branch"
496
+
497
+
0 commit comments