Skip to content

Commit ed44b65

Browse files
fix
1 parent 202f779 commit ed44b65

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
@@ -7,7 +7,7 @@
77
import re
88
import sys
99
from pathlib import Path
10-
from typing import TYPE_CHECKING, Final, Iterable, Literal
10+
from typing import TYPE_CHECKING, Final, Iterable
1111
from urllib.parse import urlparse
1212

1313
import httpx
@@ -366,19 +366,17 @@ async def resolve_commit(config: CloneConfig, url: str, token: str | None) -> st
366366
if config.commit:
367367
commit = config.commit
368368
elif config.tag:
369-
commit = await _resolve_ref_to_sha(url, ref=config.tag, kind="tag", token=token)
369+
commit = await _resolve_ref_to_sha(url, pattern=f"refs/tags/{config.tag}*", token=token)
370370
elif config.branch:
371-
commit = await _resolve_ref_to_sha(url, ref=config.branch, kind="branch", token=token)
371+
commit = await _resolve_ref_to_sha(url, pattern=f"refs/heads/{config.branch}", token=token)
372372
else:
373-
commit = await _resolve_ref_to_sha(url, ref="HEAD", kind="branch", token=token)
373+
commit = await _resolve_ref_to_sha(url, pattern="HEAD", token=token)
374374
return commit
375375

376376

377377
async def _resolve_ref_to_sha(
378378
url: str,
379-
ref: str,
380-
kind: Literal["branch", "tag"],
381-
*,
379+
pattern: str,
382380
token: str | None = None,
383381
) -> str:
384382
"""Return the commit SHA that <kind>/<ref> points to in <url>.
@@ -390,10 +388,8 @@ async def _resolve_ref_to_sha(
390388
----------
391389
url : str
392390
The URL of the remote repository.
393-
ref : str
394-
The reference to resolve to a commit SHA.
395-
kind : Literal["branch", "tag"]
396-
The kind of reference to resolve to a commit SHA.
391+
pattern : str
392+
The pattern to use to resolve the commit SHA.
397393
token : str | None
398394
GitHub personal access token (PAT) for accessing private repositories.
399395
@@ -415,21 +411,12 @@ async def _resolve_ref_to_sha(
415411
if token and is_github_host(url):
416412
cmd += ["-c", create_git_auth_header(token, url=url)]
417413

418-
if ref == "HEAD":
419-
pattern = "HEAD"
420-
elif kind == "branch":
421-
pattern = f"refs/heads/{ref}"
422-
else: # tag
423-
pattern = f"refs/tags/{ref}*"
424-
425414
cmd += ["ls-remote", url, pattern]
426415
stdout, _ = await run_command(*cmd)
427-
428416
lines = stdout.decode().splitlines()
429-
430417
sha = _pick_commit_sha(lines)
431418
if not sha:
432-
msg = f"{kind} {ref!r} not found in {url}"
419+
msg = f"{pattern!r} not found in {url}"
433420
raise ValueError(msg)
434421

435422
return sha

0 commit comments

Comments
 (0)