Skip to content
Merged
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
18 changes: 16 additions & 2 deletions src/scmrepo/git/backend/dulwich/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from ..base import BaseGitBackend, SyncStatus

if TYPE_CHECKING:
from dulwich.client import SSHVendor
from dulwich.repo import Repo

from scmrepo.progress import GitProgressEvent
Expand Down Expand Up @@ -103,16 +104,29 @@ def write(self, msg: Union[str, bytes]) -> int:
return len(msg)


def _get_ssh_vendor() -> "SSHVendor":
from dulwich.client import SubprocessSSHVendor

from .asyncssh_vendor import AsyncSSHVendor

ssh_command = os.environ.get("GIT_SSH_COMMAND", os.environ.get("GIT_SSH"))
if ssh_command:
logger.debug(
"dulwich: Using environment GIT_SSH_COMMAND '%s'", ssh_command
)
return SubprocessSSHVendor()
return AsyncSSHVendor()


class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
"""Dulwich Git backend."""

from dulwich import client

from .asyncssh_vendor import AsyncSSHVendor
from .client import GitCredentialsHTTPClient

# monkeypatch dulwich client's default SSH vendor to use asyncssh
client.get_ssh_vendor = AsyncSSHVendor # type: ignore[assignment]
client.get_ssh_vendor = _get_ssh_vendor # type: ignore[assignment]
# monkeypatch dulwich client's default HTTPClient to add support for
# git credential helpers. See https://github.com/jelmer/dulwich/pull/976
client.HttpGitClient = GitCredentialsHTTPClient # type: ignore[assignment]
Expand Down