Skip to content

Commit 9b8b268

Browse files
SCrockyLee-W
SCrocky
authored andcommitted
refactor: Code Review - round 1 changes
1 parent 644708d commit 9b8b268

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
@@ -465,6 +465,11 @@ def main():
465465
raise InvalidCommandArgumentError(
466466
f"Invalid commitizen arguments were found before -- separator: `{' '.join(unknown_args[:pos])}`. "
467467
)
468+
# Log warning for -- without any extra args
469+
elif len(unknown_args) == 1:
470+
logger.warning(
471+
"Incomplete commit command: received -- separator without any following git arguments"
472+
)
468473
extra_args = " ".join(unknown_args[1:])
469474
arguments["extra_cli_args"] = extra_args
470475

commitizen/commands/commit.py

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

100100
if signoff:
101101
out.warn("signoff mechanic is deprecated, please use `cz commit -- -s` instead.")
102-
c = git.commit(m, "-s")
103-
104-
if self.arguments.get("extra_cli_args"):
105-
c = git.commit(m, extra_args=self.arguments.get("extra_cli_args"))
102+
extra_args = "-s " + self.arguments.get("extra_cli_args")
106103
else:
107-
c = git.commit(m)
104+
extra_args = self.arguments.get("extra_cli_args")
105+
106+
c = git.commit(m, extra_args=extra_args)
108107

109108
if c.return_code != 0:
110109
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)