Skip to content

Commit 24c1242

Browse files
committedJul 31, 2021
Add type to symbolicreference()
1 parent 7e972b9 commit 24c1242

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed
 

‎git/refs/symbolic.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
__all__ = ["SymbolicReference"]
3737

3838

39-
def _git_dir(repo: 'Repo', path: PathLike) -> PathLike:
39+
def _git_dir(repo: 'Repo', path: Union[PathLike, None]) -> PathLike:
4040
""" Find the git dir that's appropriate for the path"""
4141
name = f"{path}"
4242
if name in ['HEAD', 'ORIG_HEAD', 'FETCH_HEAD', 'index', 'logs']:
@@ -136,26 +136,27 @@ def _iter_packed_refs(cls, repo: 'Repo') -> Iterator[Tuple[str, str]]:
136136
# alright.
137137

138138
@classmethod
139-
def dereference_recursive(cls, repo: 'Repo', ref_path: PathLike) -> str:
139+
def dereference_recursive(cls, repo: 'Repo', ref_path: Union[None, PathLike]) -> str:
140140
"""
141141
:return: hexsha stored in the reference at the given ref_path, recursively dereferencing all
142142
intermediate references as required
143143
:param repo: the repository containing the reference at ref_path"""
144-
while True:
144+
while True: # loop that overwrites ref_path each loop
145145
hexsha, ref_path = cls._get_ref_info(repo, ref_path)
146146
if hexsha is not None:
147147
return hexsha
148148
# END recursive dereferencing
149149

150150
@classmethod
151-
def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, str]]:
151+
def _get_ref_info_helper(cls, repo: 'Repo', ref_path: Union[PathLike, None]
152+
) -> Union[Tuple[str, None], Tuple[None, str]]:
152153
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
153154
rela_path points to, or None. target_ref_path is the reference we
154155
point to, or None"""
155156
tokens: Union[None, List[str], Tuple[str, str]] = None
156157
repodir = _git_dir(repo, ref_path)
157158
try:
158-
with open(os.path.join(repodir, ref_path), 'rt', encoding='UTF-8') as fp:
159+
with open(os.path.join(repodir, cast(str, ref_path)), 'rt', encoding='UTF-8') as fp:
159160
value = fp.read().rstrip()
160161
# Don't only split on spaces, but on whitespace, which allows to parse lines like
161162
# 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
@@ -187,7 +188,7 @@ def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[s
187188
raise ValueError("Failed to parse reference information from %r" % ref_path)
188189

189190
@classmethod
190-
def _get_ref_info(cls, repo, ref_path):
191+
def _get_ref_info(cls, repo: 'Repo', ref_path: Union[PathLike, None]) -> Union[Tuple[str, None], Tuple[None, str]]:
191192
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
192193
rela_path points to, or None. target_ref_path is the reference we
193194
point to, or None"""

0 commit comments

Comments
 (0)
Please sign in to comment.