3636
3737# typing-------------------------------------------------------
3838
39- from typing import Any , Callable , Optional , TYPE_CHECKING , Union , overload
39+ from typing import Any , Callable , Dict , Optional , TYPE_CHECKING , Union , cast , overload
4040
4141from git .types import PathLike , Literal
4242
4343if TYPE_CHECKING :
4444 from git .repo .base import Repo
4545 from git .objects .commit import Commit
46+ from git .objects .blob import Blob
47+ from git .objects .tree import Tree
48+ from git .objects .tag import TagObject
4649
50+ flagKeyLiteral = Literal [' ' , '!' , '+' , '-' , '*' , '=' , 't' ]
4751# -------------------------------------------------------------
4852
4953log = logging .getLogger ('git.remote' )
@@ -131,7 +135,7 @@ class PushInfo(object):
131135 '=' : UP_TO_DATE ,
132136 '!' : ERROR }
133137
134- def __init__ (self , flags : int , local_ref : Union [SymbolicReference , None ], remote_ref_string : str , remote ,
138+ def __init__ (self , flags : int , local_ref : Union [SymbolicReference , None ], remote_ref_string : str , remote : 'Remote' ,
135139 old_commit : Optional [str ] = None , summary : str = '' ) -> None :
136140 """ Initialize a new instance
137141 local_ref: HEAD | Head | RemoteReference | TagReference | Reference | SymbolicReference | None """
@@ -143,7 +147,7 @@ def __init__(self, flags: int, local_ref: Union[SymbolicReference, None], remote
143147 self .summary = summary
144148
145149 @property
146- def old_commit (self ) -> Optional [ bool ]:
150+ def old_commit (self ) -> Union [ str , SymbolicReference , 'Commit' , 'TagObject' , 'Blob' , 'Tree' , None ]:
147151 return self ._old_commit_sha and self ._remote .repo .commit (self ._old_commit_sha ) or None
148152
149153 @property
@@ -246,7 +250,7 @@ class FetchInfo(object):
246250 '=' : HEAD_UPTODATE ,
247251 ' ' : FAST_FORWARD ,
248252 '-' : TAG_UPDATE ,
249- }
253+ } # type: Dict[flagKeyLiteral, int]
250254
251255 @classmethod
252256 def refresh (cls ) -> Literal [True ]:
@@ -297,7 +301,7 @@ def commit(self) -> 'Commit':
297301 return self .ref .commit
298302
299303 @classmethod
300- def _from_line (cls , repo , line , fetch_line ):
304+ def _from_line (cls , repo : Repo , line : str , fetch_line ) -> 'FetchInfo' :
301305 """Parse information from the given line as returned by git-fetch -v
302306 and return a new FetchInfo object representing this information.
303307
@@ -319,7 +323,9 @@ def _from_line(cls, repo, line, fetch_line):
319323 raise ValueError ("Failed to parse line: %r" % line )
320324
321325 # parse lines
322- control_character , operation , local_remote_ref , remote_local_ref , note = match .groups ()
326+ control_character , operation , local_remote_ref , remote_local_ref_str , note = match .groups ()
327+ control_character = cast (flagKeyLiteral , control_character ) # can do this neater once 3.5 dropped
328+
323329 try :
324330 _new_hex_sha , _fetch_operation , fetch_note = fetch_line .split ("\t " )
325331 ref_type_name , fetch_note = fetch_note .split (' ' , 1 )
@@ -359,7 +365,7 @@ def _from_line(cls, repo, line, fetch_line):
359365 # the fetch result is stored in FETCH_HEAD which destroys the rule we usually
360366 # have. In that case we use a symbolic reference which is detached
361367 ref_type = None
362- if remote_local_ref == "FETCH_HEAD" :
368+ if remote_local_ref_str == "FETCH_HEAD" :
363369 ref_type = SymbolicReference
364370 elif ref_type_name == "tag" or is_tag_operation :
365371 # the ref_type_name can be branch, whereas we are still seeing a tag operation. It happens during
@@ -387,21 +393,21 @@ def _from_line(cls, repo, line, fetch_line):
387393 # by the 'ref/' prefix. Otherwise even a tag could be in refs/remotes, which is when it will have the
388394 # 'tags/' subdirectory in its path.
389395 # We don't want to test for actual existence, but try to figure everything out analytically.
390- ref_path = None
391- remote_local_ref = remote_local_ref .strip ()
392- if remote_local_ref .startswith (Reference ._common_path_default + "/" ):
396+ ref_path = None # type: Optional[PathLike]
397+ remote_local_ref_str = remote_local_ref_str .strip ()
398+ if remote_local_ref_str .startswith (Reference ._common_path_default + "/" ):
393399 # always use actual type if we get absolute paths
394400 # Will always be the case if something is fetched outside of refs/remotes (if its not a tag)
395- ref_path = remote_local_ref
401+ ref_path = remote_local_ref_str
396402 if ref_type is not TagReference and not \
397- remote_local_ref .startswith (RemoteReference ._common_path_default + "/" ):
403+ remote_local_ref_str .startswith (RemoteReference ._common_path_default + "/" ):
398404 ref_type = Reference
399405 # END downgrade remote reference
400- elif ref_type is TagReference and 'tags/' in remote_local_ref :
406+ elif ref_type is TagReference and 'tags/' in remote_local_ref_str :
401407 # even though its a tag, it is located in refs/remotes
402- ref_path = join_path (RemoteReference ._common_path_default , remote_local_ref )
408+ ref_path = join_path (RemoteReference ._common_path_default , remote_local_ref_str )
403409 else :
404- ref_path = join_path (ref_type ._common_path_default , remote_local_ref )
410+ ref_path = join_path (ref_type ._common_path_default , remote_local_ref_str )
405411 # END obtain refpath
406412
407413 # even though the path could be within the git conventions, we make
0 commit comments