Skip to content

Commit 52b5b4f

Browse files
committed
dulwich: use GIT_SSH_COMMAND when set
1 parent 75e0b28 commit 52b5b4f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from ..base import BaseGitBackend, SyncStatus
3535

3636
if TYPE_CHECKING:
37+
from dulwich.client import SSHVendor
3738
from dulwich.repo import Repo
3839

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

105106

107+
def _get_ssh_vendor() -> "SSHVendor":
108+
from dulwich.client import SubprocessSSHVendor
109+
110+
from .asyncssh_vendor import AsyncSSHVendor
111+
112+
ssh_command = os.environ.get("GIT_SSH_COMMAND", os.environ.get("GIT_SSH"))
113+
if ssh_command:
114+
logger.debug(
115+
"dulwich: Using environment GIT_SSH_COMMAND '%s'", ssh_command
116+
)
117+
return SubprocessSSHVendor()
118+
return AsyncSSHVendor()
119+
120+
106121
class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
107122
"""Dulwich Git backend."""
108123

109124
from dulwich import client
110125

111-
from .asyncssh_vendor import AsyncSSHVendor
112126
from .client import GitCredentialsHTTPClient
113127

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

0 commit comments

Comments
 (0)