55from .symbolic import SymbolicReference
66from .reference import Reference
77
8- from typing import Union , TYPE_CHECKING
8+ # typinng ---------------------------------------------------
99
10- from git .types import Commit_ish
10+ from typing import Any , Sequence , Union , TYPE_CHECKING
11+
12+ from git .types import PathLike , Commit_ish
1113
1214if TYPE_CHECKING :
1315 from git .repo import Repo
16+ from git .objects import Commit
17+ from git .refs import RemoteReference
18+
19+ # -------------------------------------------------------------------
1420
1521__all__ = ["HEAD" , "Head" ]
1622
@@ -29,20 +35,21 @@ class HEAD(SymbolicReference):
2935 _ORIG_HEAD_NAME = 'ORIG_HEAD'
3036 __slots__ = ()
3137
32- def __init__ (self , repo : 'Repo' , path = _HEAD_NAME ):
38+ def __init__ (self , repo : 'Repo' , path : PathLike = _HEAD_NAME ):
3339 if path != self ._HEAD_NAME :
3440 raise ValueError ("HEAD instance must point to %r, got %r" % (self ._HEAD_NAME , path ))
3541 super (HEAD , self ).__init__ (repo , path )
36- self .commit : 'Commit_ish '
42+ self .commit : 'Commit '
3743
38- def orig_head (self ) -> ' SymbolicReference' :
44+ def orig_head (self ) -> SymbolicReference :
3945 """
4046 :return: SymbolicReference pointing at the ORIG_HEAD, which is maintained
4147 to contain the previous value of HEAD"""
4248 return SymbolicReference (self .repo , self ._ORIG_HEAD_NAME )
4349
44- def reset (self , commit : Union [Commit_ish , SymbolicReference , str ] = 'HEAD' , index = True , working_tree = False ,
45- paths = None , ** kwargs ):
50+ def reset (self , commit : Union [Commit_ish , SymbolicReference , str ] = 'HEAD' ,
51+ index : bool = True , working_tree : bool = False ,
52+ paths : Union [PathLike , Sequence [PathLike ], None ] = None , ** kwargs : Any ) -> 'HEAD' :
4653 """Reset our HEAD to the given commit optionally synchronizing
4754 the index and working tree. The reference we refer to will be set to
4855 commit as well.
@@ -122,7 +129,7 @@ class Head(Reference):
122129 k_config_remote_ref = "merge" # branch to merge from remote
123130
124131 @classmethod
125- def delete (cls , repo , * heads , ** kwargs ):
132+ def delete (cls , repo : 'Repo' , * heads : 'Head' , ** kwargs : Any ):
126133 """Delete the given heads
127134
128135 :param force:
@@ -135,7 +142,7 @@ def delete(cls, repo, *heads, **kwargs):
135142 flag = "-D"
136143 repo .git .branch (flag , * heads )
137144
138- def set_tracking_branch (self , remote_reference ) :
145+ def set_tracking_branch (self , remote_reference : 'RemoteReference' ) -> 'Head' :
139146 """
140147 Configure this branch to track the given remote reference. This will alter
141148 this branch's configuration accordingly.
@@ -160,7 +167,7 @@ def set_tracking_branch(self, remote_reference):
160167
161168 return self
162169
163- def tracking_branch (self ):
170+ def tracking_branch (self ) -> Union [ 'RemoteReference' , None ] :
164171 """
165172 :return: The remote_reference we are tracking, or None if we are
166173 not a tracking branch"""
@@ -175,7 +182,7 @@ def tracking_branch(self):
175182 # we are not a tracking branch
176183 return None
177184
178- def rename (self , new_path , force = False ):
185+ def rename (self , new_path : PathLike , force : bool = False ) -> 'Head' :
179186 """Rename self to a new path
180187
181188 :param new_path:
@@ -196,7 +203,7 @@ def rename(self, new_path, force=False):
196203 self .path = "%s/%s" % (self ._common_path_default , new_path )
197204 return self
198205
199- def checkout (self , force = False , ** kwargs ):
206+ def checkout (self , force : bool = False , ** kwargs : Any ):
200207 """Checkout this head by setting the HEAD to this reference, by updating the index
201208 to reflect the tree we point to and by updating the working tree to reflect
202209 the latest index.
@@ -231,7 +238,7 @@ def checkout(self, force=False, **kwargs):
231238 return self .repo .active_branch
232239
233240 #{ Configuration
234- def _config_parser (self , read_only ) :
241+ def _config_parser (self , read_only : bool ) -> SectionConstraint :
235242 if read_only :
236243 parser = self .repo .config_reader ()
237244 else :
@@ -240,13 +247,13 @@ def _config_parser(self, read_only):
240247
241248 return SectionConstraint (parser , 'branch "%s"' % self .name )
242249
243- def config_reader (self ):
250+ def config_reader (self ) -> SectionConstraint :
244251 """
245252 :return: A configuration parser instance constrained to only read
246253 this instance's values"""
247254 return self ._config_parser (read_only = True )
248255
249- def config_writer (self ):
256+ def config_writer (self ) -> SectionConstraint :
250257 """
251258 :return: A configuration writer instance with read-and write access
252259 to options of this head"""
0 commit comments