Skip to content

Commit e2d5e0e

Browse files
authored
Update head.py
1 parent b833eeb commit e2d5e0e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

git/refs/head.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from git.config import SectionConstraint
1+
from git.config import GitConfigParser, SectionConstraint
22
from git.util import join_path
33
from git.exc import GitCommandError
44

@@ -142,7 +142,7 @@ def delete(cls, repo: 'Repo', *heads: 'Head', **kwargs: Any):
142142
flag = "-D"
143143
repo.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':
203203
self.path = "%s/%s" % (self._common_path_default, new_path)
204204
return 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):
235235
self.repo.git.checkout(self, **kwargs)
236236
if self.repo.head.is_detached:
237237
return 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]:
242243
if read_only:
243244
parser = self.repo.config_reader()
244245
else:
@@ -247,13 +248,13 @@ def _config_parser(self, read_only: bool) -> SectionConstraint:
247248

248249
return 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"""
254255
return 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"""

0 commit comments

Comments
 (0)