Commit Diff


commit - 343ed68cdeb65d9a47851702cfd38f4cec8e2629
commit + 5c1a5ecedb1d272dc7121f5cb7fa191b040f929d
blob - 626b2be493884a139c4fd9cfd31dffedaf7c4e14
blob + 61dae810d378fc0c2f1fc530fb60b8c82c675c88
--- dulwich/client.py
+++ dulwich/client.py
@@ -1923,8 +1923,10 @@ class SubprocessSSHVendor(SSHVendor):
         if key_filename:
             args.extend(["-i", str(key_filename)])
 
-        if protocol_version is None or protocol_version == 2:
-            args.extend(["-o", "SetEnv GIT_PROTOCOL=version=2"])
+        if protocol_version is None:
+            protocol_version = DEFAULT_GIT_PROTOCOL_VERSION_FETCH
+        if protocol_version > 0:
+            args.extend(["-o", f"SetEnv GIT_PROTOCOL=version={protocol_version}"])
 
         if username:
             host = f"{username}@{host}"
@@ -1992,8 +1994,10 @@ class PLinkSSHVendor(SSHVendor):
         # does not work then the server should behave as if we had requested
         # protocol version 0.
         env = copy.deepcopy(os.environ)
-        if protocol_version is None or protocol_version == 2:
-            env["GIT_PROTOCOL"] = "version=2"
+        if protocol_version is None:
+            protocol_version = DEFAULT_GIT_PROTOCOL_VERSION_FETCH
+        if protocol_version > 0:
+            env["GIT_PROTOCOL"] = f"version={protocol_version}"
 
         proc = subprocess.Popen(
             [*args, command],
blob - 92475a98210074af763a375fa983e4f9885ddb0b
blob + 910a16953a9a5ed27b42ba3c1952636f9540513c
--- tests/compat/test_client.py
+++ tests/compat/test_client.py
@@ -435,8 +435,10 @@ class TestSSHVendor:
         cmd = cmd.split("-", 1)
         path = path.replace("'", "")
         env = dict(os.environ)
-        if protocol_version is None or protocol_version == 2:
-            env["GIT_PROTOCOL"] = "version=2"
+        if protocol_version is None:
+            protocol_version = protocol.DEFAULT_GIT_PROTOCOL_VERSION_FETCH
+        if protocol_version > 0:
+            env["GIT_PROTOCOL"] = f"version={protocol_version}"
 
         p = subprocess.Popen(
             [*cmd, path],
blob - 5bc1ada62218f301e6261516d1f0f1ed2c2c6a2a
blob + 329ace1c3432a9f8130942a0b75f5f1f550d9f93
--- tests/test_client.py
+++ tests/test_client.py
@@ -58,7 +58,7 @@ from dulwich.client import (
 from dulwich.config import ConfigDict
 from dulwich.objects import Commit, Tree
 from dulwich.pack import pack_objects_to_data, write_pack_data, write_pack_objects
-from dulwich.protocol import TCP_GIT_PORT, Protocol
+from dulwich.protocol import DEFAULT_GIT_PROTOCOL_VERSION_FETCH, TCP_GIT_PORT, Protocol
 from dulwich.repo import MemoryRepo, Repo
 from dulwich.tests.utils import open_repo, setup_warning_catcher, tear_down_repo
 
@@ -1539,8 +1539,13 @@ class SubprocessSSHVendorTests(TestCase):
             "2200",
             "-i",
             "/tmp/id_rsa",
-            "-o",
-            "SetEnv GIT_PROTOCOL=version=2",
+        ]
+        if DEFAULT_GIT_PROTOCOL_VERSION_FETCH:
+            expected += [
+                "-o",
+                f"SetEnv GIT_PROTOCOL=version={DEFAULT_GIT_PROTOCOL_VERSION_FETCH}",
+            ]
+        expected += [
             "user@host",
             "git-clone-url",
         ]
@@ -1564,8 +1569,13 @@ class SubprocessSSHVendorTests(TestCase):
             "-o",
             "Option=Value",
             "-x",
-            "-o",
-            "SetEnv GIT_PROTOCOL=version=2",
+        ]
+        if DEFAULT_GIT_PROTOCOL_VERSION_FETCH:
+            expected += [
+                "-o",
+                f"SetEnv GIT_PROTOCOL=version={DEFAULT_GIT_PROTOCOL_VERSION_FETCH}",
+            ]
+        expected += [
             "host",
             "git-clone-url",
         ]