From f066c7adb5f5773dc1d0dd986c786bc0c5094e31 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 16:52:42 +0100 Subject: Add type to symbolicreference.is_remote() --- git/refs/symbolic.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index bffcfea5..b072f142 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -526,8 +526,9 @@ class SymbolicReference(object): return ref @classmethod - def create(cls, repo: 'Repo', path: PathLike, reference: Union[Commit_ish, str] = 'HEAD', - logmsg: Union[str, None] = None, force: bool = False, **kwargs: Any): + def create(cls: Type[T_References], repo: 'Repo', path: PathLike, + reference: Union['SymbolicReference', str] = 'HEAD', + logmsg: Union[str, None] = None, force: bool = False, **kwargs: Any) -> T_References: """Create a new symbolic reference, hence a reference pointing , to another reference. :param repo: @@ -689,6 +690,6 @@ class SymbolicReference(object): # END for each type to try raise ValueError("Could not find reference type suitable to handle path %r" % path) - def is_remote(self): + def is_remote(self) -> bool: """:return: True if this symbolic reference points to a remote branch""" - return self.path.startswith(self._remote_common_path_default + "/") + return str(self.path).startswith(self._remote_common_path_default + "/") -- cgit v1.2.1 From a8ee94b1998589085ae2b8a6de310d0a5dfd0ffd Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 16:57:56 +0100 Subject: Add type to symbolicreference._create() --- git/refs/symbolic.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index b072f142..1000204f 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -493,7 +493,9 @@ class SymbolicReference(object): # END remove reflog @classmethod - def _create(cls, repo, path, resolve, reference, force, logmsg=None): + def _create(cls: Type[T_References], repo: 'Repo', path: PathLike, resolve: bool, + reference: Union['SymbolicReference', str], force: bool, + logmsg: Union[str, None] = None) -> T_References: """internal method used to create a new symbolic reference. If resolve is False, the reference will be taken as is, creating a proper symbolic reference. Otherwise it will be resolved to the @@ -511,7 +513,7 @@ class SymbolicReference(object): if not force and os.path.isfile(abs_ref_path): target_data = str(target) if isinstance(target, SymbolicReference): - target_data = target.path + target_data = str(target.path) if not resolve: target_data = "ref: " + target_data with open(abs_ref_path, 'rb') as fd: -- cgit v1.2.1 From afd2ec5251479f48044408c7fcb7dab0494cd4c1 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 17:02:53 +0100 Subject: Add type to symbolicreference.delete() --- git/refs/symbolic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 1000204f..89999eda 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -421,7 +421,7 @@ class SymbolicReference(object): return RefLog.entry_at(RefLog.path(self), index) @classmethod - def to_full_path(cls, path) -> PathLike: + def to_full_path(cls, path: Union[PathLike, 'SymbolicReference']) -> PathLike: """ :return: string with a full repository-relative path which can be used to initialize a Reference instance, for instance by using ``Reference.from_path``""" @@ -430,12 +430,12 @@ class SymbolicReference(object): full_ref_path = path if not cls._common_path_default: return full_ref_path - if not path.startswith(cls._common_path_default + "/"): + if not str(path).startswith(cls._common_path_default + "/"): full_ref_path = '%s/%s' % (cls._common_path_default, path) return full_ref_path @classmethod - def delete(cls, repo, path): + def delete(cls, repo: 'Repo', path: PathLike) -> None: """Delete the reference at the given path :param repo: @@ -457,8 +457,8 @@ class SymbolicReference(object): new_lines = [] made_change = False dropped_last_line = False - for line in reader: - line = line.decode(defenc) + for line_bytes in reader: + line = line_bytes.decode(defenc) _, _, line_ref = line.partition(' ') line_ref = line_ref.strip() # keep line if it is a comment or if the ref to delete is not -- cgit v1.2.1 From 581d40d957fd3d7ee85c28c4dde4d6f28e104433 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 17:06:22 +0100 Subject: Add type to symbolicreference.log_append() --- git/refs/symbolic.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 89999eda..5d3a6a0d 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -27,6 +27,10 @@ from git.types import Commit_ish, PathLike, TBD, Literal if TYPE_CHECKING: from git.repo import Repo from git.refs import Head, TagReference, Reference + from .log import RefLogEntry + from git.config import GitConfigParser + from git.objects.commit import Actor + T_References = TypeVar('T_References', bound='SymbolicReference') @@ -391,7 +395,8 @@ class SymbolicReference(object): instead of calling this method repeatedly. It should be considered read-only.""" return RefLog.from_file(RefLog.path(self)) - def log_append(self, oldbinsha, message, newbinsha=None): + def log_append(self, oldbinsha: bytes, message: Union[str, None], + newbinsha: Union[bytes, None] = None) -> 'RefLogEntry': """Append a logentry to the logfile of this ref :param oldbinsha: binary sha this ref used to point to @@ -403,15 +408,19 @@ class SymbolicReference(object): # correct to allow overriding the committer on a per-commit level. # See https://github.com/gitpython-developers/GitPython/pull/146 try: - committer_or_reader = self.commit.committer + committer_or_reader: Union['Actor', 'GitConfigParser'] = self.commit.committer except ValueError: committer_or_reader = self.repo.config_reader() # end handle newly cloned repositories - return RefLog.append_entry(committer_or_reader, RefLog.path(self), oldbinsha, - (newbinsha is None and self.commit.binsha) or newbinsha, - message) + if newbinsha is None: + newbinsha = self.commit.binsha + + if message is None: + message = '' + + return RefLog.append_entry(committer_or_reader, RefLog.path(self), oldbinsha, newbinsha, message) - def log_entry(self, index): + def log_entry(self, index: int) -> 'RefLogEntry': """:return: RefLogEntry at the given index :param index: python list compatible positive or negative index -- cgit v1.2.1 From 7f401fc659a7f9c84a9c88675aba498357a2916d Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 17:09:54 +0100 Subject: Add type to symbolicreference.is_valid() --- git/refs/symbolic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 5d3a6a0d..65bad6e4 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -360,9 +360,9 @@ class SymbolicReference(object): # aliased reference reference = property(_get_reference, set_reference, doc="Returns the Reference we point to") - ref: Union[Commit_ish] = reference # type: ignore # Union[str, Commit_ish, SymbolicReference] + ref: Union['Reference'] = reference # type: ignore - def is_valid(self): + def is_valid(self) -> bool: """ :return: True if the reference is valid, hence it can be read and points to @@ -375,7 +375,7 @@ class SymbolicReference(object): return True @property - def is_detached(self): + def is_detached(self) -> bool: """ :return: True if we are a detached reference, hence we point to a specific commit @@ -386,7 +386,7 @@ class SymbolicReference(object): except TypeError: return True - def log(self): + def log(self) -> 'RefLog': """ :return: RefLog for this reference. Its last entry reflects the latest change applied to this reference -- cgit v1.2.1 From e8442eead72bfc2a547234d0289d0f90642167fd Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 17:15:33 +0100 Subject: Add type to symbolicreference.set_reference() --- git/refs/symbolic.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 65bad6e4..4713e0c4 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -289,7 +289,8 @@ class SymbolicReference(object): raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha)) return self.from_path(self.repo, target_ref_path) - def set_reference(self, ref, logmsg=None): + def set_reference(self, ref: Union[Commit_ish, 'SymbolicReference', str], + logmsg: Union[str, None] = None) -> Union[Commit_ish, 'SymbolicReference']: """Set ourselves to the given ref. It will stay a symbol if the ref is a Reference. Otherwise an Object, given as Object instance or refspec, is assumed and if valid, will be set which effectively detaches the refererence if it was a purely @@ -330,7 +331,7 @@ class SymbolicReference(object): raise TypeError("Require commit, got %r" % obj) # END verify type - oldbinsha = None + oldbinsha: bytes = b'' if logmsg is not None: try: oldbinsha = self.commit.binsha @@ -359,8 +360,8 @@ class SymbolicReference(object): return self # aliased reference - reference = property(_get_reference, set_reference, doc="Returns the Reference we point to") - ref: Union['Reference'] = reference # type: ignore + reference = property(_get_reference, set_reference, doc="Returns the Reference we point to") # type: ignore + ref: Union['Reference'] = reference # type: ignore def is_valid(self) -> bool: """ -- cgit v1.2.1 From f2012e599e388580bf8823a23ff63a201e0bf4c4 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 17:25:46 +0100 Subject: Add type to symbolicreference.set_object() --- git/refs/reference.py | 4 ++-- git/refs/symbolic.py | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'git/refs') diff --git a/git/refs/reference.py b/git/refs/reference.py index bc2c6e80..539691e7 100644 --- a/git/refs/reference.py +++ b/git/refs/reference.py @@ -63,8 +63,8 @@ class Reference(SymbolicReference, LazyMixin, IterableObj): #{ Interface # @ReservedAssignment - def set_object(self, object: Union[Commit_ish, 'SymbolicReference'], logmsg: Union[str, None] = None - ) -> 'SymbolicReference': + def set_object(self, object: Union[Commit_ish, 'SymbolicReference', str], logmsg: Union[str, None] = None + ) -> 'Reference': """Special version which checks if the head-log needs an update as well :return: self""" oldbinsha = None diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 4713e0c4..0d2c9829 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -221,7 +221,8 @@ class SymbolicReference(object): # END handle type return obj - def set_commit(self, commit: Union[Commit, 'SymbolicReference', str], logmsg=None): + def set_commit(self, commit: Union[Commit, 'SymbolicReference', str], logmsg: Union[str, None] = None + ) -> 'SymbolicReference': """As set_object, but restricts the type of object to be a Commit :raise ValueError: If commit is not a Commit object or doesn't point to @@ -250,7 +251,8 @@ class SymbolicReference(object): return self - def set_object(self, object, logmsg=None): # @ReservedAssignment + def set_object(self, object: Union[Commit_ish, 'SymbolicReference', str], logmsg: Union[str, None] = None + ) -> 'SymbolicReference': """Set the object we point to, possibly dereference our symbolic reference first. If the reference does not exist, it will be created @@ -277,10 +279,10 @@ class SymbolicReference(object): # set the commit on our reference return self._get_reference().set_object(object, logmsg) - commit = property(_get_commit, set_commit, doc="Query or set commits directly") - object = property(_get_object, set_object, doc="Return the object our ref currently refers to") + commit = property(_get_commit, set_commit, doc="Query or set commits directly") # type: ignore + object = property(_get_object, set_object, doc="Return the object our ref currently refers to") # type: ignore - def _get_reference(self): + def _get_reference(self) -> 'SymbolicReference': """:return: Reference Object we point to :raise TypeError: If this symbolic reference is detached, hence it doesn't point to a reference, but to a commit""" @@ -290,7 +292,7 @@ class SymbolicReference(object): return self.from_path(self.repo, target_ref_path) def set_reference(self, ref: Union[Commit_ish, 'SymbolicReference', str], - logmsg: Union[str, None] = None) -> Union[Commit_ish, 'SymbolicReference']: + logmsg: Union[str, None] = None) -> 'SymbolicReference': """Set ourselves to the given ref. It will stay a symbol if the ref is a Reference. Otherwise an Object, given as Object instance or refspec, is assumed and if valid, will be set which effectively detaches the refererence if it was a purely -- cgit v1.2.1 From d4d46697a6ce23edba8e22030916dad28d42abc2 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 17:29:06 +0100 Subject: cleanup --- git/refs/reference.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/refs') diff --git a/git/refs/reference.py b/git/refs/reference.py index 539691e7..a3647fb3 100644 --- a/git/refs/reference.py +++ b/git/refs/reference.py @@ -7,7 +7,7 @@ from .symbolic import SymbolicReference, T_References # typing ------------------------------------------------------------------ -from typing import Any, Callable, Iterator, List, Match, Optional, Tuple, Type, TypeVar, Union, TYPE_CHECKING # NOQA +from typing import Any, Callable, Iterator, Type, Union, TYPE_CHECKING # NOQA from git.types import Commit_ish, PathLike, TBD, Literal, _T # NOQA if TYPE_CHECKING: -- cgit v1.2.1 From 13b38ce012dc1bf84d9dca8d141dcab86c0d4e09 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 17:49:18 +0100 Subject: Add type to symbolicreference.reference() --- git/refs/head.py | 1 + git/refs/symbolic.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'git/refs') diff --git a/git/refs/head.py b/git/refs/head.py index 260bf5e7..16027204 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -40,6 +40,7 @@ class HEAD(SymbolicReference): raise ValueError("HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path)) super(HEAD, self).__init__(repo, path) self.commit: 'Commit' + self.ref: 'Head' def orig_head(self) -> SymbolicReference: """ diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 0d2c9829..5ce74938 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -65,6 +65,7 @@ class SymbolicReference(object): def __init__(self, repo: 'Repo', path: PathLike, check_path: bool = False): self.repo = repo self.path = path + self.ref = self.reference def __str__(self) -> str: return str(self.path) @@ -282,7 +283,7 @@ class SymbolicReference(object): commit = property(_get_commit, set_commit, doc="Query or set commits directly") # type: ignore object = property(_get_object, set_object, doc="Return the object our ref currently refers to") # type: ignore - def _get_reference(self) -> 'SymbolicReference': + def _get_reference(self) -> 'Reference': """:return: Reference Object we point to :raise TypeError: If this symbolic reference is detached, hence it doesn't point to a reference, but to a commit""" @@ -362,8 +363,15 @@ class SymbolicReference(object): return self # aliased reference - reference = property(_get_reference, set_reference, doc="Returns the Reference we point to") # type: ignore - ref: Union['Reference'] = reference # type: ignore + # reference = property(_get_reference, set_reference, doc="Returns the Reference we point to") # type: ignore + + @property + def reference(self) -> 'Reference': + return self._get_reference() + + @reference.setter + def reference(self, *args, **kwargs): + return self.set_reference(*args, **kwargs) def is_valid(self) -> bool: """ -- cgit v1.2.1 From 3be955e5adc09d20a7e2e919ee1e95a7a0f5fb0e Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 17:53:44 +0100 Subject: Add type to symbolicreference.references() --- git/refs/head.py | 1 - git/refs/symbolic.py | 14 +++----------- 2 files changed, 3 insertions(+), 12 deletions(-) (limited to 'git/refs') diff --git a/git/refs/head.py b/git/refs/head.py index 16027204..260bf5e7 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -40,7 +40,6 @@ class HEAD(SymbolicReference): raise ValueError("HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path)) super(HEAD, self).__init__(repo, path) self.commit: 'Commit' - self.ref: 'Head' def orig_head(self) -> SymbolicReference: """ diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 5ce74938..ae391c1e 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -26,7 +26,7 @@ from git.types import Commit_ish, PathLike, TBD, Literal if TYPE_CHECKING: from git.repo import Repo - from git.refs import Head, TagReference, Reference + from git.refs import Head, TagReference, RemoteReference, Reference from .log import RefLogEntry from git.config import GitConfigParser from git.objects.commit import Actor @@ -65,7 +65,6 @@ class SymbolicReference(object): def __init__(self, repo: 'Repo', path: PathLike, check_path: bool = False): self.repo = repo self.path = path - self.ref = self.reference def __str__(self) -> str: return str(self.path) @@ -363,15 +362,8 @@ class SymbolicReference(object): return self # aliased reference - # reference = property(_get_reference, set_reference, doc="Returns the Reference we point to") # type: ignore - - @property - def reference(self) -> 'Reference': - return self._get_reference() - - @reference.setter - def reference(self, *args, **kwargs): - return self.set_reference(*args, **kwargs) + reference = property(_get_reference, set_reference, doc="Returns the Reference we point to") # type: ignore + ref: Union['Head', 'TagReference', 'RemoteReference', 'Reference'] = reference # type: ignore def is_valid(self) -> bool: """ -- cgit v1.2.1 From ef48a3513d7a9456fd57f4da248a9c73f9e668bd Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 18:01:01 +0100 Subject: Add type to refs.head.delete() --- git/refs/head.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'git/refs') diff --git a/git/refs/head.py b/git/refs/head.py index 260bf5e7..56a87182 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -21,7 +21,7 @@ if TYPE_CHECKING: __all__ = ["HEAD", "Head"] -def strip_quotes(string): +def strip_quotes(string: str) -> str: if string.startswith('"') and string.endswith('"'): return string[1:-1] return string @@ -129,14 +129,13 @@ class Head(Reference): k_config_remote_ref = "merge" # branch to merge from remote @classmethod - def delete(cls, repo: 'Repo', *heads: 'Head', **kwargs: Any): + def delete(cls, repo: 'Repo', *heads: 'Head', force: bool = False, **kwargs: Any) -> None: """Delete the given heads :param force: If True, the heads will be deleted even if they are not yet merged into the main development stream. Default False""" - force = kwargs.get("force", False) flag = "-d" if force: flag = "-D" -- cgit v1.2.1 From e364c5e327f916366e5936aa2c9f3f4065aec034 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 18:02:06 +0100 Subject: Add type to refs.log._read_from_file() --- git/refs/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/refs') diff --git a/git/refs/log.py b/git/refs/log.py index 643b4114..ddd78bc7 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -157,7 +157,7 @@ class RefLog(List[RefLogEntry], Serializable): self._read_from_file() # END handle filepath - def _read_from_file(self): + def _read_from_file(self) -> None: try: fmap = file_contents_ro_filepath( self._path, stream=True, allow_mmap=True) -- cgit v1.2.1 From 3c2454d20ba60e3350f3da103d5c1570ccc41c6f Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 20:10:29 +0100 Subject: Add final types to symbolic.py --- git/refs/symbolic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index ae391c1e..bcd3d261 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -146,13 +146,13 @@ class SymbolicReference(object): 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) + hexsha, ref_path = cls._get_ref_info(repo, ref_path) # type: ignore if hexsha is not None: return hexsha # END recursive dereferencing @classmethod - def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike): + def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> 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""" @@ -191,13 +191,13 @@ class SymbolicReference(object): raise ValueError("Failed to parse reference information from %r" % ref_path) @classmethod - def _get_ref_info(cls, repo, ref_path): + def _get_ref_info(cls, repo: 'Repo', ref_path: PathLike) -> 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""" return cls._get_ref_info_helper(repo, ref_path) - def _get_object(self): + def _get_object(self) -> Commit_ish: """ :return: The object our ref currently refers to. Refs can be cached, they will @@ -206,7 +206,7 @@ class SymbolicReference(object): # Our path will be resolved to the hexsha which will be used accordingly return Object.new_from_sha(self.repo, hex_to_bin(self.dereference_recursive(self.repo, self.path))) - def _get_commit(self): + def _get_commit(self) -> 'Commit': """ :return: Commit object we point to, works for detached and non-detached -- cgit v1.2.1 From 2a350b57ce79a0e1b71623d1146c52918232e074 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Sat, 31 Jul 2021 20:18:20 +0100 Subject: Add final final types to symbolic.py --- git/refs/symbolic.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'git/refs') 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""" -- cgit v1.2.1