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 3d8d27c

Browse files
author
SCrocky
committed
refactor: Code Review - round 1 changes
1 parent b3d2bbf commit 3d8d27c

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

‎commitizen/cli.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ def main():
434434
raise InvalidCommandArgumentError(
435435
f"Invalid commitizen arguments were found before -- separator: `{' '.join(unknown_args[:pos])}`. "
436436
)
437+
# Log warning for -- without any extra args
438+
elif len(unknown_args) == 1:
439+
logger.warning(
440+
"Incomplete commit command: received -- separator without any following git arguments"
441+
)
437442
extra_args = " ".join(unknown_args[1:])
438443
arguments["extra_cli_args"] = extra_args
439444

‎commitizen/commands/commit.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,11 @@ def __call__(self):
9292

9393
if signoff:
9494
out.warn("signoff mechanic is deprecated, please use `cz commit -- -s` instead.")
95-
c = git.commit(m, "-s")
96-
97-
if self.arguments.get("extra_cli_args"):
98-
c = git.commit(m, extra_args=self.arguments.get("extra_cli_args"))
95+
extra_args = "-s " + self.arguments.get("extra_cli_args")
9996
else:
100-
c = git.commit(m)
97+
extra_args = self.arguments.get("extra_cli_args")
98+
99+
c = git.commit(m, extra_args=extra_args)
101100

102101
if c.return_code != 0:
103102
out.error(c.err)

‎docs/commit.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ case for this is to [automatically prepare a commit message](./tutorials/auto_pr
1919

2020
`git` command options that are not implemented by commitizen can be use via the `--` syntax for the `commit` command.
2121
The syntax separates commitizen arguments from `git commit` arguments by a double dash. This is the resulting syntax:
22-
```
23-
cz commit -commitizen-args -- -git-cli-args
22+
```sh
23+
cz commit <commitizen-args> -- <git-cli-args>
24+
25+
# e.g., cz commit --dry-run -- -a -S
2426
```
2527
For example, using the `-S` option on `git commit` to sign a commit is now commitizen compatible: `cz c -- -S`
2628

‎tests/test_cli.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,4 @@ def test_unknown_args_before_double_dash_raises(mocker: MockFixture):
167167
with pytest.raises(InvalidCommandArgumentError) as excinfo:
168168
cli.main()
169169
assert "Invalid commitizen arguments were found before -- separator" in str(excinfo.value)
170+

‎tests/test_command_commit.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
3+
from unittest.mock import patch
4+
from pytest_mock import MockFixture
5+
6+
from commitizen import cli
7+
from commitizen.commands.commit import Commit
8+
9+
10+
def test_extra_args_no_raise(mocker: MockFixture):
11+
testargs = ["cz", "c", "--dry-run", "--", "-extra-args1", "-extra-arg2"]
12+
extra_cli_args = "-extra-args1 -extra-args2"
13+
mocker.patch.object(sys, "argv", testargs)
14+
commit_call = mocker.patch.object(Commit, "__call__")
15+
16+
def assert_extra_args(self):
17+
assert self.arguments["extra_cli_args"] == extra_cli_args
18+
19+
with patch.object(Commit, "test_extra_args", assert_extra_args, autospec=True) as mock:
20+
commit_call.side_effect = Commit.test_extra_args
21+
cli.main()
22+
Commit.__call__.assert_called_once()

0 commit comments

Comments
(0)

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