Skip to content

Commit 6d2e2fd

Browse files
fix
1 parent 3edb86f commit 6d2e2fd

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

src/gitingest/utils/git_utils.py

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import base64
77
import re
88
from pathlib import Path
9-
from typing import TYPE_CHECKING, Final, Iterable, Literal
9+
from typing import TYPE_CHECKING, Final, Iterable
1010
from urllib.parse import urlparse
1111

1212
import httpx
@@ -348,19 +348,17 @@ async def resolve_commit(config: CloneConfig, url: str, token: str | None) -> st
348348
if config.commit:
349349
commit = config.commit
350350
elif config.tag:
351-
commit = await _resolve_ref_to_sha(url, ref=config.tag, kind="tag", token=token)
351+
commit = await _resolve_ref_to_sha(url, pattern=f"refs/tags/{config.tag}*", token=token)
352352
elif config.branch:
353-
commit = await _resolve_ref_to_sha(url, ref=config.branch, kind="branch", token=token)
353+
commit = await _resolve_ref_to_sha(url, pattern=f"refs/heads/{config.branch}", token=token)
354354
else:
355-
commit = await _resolve_ref_to_sha(url, ref="HEAD", kind="branch", token=token)
355+
commit = await _resolve_ref_to_sha(url, pattern="HEAD", token=token)
356356
return commit
357357

358358

359359
async def _resolve_ref_to_sha(
360360
url: str,
361-
ref: str,
362-
kind: Literal["branch", "tag"],
363-
*,
361+
pattern: str,
364362
token: str | None = None,
365363
) -> str:
366364
"""Return the commit SHA that <kind>/<ref> points to in <url>.
@@ -372,10 +370,8 @@ async def _resolve_ref_to_sha(
372370
----------
373371
url : str
374372
The URL of the remote repository.
375-
ref : str
376-
The reference to resolve to a commit SHA.
377-
kind : Literal["branch", "tag"]
378-
The kind of reference to resolve to a commit SHA.
373+
pattern : str
374+
The pattern to use to resolve the commit SHA.
379375
token : str | None
380376
GitHub personal access token (PAT) for accessing private repositories.
381377
@@ -397,21 +393,12 @@ async def _resolve_ref_to_sha(
397393
if token and is_github_host(url):
398394
cmd += ["-c", create_git_auth_header(token, url=url)]
399395

400-
if ref == "HEAD":
401-
pattern = "HEAD"
402-
elif kind == "branch":
403-
pattern = f"refs/heads/{ref}"
404-
else: # tag
405-
pattern = f"refs/tags/{ref}*"
406-
407396
cmd += ["ls-remote", url, pattern]
408397
stdout, _ = await run_command(*cmd)
409-
410398
lines = stdout.decode().splitlines()
411-
412399
sha = _pick_commit_sha(lines)
413400
if not sha:
414-
msg = f"{kind} {ref!r} not found in {url}"
401+
msg = f"{pattern!r} not found in {url}"
415402
raise ValueError(msg)
416403

417404
return sha

0 commit comments

Comments
 (0)