Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 4 additions & 10 deletions src/scmrepo/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,12 @@ def fetch_refspecs(
progress: Optional[Callable[["GitProgressEvent"], None]] = None,
**kwargs,
) -> typing.Mapping[str, SyncStatus]:
from urllib.parse import urlparse

from .credentials import get_matching_helper_commands

if "dulwich" in kwargs.get("backends", self.backends.backends):
credentials_helper = any(
get_matching_helper_commands(url, self.dulwich.repo.get_config_stack())
)
parsed = urlparse(url)
ssh = parsed.scheme in ("git", "git+ssh", "ssh") or url.startswith("git@")
if credentials_helper or ssh:
kwargs["backends"] = ["dulwich"]
if "dulwich" in kwargs.get("backends", self.backends.backends) and any(
get_matching_helper_commands(url, self.dulwich.repo.get_config_stack())
):
kwargs["backends"] = ["dulwich"]

return self._fetch_refspecs(
url,
Expand Down
4 changes: 3 additions & 1 deletion src/scmrepo/git/backend/pygit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Tuple,
Union,
)
from urllib.parse import urlparse

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

if os.name == "nt" and url.startswith("ssh://"):
parsed = urlparse(url)
if parsed.scheme in ("git", "git+ssh", "ssh") or url.startswith("git@"):
raise NotImplementedError
if os.name == "nt" and url.startswith("file://"):
url = url[len("file://") :]
Expand Down
15 changes: 15 additions & 0 deletions tests/test_pygit2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=unused-argument
import pygit2
import pytest
from pytest_mock import MockerFixture
Expand Down Expand Up @@ -58,3 +59,17 @@ def test_pygit_stash_apply_conflicts(
strategy=expected_strategy,
reinstate_index=False,
)


@pytest.mark.parametrize(
"url",
[
"git@github.com:iterative/scmrepo.git",
"ssh://login@server.com:12345/repository.git",
],
)
def test_pygit2_ssh_error(tmp_dir: TmpDir, scm: Git, url):
backend = Pygit2Backend(tmp_dir)
with pytest.raises(NotImplementedError):
with backend.get_remote(url):
pass