|
18 | 18 | from dulwich.config import parse_submodules |
19 | 19 | from dulwich.errors import NotGitRepository |
20 | 20 | from dulwich.index import IndexEntry |
21 | | -from dulwich.objects import Commit |
22 | 21 | from dulwich.refs import ANNOTATED_TAG_SUFFIX |
23 | 22 | from dulwich.repo import Repo |
24 | 23 |
|
@@ -55,14 +54,14 @@ class GitRefSpec: |
55 | 54 | tag: str | None = None |
56 | 55 | ref: bytes = dataclasses.field(default_factory=lambda: b"HEAD") |
57 | 56 |
|
58 | | - def resolve(self, remote_refs: FetchPackResult) -> None: |
| 57 | + def resolve(self, remote_refs: FetchPackResult, repo: Repo) -> None: |
59 | 58 | """ |
60 | 59 | Resolve the ref using the provided remote refs. |
61 | 60 | """ |
62 | | - self._normalise(remote_refs=remote_refs) |
| 61 | + self._normalise(remote_refs=remote_refs, repo=repo) |
63 | 62 | self._set_head(remote_refs=remote_refs) |
64 | 63 |
|
65 | | - def _normalise(self, remote_refs: FetchPackResult) -> None: |
| 64 | + def _normalise(self, remote_refs: FetchPackResult, repo: Repo) -> None: |
66 | 65 | """ |
67 | 66 | Internal helper method to determine if given revision is |
68 | 67 | 1. a branch or tag; if so, set corresponding properties. |
@@ -99,7 +98,12 @@ def _normalise(self, remote_refs: FetchPackResult) -> None: |
99 | 98 | for sha in remote_refs.refs.values(): |
100 | 99 | if sha.startswith(short_sha): |
101 | 100 | self.revision = sha.decode("utf-8") |
102 | | - break |
| 101 | + return |
| 102 | + |
| 103 | + # no heads with such SHA, let's check all objects |
| 104 | + for sha in repo.object_store.iter_prefix(short_sha): |
| 105 | + self.revision = sha.decode("utf-8") |
| 106 | + return |
103 | 107 |
|
104 | 108 | def _set_head(self, remote_refs: FetchPackResult) -> None: |
105 | 109 | """ |
@@ -270,7 +274,7 @@ def _clone(cls, url: str, refspec: GitRefSpec, target: Path) -> Repo: |
270 | 274 | ) |
271 | 275 |
|
272 | 276 | try: |
273 | | - refspec.resolve(remote_refs=remote_refs) |
| 277 | + refspec.resolve(remote_refs=remote_refs, repo=local) |
274 | 278 | except KeyError: # branch / ref does not exist |
275 | 279 | raise PoetryConsoleError( |
276 | 280 | f"Failed to clone {url} at '{refspec.key}', verify ref exists on" |
@@ -314,38 +318,13 @@ def _clone(cls, url: str, refspec: GitRefSpec, target: Path) -> Repo: |
314 | 318 | if isinstance(e, AssertionError) and "Invalid object name" not in str(e): |
315 | 319 | raise |
316 | 320 |
|
317 | | - short_ref_found = False |
318 | | - |
319 | | - if refspec.is_sha_short: |
320 | | - commit = cls._find_object_by_sha_prefix(local, refspec.key.encode()) |
321 | | - if commit is not None: |
322 | | - logger.debug( |
323 | | - "\nResolved short SHA <c2>%s</c2> as <c2>%s</c2>", |
324 | | - refspec.key, |
325 | | - commit.id, |
326 | | - ) |
327 | | - local.refs[b"HEAD"] = commit.id |
328 | | - with local: |
329 | | - local.reset_index() |
330 | | - short_ref_found = True |
331 | | - |
332 | | - if not short_ref_found: |
333 | | - raise PoetryConsoleError( |
334 | | - f"Failed to clone {url} at '{refspec.key}', verify ref exists on" |
335 | | - " remote." |
336 | | - ) |
| 321 | + raise PoetryConsoleError( |
| 322 | + f"Failed to clone {url} at '{refspec.key}', verify ref exists on" |
| 323 | + " remote." |
| 324 | + ) |
337 | 325 |
|
338 | 326 | return local |
339 | 327 |
|
340 | | - @classmethod |
341 | | - def _find_object_by_sha_prefix(cls, repo: Repo, sha_prefix: bytes) -> Commit | None: |
342 | | - for sha in repo.object_store: |
343 | | - if sha.startswith(sha_prefix): |
344 | | - obj = repo.object_store[sha] |
345 | | - if isinstance(obj, Commit): |
346 | | - return obj |
347 | | - return None |
348 | | - |
349 | 328 | @classmethod |
350 | 329 | def _clone_submodules(cls, repo: Repo) -> None: |
351 | 330 | """ |
|
0 commit comments