|
34 | 34 | from ..base import BaseGitBackend, SyncStatus |
35 | 35 |
|
36 | 36 | if TYPE_CHECKING: |
| 37 | + from dulwich.client import SSHVendor |
37 | 38 | from dulwich.repo import Repo |
38 | 39 |
|
39 | 40 | from scmrepo.progress import GitProgressEvent |
@@ -103,16 +104,29 @@ def write(self, msg: Union[str, bytes]) -> int: |
103 | 104 | return len(msg) |
104 | 105 |
|
105 | 106 |
|
| 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 | + |
106 | 121 | class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method |
107 | 122 | """Dulwich Git backend.""" |
108 | 123 |
|
109 | 124 | from dulwich import client |
110 | 125 |
|
111 | | - from .asyncssh_vendor import AsyncSSHVendor |
112 | 126 | from .client import GitCredentialsHTTPClient |
113 | 127 |
|
114 | 128 | # 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] |
116 | 130 | # monkeypatch dulwich client's default HTTPClient to add support for |
117 | 131 | # git credential helpers. See https://github.com/jelmer/dulwich/pull/976 |
118 | 132 | client.HttpGitClient = GitCredentialsHTTPClient # type: ignore[assignment] |
|
0 commit comments