|
40 | 40 | __all__ = ["SymbolicReference"] |
41 | 41 |
|
42 | 42 |
|
43 | | -def _git_dir(repo: 'Repo', path: PathLike) -> PathLike: |
| 43 | +def _git_dir(repo: 'Repo', path: Union[PathLike, None]) -> PathLike: |
44 | 44 | """ Find the git dir that's appropriate for the path""" |
45 | 45 | name = f"{path}" |
46 | 46 | if name in ['HEAD', 'ORIG_HEAD', 'FETCH_HEAD', 'index', 'logs']: |
@@ -140,26 +140,28 @@ def _iter_packed_refs(cls, repo: 'Repo') -> Iterator[Tuple[str, str]]: |
140 | 140 | # alright. |
141 | 141 |
|
142 | 142 | @classmethod |
143 | | - def dereference_recursive(cls, repo: 'Repo', ref_path: PathLike) -> str: |
| 143 | + def dereference_recursive(cls, repo: 'Repo', ref_path: Union[PathLike, None]) -> str: |
144 | 144 | """ |
145 | 145 | :return: hexsha stored in the reference at the given ref_path, recursively dereferencing all |
146 | 146 | intermediate references as required |
147 | 147 | :param repo: the repository containing the reference at ref_path""" |
| 148 | + |
148 | 149 | while True: |
149 | | - hexsha, ref_path = cls._get_ref_info(repo, ref_path) # type: ignore |
| 150 | + hexsha, ref_path = cls._get_ref_info(repo, ref_path) |
150 | 151 | if hexsha is not None: |
151 | 152 | return hexsha |
152 | 153 | # END recursive dereferencing |
153 | 154 |
|
154 | 155 | @classmethod |
155 | | - def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, str]]: |
| 156 | + def _get_ref_info_helper(cls, repo: 'Repo', ref_path: Union[PathLike, None] |
| 157 | + ) -> Union[Tuple[str, None], Tuple[None, str]]: |
156 | 158 | """Return: (str(sha), str(target_ref_path)) if available, the sha the file at |
157 | 159 | rela_path points to, or None. target_ref_path is the reference we |
158 | 160 | point to, or None""" |
159 | 161 | tokens: Union[None, List[str], Tuple[str, str]] = None |
160 | 162 | repodir = _git_dir(repo, ref_path) |
161 | 163 | try: |
162 | | - with open(os.path.join(repodir, ref_path), 'rt', encoding='UTF-8') as fp: |
| 164 | + with open(os.path.join(repodir, str(ref_path)), 'rt', encoding='UTF-8') as fp: |
163 | 165 | value = fp.read().rstrip() |
164 | 166 | # Don't only split on spaces, but on whitespace, which allows to parse lines like |
165 | 167 | # 60b64ef992065e2600bfef6187a97f92398a9144 branch 'master' of git-server:/path/to/repo |
@@ -191,7 +193,7 @@ def _get_ref_info_helper(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[s |
191 | 193 | raise ValueError("Failed to parse reference information from %r" % ref_path) |
192 | 194 |
|
193 | 195 | @classmethod |
194 | | - def _get_ref_info(cls, repo: 'Repo', ref_path: PathLike) -> Union[Tuple[str, None], Tuple[None, str]]: |
| 196 | + def _get_ref_info(cls, repo: 'Repo', ref_path: Union[PathLike, None]) -> Union[Tuple[str, None], Tuple[None, str]]: |
195 | 197 | """Return: (str(sha), str(target_ref_path)) if available, the sha the file at |
196 | 198 | rela_path points to, or None. target_ref_path is the reference we |
197 | 199 | point to, or None""" |
|
0 commit comments