1111from git .db .complex import CmdCompatibilityGitDB
1212from git .db .cmd .base import *
1313
14+ from git .refs import TagReference , Reference , RemoteReference
15+
1416class TestBase (RepoBase ):
1517 RepoCls = CmdCompatibilityGitDB
1618
@@ -28,5 +30,62 @@ def test_basics(self):
2830 self .failUnlessRaises (BadObject , gdb .partial_to_complete_sha_hex , invalid_rev )
2931
3032 def test_fetch_info (self ):
31- self .failUnlessRaises (ValueError , CmdFetchInfo ._from_line , self .rorepo , "nonsense" , '' )
32- self .failUnlessRaises (ValueError , CmdFetchInfo ._from_line , self .rorepo , "? [up to date] 0.1.7RC -> origin/0.1.7RC" , '' )
33+ self .failUnlessRaises (ValueError , CmdCmdFetchInfo ._from_line , self .rorepo , "nonsense" , '' )
34+ self .failUnlessRaises (ValueError , CmdCmdFetchInfo ._from_line , self .rorepo , "? [up to date] 0.1.7RC -> origin/0.1.7RC" , '' )
35+
36+
37+ def test_fetch_info (self ):
38+ # assure we can handle remote-tracking branches
39+ fetch_info_line_fmt = "c437ee5deb8d00cf02f03720693e4c802e99f390 not-for-merge %s '0.3' of git://github.com/gitpython-developers/GitPython"
40+ remote_info_line_fmt = "* [new branch] nomatter -> %s"
41+ fi = CmdFetchInfo ._from_line (self .rorepo ,
42+ remote_info_line_fmt % "local/master" ,
43+ fetch_info_line_fmt % 'remote-tracking branch' )
44+
45+ # we wouldn't be here if it wouldn't have worked
46+
47+ # handles non-default refspecs: One can specify a different path in refs/remotes
48+ # or a special path just in refs/something for instance
49+
50+ fi = CmdFetchInfo ._from_line (self .rorepo ,
51+ remote_info_line_fmt % "subdir/tagname" ,
52+ fetch_info_line_fmt % 'tag' )
53+
54+ assert isinstance (fi .ref , TagReference )
55+ assert fi .ref .path .startswith ('refs/tags' )
56+
57+ # it could be in a remote direcftory though
58+ fi = CmdFetchInfo ._from_line (self .rorepo ,
59+ remote_info_line_fmt % "remotename/tags/tagname" ,
60+ fetch_info_line_fmt % 'tag' )
61+
62+ assert isinstance (fi .ref , TagReference )
63+ assert fi .ref .path .startswith ('refs/remotes/' )
64+
65+ # it can also be anywhere !
66+ tag_path = "refs/something/remotename/tags/tagname"
67+ fi = CmdFetchInfo ._from_line (self .rorepo ,
68+ remote_info_line_fmt % tag_path ,
69+ fetch_info_line_fmt % 'tag' )
70+
71+ assert isinstance (fi .ref , TagReference )
72+ assert fi .ref .path == tag_path
73+
74+ # branches default to refs/remotes
75+ fi = CmdFetchInfo ._from_line (self .rorepo ,
76+ remote_info_line_fmt % "remotename/branch" ,
77+ fetch_info_line_fmt % 'branch' )
78+
79+ assert isinstance (fi .ref , RemoteReference )
80+ assert fi .ref .remote_name == 'remotename'
81+
82+ # but you can force it anywhere, in which case we only have a references
83+ fi = CmdFetchInfo ._from_line (self .rorepo ,
84+ remote_info_line_fmt % "refs/something/branch" ,
85+ fetch_info_line_fmt % 'branch' )
86+
87+ assert type (fi .ref ) is Reference
88+ assert fi .ref .path == "refs/something/branch"
89+
90+
91+
0 commit comments