1- from git .config import SectionConstraint
1+ from git .config import GitConfigParser , SectionConstraint
22from git .util import join_path
33from git .exc import GitCommandError
44
@@ -142,7 +142,7 @@ def delete(cls, repo: 'Repo', *heads: 'Head', **kwargs: Any):
142142flag = "-D"
143143repo .git .branch (flag ,* heads )
144144
145- def set_tracking_branch (self ,remote_reference :'RemoteReference' )-> 'Head' :
145+ def set_tracking_branch (self ,remote_reference :Union [ 'RemoteReference' , None ] )-> 'Head' :
146146"""
147147 Configure this branch to track the given remote reference. This will alter
148148 this branch's configuration accordingly.
@@ -203,7 +203,7 @@ def rename(self, new_path: PathLike, force: bool = False) -> 'Head':
203203self .path = "%s/%s" % (self ._common_path_default ,new_path )
204204return self
205205
206- def checkout (self ,force :bool = False ,** kwargs :Any ):
206+ def checkout (self ,force :bool = False ,** kwargs :Any )-> Union [ 'HEAD' , 'Head' ] :
207207"""Checkout this head by setting the HEAD to this reference, by updating the index
208208 to reflect the tree we point to and by updating the working tree to reflect
209209 the latest index.
@@ -235,10 +235,11 @@ def checkout(self, force: bool = False, **kwargs: Any):
235235self .repo .git .checkout (self ,** kwargs )
236236if self .repo .head .is_detached :
237237return self .repo .head
238- return self .repo .active_branch
238+ else :
239+ return self .repo .active_branch
239240
240241#{ Configuration
241- def _config_parser (self ,read_only :bool )-> SectionConstraint :
242+ def _config_parser (self ,read_only :bool )-> SectionConstraint [ GitConfigParser ] :
242243if read_only :
243244parser = self .repo .config_reader ()
244245else :
@@ -247,13 +248,13 @@ def _config_parser(self, read_only: bool) -> SectionConstraint:
247248
248249return SectionConstraint (parser ,'branch "%s"' % self .name )
249250
250- def config_reader (self )-> SectionConstraint :
251+ def config_reader (self )-> SectionConstraint [ GitConfigParser ] :
251252"""
252253 :return: A configuration parser instance constrained to only read
253254 this instance's values"""
254255return self ._config_parser (read_only = True )
255256
256- def config_writer (self )-> SectionConstraint :
257+ def config_writer (self )-> SectionConstraint [ GitConfigParser ] :
257258"""
258259 :return: A configuration writer instance with read-and write access
259260 to options of this head"""