summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-07-31 20:18:20 +0100
committerYobmod <yobmod@gmail.com>2021-07-31 20:18:20 +0100
commit2a350b57ce79a0e1b71623d1146c52918232e074 (patch)
tree9253532b6bb74372d2034c16ad58c6094f11fcc8
parent3c2454d20ba60e3350f3da103d5c1570ccc41c6f (diff)
downloadgitpython-2a350b57ce79a0e1b71623d1146c52918232e074.tar.gz
Add final final types to symbolic.py
-rw-r--r--git/refs/symbolic.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py
index bcd3d261..b4a933aa 100644
--- a/git/refs/symbolic.py
+++ b/git/refs/symbolic.py
@@ -40,7 +40,7 @@ T_References = TypeVar('T_References', bound='SymbolicReference')
__all__ = ["SymbolicReference"]
-def _git_dir(repo: 'Repo', path: PathLike) -> PathLike:
+def _git_dir(repo: 'Repo', path: Union[PathLike, None]) -> PathLike:
""" Find the git dir that's appropriate for the path"""
name = f"{path}"
if name in ['HEAD', 'ORIG_HEAD', 'FETCH_HEAD', 'index', 'logs']:
@@ -140,26 +140,28 @@ class SymbolicReference(object):
# alright.
@classmethod
- def dereference_recursive(cls, repo: 'Repo', ref_path: PathLike) -> str:
+ def dereference_recursive(cls, repo: 'Repo', ref_path: Union[PathLike, None]) -> str:
"""
:return: hexsha stored in the reference at the given ref_path, recursively dereferencing all
intermediate references as required
:param repo: the repository containing the reference at ref_path"""
+
while True:
- hexsha, ref_path = cls._get_ref_info(repo, ref_path) # type: ignore
+ hexsha, ref_path = cls._get_ref_info(repo, ref_path)
if hexsha is not None:
return hexsha
# END recursive dereferencing
@classmethod
- def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, str]]:
+ def _get_ref_info_helper(cls, repo: 'Repo', ref_path: Union[PathLike, None]
+ ) -> Union[Tuple[str, None], Tuple[None, str]]:
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
rela_path points to, or None. target_ref_path is the reference we
point to, or None"""
tokens: Union[None, List[str], Tuple[str, str]] = None
repodir = _git_dir(repo, ref_path)
try:
- with open(os.path.join(repodir, ref_path), 'rt', encoding='UTF-8') as fp:
+ with open(os.path.join(repodir, str(ref_path)), 'rt', encoding='UTF-8') as fp:
value = fp.read().rstrip()
# Don't only split on spaces, but on whitespace, which allows to parse lines like
# 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo
@@ -191,7 +193,7 @@ class SymbolicReference(object):
raise ValueError("Failed to parse reference information from %r" % ref_path)
@classmethod
- def _get_ref_info(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, str]]:
+ def _get_ref_info(cls, repo: 'Repo', ref_path: Union[PathLike, None]) -> Union[Tuple[str, None], Tuple[None, str]]:
"""Return: (str(sha), str(target_ref_path)) if available, the sha the file at
rela_path points to, or None. target_ref_path is the reference we
point to, or None"""