Skip to content

Commit 6441de4

Browse files
committed
vcs(fix): Forward global command options correctly
1 parent 0f3ece0 commit 6441de4

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎src/libvcs/cmd/hg.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def run(
164164
>>> hg.run(['help'])
165165
"Mercurial Distributed SCM..."
166166
"""
167-
cli_args: list[StrOrBytesPath] = ["hg", *_normalize_command_args(args)]
167+
cli_args: list[StrOrBytesPath] = ["hg"]
168168

169169
if "cwd" not in kwargs:
170170
kwargs["cwd"] = self.path
@@ -196,6 +196,8 @@ def run(
196196
if _help is True:
197197
cli_args.append("--help")
198198

199+
cli_args.extend(_normalize_command_args(args))
200+
199201
if self.progress_callback is not None:
200202
kwargs["callback"] = self.progress_callback
201203

‎src/libvcs/cmd/svn.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ def run(
144144
if "cwd" not in kwargs:
145145
kwargs["cwd"] = self.path
146146

147+
if quiet is True:
148+
cli_args.append("--quiet")
147149
if no_auth_cache is True:
148150
cli_args.append("--no-auth-cache")
149151
if non_interactive is True:
@@ -153,7 +155,7 @@ def run(
153155
if password is not None:
154156
cli_args.extend(["--password", password])
155157
if trust_server_cert is True:
156-
cli_args.append("--trust-server_cert")
158+
cli_args.append("--trust-server-cert")
157159
if config_dir is not None:
158160
cli_args.extend(["--config-dir", os.fspath(config_dir)])
159161
if config_option is not None:

‎tests/cmd/test_hg.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@
1717
pytestmark = pytest.mark.skip(reason="hg is not available")
1818

1919

20+
def test_hg_run_keeps_global_options_before_separator(
21+
tmp_path: pathlib.Path,
22+
mocker: MockerFixture,
23+
) -> None:
24+
"""Mercurial global options precede command operands and their separator."""
25+
repo = Hg(path=tmp_path)
26+
mock_run = mocker.patch("libvcs.cmd.hg.run", return_value="")
27+
28+
repo.run(["clone", "--", "source", "destination"], quiet=True)
29+
30+
assert mock_run.call_args.kwargs["args"] == [
31+
"hg",
32+
"--quiet",
33+
"clone",
34+
"--",
35+
"source",
36+
"destination",
37+
]
38+
39+
2040
def test_hg_run_accepts_scalar_string(tmp_path: pathlib.Path) -> None:
2141
"""Mercurial run() should not split scalar command strings."""
2242
repo = Hg(path=tmp_path)

‎tests/cmd/test_svn.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,27 @@ def test_svn_run_timeout_propagates_to_runner(
5151
assert kwargs.get("timeout") == 2.5
5252

5353

54+
def test_svn_run_forwards_quiet_and_trust_cert_with_native_spelling(
55+
tmp_path: pathlib.Path,
56+
mocker: MockerFixture,
57+
) -> None:
58+
"""Global checkout options use the argv accepted by Subversion."""
59+
repo = Svn(path=tmp_path)
60+
mock_run = mocker.patch("libvcs.cmd.svn.run", return_value="")
61+
62+
repo.run(["info", "--", "."], quiet=True, trust_server_cert=True)
63+
64+
assert mock_run.call_args.kwargs["args"] == [
65+
"svn",
66+
"--quiet",
67+
"--non-interactive",
68+
"--trust-server-cert",
69+
"info",
70+
"--",
71+
".",
72+
]
73+
74+
5475
def test_checkout_rejects_option_like_url(tmp_path: pathlib.Path) -> None:
5576
"""Reject a checkout URL that svn would parse as an option.
5677

0 commit comments

Comments
 (0)