Skip to content

Commit 661013c

Browse files
committed
fix(pygit2) migrate ls_remotes to list_heads
1 parent 802269b commit 661013c

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ dynamic = ["version"]
2626
dependencies = [
2727
"gitpython>3",
2828
"dulwich>=0.24.0",
29-
"pygit2>=1.14.0",
29+
"pygit2>=1.14.0,<1.19.0; python_version < '3.11'",
30+
"pygit2>=1.19.0; python_version >= '3.11'",
3031
"pygtrie>=2.3.2",
3132
"fsspec[tqdm]>=2024.2.0",
3233
"pathspec>=0.9.0",

src/scmrepo/git/backend/pygit2/__init__.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import stat
5+
import sys
56
from collections.abc import Iterable, Iterator, Mapping
67
from contextlib import contextmanager
78
from io import BytesIO, StringIO, TextIOWrapper
@@ -731,14 +732,21 @@ def _default_status(
731732
SCMError(f"Git failed to fetch ref from '{url}'"),
732733
):
733734
with RemoteCallbacks(progress=progress) as cb:
734-
remote_refs: dict[str, Oid] = (
735-
{
736-
head["name"]: head["oid"]
737-
for head in remote.ls_remotes(callbacks=cb, proxy=True)
738-
}
739-
if not force
740-
else {}
741-
)
735+
remote_refs: dict[str, Oid] = {}
736+
if not force:
737+
# pygit2 1.19.0 deprecated ls_remotes() in favor of list_heads()
738+
# but 1.19.0+ requires Python 3.11+
739+
if sys.version_info >= (3, 11):
740+
for head in remote.list_heads(callbacks=cb, proxy=True):
741+
assert head.name is not None
742+
remote_refs[head.name] = head.oid
743+
else:
744+
remote_refs = {
745+
head["name"]: head["oid"]
746+
for head in remote.ls_remotes( # type: ignore[attr-defined]
747+
callbacks=cb, proxy=True
748+
)
749+
}
742750
remote.fetch(
743751
refspecs=refspecs, callbacks=cb, message="fetch", proxy=True
744752
)

0 commit comments

Comments
 (0)