25
25
26
26
if TYPE_CHECKING :
27
27
from git .repo import Repo
28
- from git .refs import Reference ,Head ,TagReference ,RemoteReference
29
- from git .config import GitConfigParser
30
- from git .objects .commit import Actor
28
+ from git .refs import Reference ,Head ,TagReference ,RemoteReference # NOQA
29
+ from git .config import GitConfigParser # NOQA
30
+ from git .objects .commit import Actor # NOQA
31
31
32
32
T_References = TypeVar ('T_References' ,bound = 'SymbolicReference' )
33
33
37
37
__all__ = ["SymbolicReference" ]
38
38
39
39
40
- def _git_dir (repo ,path ) :
40
+ def _git_dir (repo : 'Repo' ,path : PathLike ) -> PathLike :
41
41
""" Find the git dir that's appropriate for the path"""
42
- name = "%s" % ( path ,)
42
+ name = f" { path } "
43
43
if name in ['HEAD' ,'ORIG_HEAD' ,'FETCH_HEAD' ,'index' ,'logs' ]:
44
44
return repo .git_dir
45
45
return repo .common_dir
@@ -59,34 +59,35 @@ class SymbolicReference(object):
59
59
_remote_common_path_default = "refs/remotes"
60
60
_id_attribute_ = "name"
61
61
62
- def __init__ (self ,repo :'Repo' ,path :PathLike ,check_path :bool = False ):
62
+ def __init__ (self ,repo :'Repo' ,path :PathLike ,check_path :bool = False )-> None :
63
63
self .repo = repo
64
64
self .path = str (path )
65
+ self .ref = self ._get_reference ()
65
66
66
67
def __str__ (self )-> str :
67
68
return self .path
68
69
69
- def __repr__ (self ):
70
+ def __repr__ (self )-> str :
70
71
return '<git.%s "%s">' % (self .__class__ .__name__ ,self .path )
71
72
72
- def __eq__ (self ,other ):
73
+ def __eq__ (self ,other )-> bool :
73
74
if hasattr (other ,'path' ):
74
75
return self .path == other .path
75
76
return False
76
77
77
- def __ne__ (self ,other ):
78
+ def __ne__ (self ,other )-> bool :
78
79
return not (self == other )
79
80
80
81
def __hash__ (self ):
81
82
return hash (self .path )
82
83
83
84
@property
84
- def name (self ):
85
+ def name (self )-> str :
85
86
"""
86
87
:return:
87
88
In case of symbolic references, the shortest assumable name
88
89
is the path itself."""
89
- return self .path
90
+ return str ( self .path )
90
91
91
92
@property
92
93
def abspath (self ):