Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8df5c94

Browse files
author
Scrocky
committed
refactor(extra_args): Fixed broken code due to rebase and finalized tests
1 parent 0abb01e commit 8df5c94

File tree

7 files changed

+42
-35
lines changed

7 files changed

+42
-35
lines changed

‎commitizen/commands/commit.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ def __call__(self):
9898
)
9999

100100
if signoff:
101-
out.warn("signoff mechanic is deprecated, please use `cz commit -- -s` instead.")
102-
extra_args = "-s " + self.arguments.get("extra_cli_args")
101+
out.warn(
102+
"signoff mechanic is deprecated, please use `cz commit -- -s` instead."
103+
)
104+
extra_args = self.arguments.get("extra_cli_args", "--") + " -s"
103105
else:
104-
extra_args = self.arguments.get("extra_cli_args")
106+
extra_args = self.arguments.get("extra_cli_args", "")
105107

106108
c = git.commit(m, extra_args=extra_args)
107109

‎commitizen/git.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,16 @@ def add(args: str = "") -> cmd.Command:
9898

9999

100100
def commit(
101-
message: str, args: str = "", extra_args: str = "", committer_date: str | None = None
101+
message: str,
102+
args: str = "",
103+
extra_args: str = "",
104+
committer_date: str | None = None,
102105
) -> cmd.Command:
103106
f = NamedTemporaryFile("wb", delete=False)
104107
f.write(message.encode("utf-8"))
105108
f.close()
106109

107-
command = cmd.run(f"git commit {args} {extra_args} -F {f.name}")
110+
command = f"git commit {args} {extra_args} -F {f.name}"
108111

109112
if committer_date and os.name == "nt": # pragma: no cover
110113
# Using `cmd /v /c "{command}"` sets environment variables only for that command

‎docs/bump.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ These are used in:
323323
324324
* `cz bump`: Find previous release tag (exact match) and generate new tag.
325325
* Find previous release tags in `cz changelog`.
326-
* If `--incremental`: Using latest version found in the changelog, scan existing Git tags with 89\% similarity match.
326+
* If `--incremental`: Using latest version found in the changelog, scan existing Git tags with 89\% similarity match.
327327
* `--rev-range` is converted to Git tag names with `tag_format` before searching Git history.
328328
* If the `scm` `version_provider` is used, it uses different regexes to find the previous version tags:
329329
* If `tag_format` is set to `$version` (default): `VersionProtocol.parser` (allows `v` prefix)

‎docs/commit.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ For example, using the `-S` option on `git commit` to sign a commit is now commi
2828

2929
!!! note
3030
Deprecation warning: A commit can be signed off using `cz commit --signoff` or the shortcut `cz commit -s`.
31-
This syntax is now deprecated in favor of the new `cz commit -- -s` syntax.
31+
This syntax is now deprecated in favor of the new `cz commit -- -s` syntax.

‎tests/commands/test_commit_command.py‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_commit_retry_works(config, mocker: MockFixture):
8888

8989
commands.Commit(config, {"retry": True})()
9090

91-
commit_mock.assert_called_with("feat: user created\n\ncloses #21")
91+
commit_mock.assert_called_with("feat: user created\n\ncloses #21", extra_args="")
9292
prompt_mock.assert_called_once()
9393
success_mock.assert_called_once()
9494
assert not os.path.isfile(temp_file)
@@ -174,7 +174,7 @@ def test_commit_command_with_signoff_option(config, mocker: MockFixture):
174174

175175
commands.Commit(config, {"signoff": True})()
176176

177-
commit_mock.assert_called_once_with(ANY, "-s")
177+
commit_mock.assert_called_once_with(ANY, extra_args="-- -s")
178178
success_mock.assert_called_once()
179179

180180

@@ -197,7 +197,7 @@ def test_commit_command_with_always_signoff_enabled(config, mocker: MockFixture)
197197
config.settings["always_signoff"] = True
198198
commands.Commit(config, {})()
199199

200-
commit_mock.assert_called_once_with(ANY, "-s")
200+
commit_mock.assert_called_once_with(ANY, extra_args="-- -s")
201201
success_mock.assert_called_once()
202202

203203

@@ -276,3 +276,23 @@ def test_commit_command_with_all_option(config, mocker: MockFixture):
276276
commands.Commit(config, {"all": True})()
277277
add_mock.assert_called()
278278
success_mock.assert_called_once()
279+
280+
281+
@pytest.mark.usefixtures("staging_is_clean")
282+
def test_commit_command_with_extra_args(config, mocker: MockFixture):
283+
prompt_mock = mocker.patch("questionary.prompt")
284+
prompt_mock.return_value = {
285+
"prefix": "feat",
286+
"subject": "user created",
287+
"scope": "",
288+
"is_breaking_change": False,
289+
"body": "",
290+
"footer": "",
291+
}
292+
293+
commit_mock = mocker.patch("commitizen.git.commit")
294+
commit_mock.return_value = cmd.Command("success", "", b"", b"", 0)
295+
success_mock = mocker.patch("commitizen.out.success")
296+
commands.Commit(config, {"extra_cli_args": "-- -extra-args1 -extra-arg2"})()
297+
commit_mock.assert_called_once_with(ANY, extra_args="-- -extra-args1 -extra-arg2")
298+
success_mock.assert_called_once()

‎tests/test_cli.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
from commitizen import cli
1010
from commitizen.exceptions import (
11-
ExpectedExit, NoCommandFoundError, NotAGitProjectError, InvalidCommandArgumentError, NothingToCommitError
11+
ExpectedExit,
12+
NoCommandFoundError,
13+
NotAGitProjectError,
14+
InvalidCommandArgumentError,
1215
)
1316

1417

@@ -166,5 +169,6 @@ def test_unknown_args_before_double_dash_raises(mocker: MockFixture):
166169
mocker.patch.object(sys, "argv", testargs)
167170
with pytest.raises(InvalidCommandArgumentError) as excinfo:
168171
cli.main()
169-
assert "Invalid commitizen arguments were found before -- separator" in str(excinfo.value)
170-
172+
assert "Invalid commitizen arguments were found before -- separator" in str(
173+
excinfo.value
174+
)

‎tests/test_command_commit.py‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /