Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ dynamic = ["version"]
dependencies = [
"gitpython>3",
"dulwich>=0.24.0",
"pygit2>=1.14.0",
"pygit2>=1.14.0,<1.19.0; python_version < '3.11'",
"pygit2>=1.19.0; python_version >= '3.11'",
"pygtrie>=2.3.2",
"fsspec[tqdm]>=2024.2.0",
"pathspec>=0.9.0",
Expand Down
31 changes: 23 additions & 8 deletions src/scmrepo/git/backend/pygit2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,26 @@ def _get_remote(self, url: str) -> Iterator["Remote"]:
raise NotImplementedError
yield remote

@staticmethod
def _get_remote_refs(remote: "Remote", callbacks) -> dict[str, "Oid"]:
"""Get remote refs using the appropriate pygit2 API.

pygit2 1.19.0 deprecated ls_remotes() in favor of list_heads(),
but 1.19.0+ requires Python 3.11+.
"""
if hasattr(remote, "list_heads"):
result: dict[str, Oid] = {}
for head in remote.list_heads(callbacks=callbacks, proxy=True):
assert head.name is not None
result[head.name] = head.oid
return result
return {
head["name"]: head["oid"]
for head in remote.ls_remotes( # type: ignore[attr-defined]
callbacks=callbacks, proxy=True
)
}

def fetch_refspecs(
self,
url: str,
Expand Down Expand Up @@ -731,14 +751,9 @@ def _default_status(
SCMError(f"Git failed to fetch ref from '{url}'"),
):
with RemoteCallbacks(progress=progress) as cb:
remote_refs: dict[str, Oid] = (
{
head["name"]: head["oid"]
for head in remote.ls_remotes(callbacks=cb, proxy=True)
}
if not force
else {}
)
remote_refs: dict[str, Oid] = {}
if not force:
remote_refs = self._get_remote_refs(remote, cb)
remote.fetch(
refspecs=refspecs, callbacks=cb, message="fetch", proxy=True
)
Expand Down
Loading