Resolve `reference` to a full commit SHA with `git ls-remote`.
(repository: str, reference: str)
| 372 | |
| 373 | |
| 374 | def resolve_reference(repository: str, reference: str) -> str: |
| 375 | """Resolve `reference` to a full commit SHA with `git ls-remote`.""" |
| 376 | if is_full_sha(reference): |
| 377 | return reference.lower() |
| 378 | result = subprocess.run( |
| 379 | [ |
| 380 | "git", |
| 381 | "ls-remote", |
| 382 | repository, |
| 383 | f"refs/tags/{reference}", |
| 384 | f"refs/tags/{reference}^{{}}", |
| 385 | f"refs/heads/{reference}", |
| 386 | ], |
| 387 | capture_output=True, |
| 388 | text=True, |
| 389 | check=False, |
| 390 | ) |
| 391 | if result.returncode != 0: |
| 392 | raise PinError( |
| 393 | f"git ls-remote {repository} {reference} failed: {result.stderr.strip()}" |
| 394 | ) |
| 395 | try: |
| 396 | return commit_from_ls_remote(result.stdout, reference) |
| 397 | except PinError as exc: |
| 398 | raise PinError(f"could not resolve {reference} on {repository}") from exc |
| 399 | |
| 400 | |
| 401 | def run_cargo(root: Path, args: list[str]) -> None: |
no test coverage detected