Skip to content

Commit

Permalink
dulwich: add ls-remote to list remote repository (#322)
Browse files Browse the repository at this point in the history
Closes #321.
  • Loading branch information
skshetry authored Feb 14, 2024
1 parent 6854f0d commit 454a522
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/scmrepo/git/backend/dulwich/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,16 @@ def _parse_identity(identity: str) -> tuple[str, str]:
if not m:
raise SCMError("Could not parse tagger identity '{identity}'")
return m.group("name"), m.group("email")


def ls_remote(url: str) -> dict[str, str]:
from dulwich import porcelain
from dulwich.client import HTTPUnauthorized

try:
refs = porcelain.ls_remote(url)
return {os.fsdecode(ref): sha.decode("ascii") for ref, sha in refs.items()}
except HTTPUnauthorized as exc:
raise AuthError(url) from exc
except Exception as exc: # noqa: BLE001
raise InvalidRemote(url) from exc

0 comments on commit 454a522

Please sign in to comment.