From 99715fa658a8b2f81c5337415c2a61ac1fa44951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Wed, 7 Feb 2024 21:12:42 +0545 Subject: [PATCH] dulwich: add ls-remote to list remote repository Closes #321. --- src/scmrepo/git/backend/dulwich/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/scmrepo/git/backend/dulwich/__init__.py b/src/scmrepo/git/backend/dulwich/__init__.py index 4a47da5d..c30c6563 100644 --- a/src/scmrepo/git/backend/dulwich/__init__.py +++ b/src/scmrepo/git/backend/dulwich/__init__.py @@ -978,3 +978,17 @@ 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.client import HTTPUnauthorized + from dulwich.porcelain import ls_remote + + try: + return { + os.fsdecode(ref): sha.decode("ascii") for ref, sha in ls_remote(url).items() + } + except HTTPUnauthorized as exc: + raise AuthError(url) from exc + except Exception as exc: # noqa: BLE001 + raise InvalidRemote(url) from exc