Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add initial support for Git protocol v2 #1244

Merged
merged 12 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
don't hard-code protocol v2 and tweak version comparisons to be futur…
…e-proof

Based on a suggestion by Jelmer
  • Loading branch information
stspdotname committed Jun 25, 2024
commit 5c1a5ecedb1d272dc7121f5cb7fa191b040f929d
12 changes: 8 additions & 4 deletions dulwich/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,8 +1923,10 @@ def run_command(
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}"
Expand Down Expand Up @@ -1992,8 +1994,10 @@ def run_command(
# 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],
Expand Down
6 changes: 4 additions & 2 deletions tests/compat/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,10 @@ def run_command(
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],
Expand Down
20 changes: 15 additions & 5 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
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

Expand Down Expand Up @@ -1539,8 +1539,13 @@ def test_run_command_with_port_username_and_privkey(self):
"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",
]
Expand All @@ -1564,8 +1569,13 @@ def test_run_with_ssh_command(self):
"-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",
]
Expand Down