Skip to content

Commit 7ccd1b0

Browse files
authored
pygit2: Raise NotImplementedError on ssh remotes. (#201)
1 parent b5c804e commit 7ccd1b0

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/scmrepo/git/__init__.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,12 @@ def fetch_refspecs(
327327
progress: Optional[Callable[["GitProgressEvent"], None]] = None,
328328
**kwargs,
329329
) -> typing.Mapping[str, SyncStatus]:
330-
from urllib.parse import urlparse
331-
332330
from .credentials import get_matching_helper_commands
333331

334-
if "dulwich" in kwargs.get("backends", self.backends.backends):
335-
credentials_helper = any(
336-
get_matching_helper_commands(url, self.dulwich.repo.get_config_stack())
337-
)
338-
parsed = urlparse(url)
339-
ssh = parsed.scheme in ("git", "git+ssh", "ssh") or url.startswith("git@")
340-
if credentials_helper or ssh:
341-
kwargs["backends"] = ["dulwich"]
332+
if "dulwich" in kwargs.get("backends", self.backends.backends) and any(
333+
get_matching_helper_commands(url, self.dulwich.repo.get_config_stack())
334+
):
335+
kwargs["backends"] = ["dulwich"]
342336

343337
return self._fetch_refspecs(
344338
url,

src/scmrepo/git/backend/pygit2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Tuple,
1717
Union,
1818
)
19+
from urllib.parse import urlparse
1920

2021
from funcy import cached_property, reraise
2122
from shortuuid import uuid
@@ -460,7 +461,8 @@ def get_remote(self, url: str) -> Generator["Remote", None, None]:
460461
except KeyError:
461462
raise SCMError(f"'{url}' is not a valid Git remote or URL")
462463

463-
if os.name == "nt" and url.startswith("ssh://"):
464+
parsed = urlparse(url)
465+
if parsed.scheme in ("git", "git+ssh", "ssh") or url.startswith("git@"):
464466
raise NotImplementedError
465467
if os.name == "nt" and url.startswith("file://"):
466468
url = url[len("file://") :]

tests/test_pygit2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=unused-argument
12
import pygit2
23
import pytest
34
from pytest_mock import MockerFixture
@@ -58,3 +59,17 @@ def test_pygit_stash_apply_conflicts(
5859
strategy=expected_strategy,
5960
reinstate_index=False,
6061
)
62+
63+
64+
@pytest.mark.parametrize(
65+
"url",
66+
[
67+
"[email protected]:iterative/scmrepo.git",
68+
"ssh://[email protected]:12345/repository.git",
69+
],
70+
)
71+
def test_pygit2_ssh_error(tmp_dir: TmpDir, scm: Git, url):
72+
backend = Pygit2Backend(tmp_dir)
73+
with pytest.raises(NotImplementedError):
74+
with backend.get_remote(url):
75+
pass

0 commit comments

Comments
 (0)