Skip to content

Commit f74b9af

Browse files
committed
fix(commit): resolve 'always_signoff' configuration and '-s' CLI issues
If 'always_signoff' is enabled in configurations, or '-s' is used alone on the CLI, the following errors arise due to 'git commit' argument failures : > signoff mechanic is deprecated, please use `cz commit -- -s` instead. > fatal: /tmp/...: '/tmp/... is outside repository at '...' Signed-off-by: Adrian DC <[email protected]>
1 parent 01fd042 commit f74b9af

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

commitizen/commands/commit.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ def __call__(self):
114114
self.arguments.get("signoff") or self.config.settings["always_signoff"]
115115
)
116116

117+
extra_args = self.arguments.get("extra_cli_args", "")
118+
117119
if signoff:
118120
out.warn(
119121
"signoff mechanic is deprecated, please use `cz commit -- -s` instead."
120122
)
121-
extra_args = self.arguments.get("extra_cli_args", "--") + " -s"
122-
else:
123-
extra_args = self.arguments.get("extra_cli_args", "")
123+
if extra_args:
124+
extra_args += " "
125+
extra_args += "-s"
124126

125127
c = git.commit(m, args=extra_args)
126128

tests/commands/test_commit_command.py

+27-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_commit_command_with_signoff_option(config, mocker: MockFixture):
260260

261261
commands.Commit(config, {"signoff": True})()
262262

263-
commit_mock.assert_called_once_with(ANY, args="-- -s")
263+
commit_mock.assert_called_once_with(ANY, args="-s")
264264
success_mock.assert_called_once()
265265

266266

@@ -283,7 +283,32 @@ def test_commit_command_with_always_signoff_enabled(config, mocker: MockFixture)
283283
config.settings["always_signoff"] = True
284284
commands.Commit(config, {})()
285285

286-
commit_mock.assert_called_once_with(ANY, args="-- -s")
286+
commit_mock.assert_called_once_with(ANY, args="-s")
287+
success_mock.assert_called_once()
288+
289+
290+
@pytest.mark.usefixtures("staging_is_clean")
291+
def test_commit_command_with_gpgsign_and_always_signoff_enabled(
292+
config, mocker: MockFixture
293+
):
294+
prompt_mock = mocker.patch("questionary.prompt")
295+
prompt_mock.return_value = {
296+
"prefix": "feat",
297+
"subject": "user created",
298+
"scope": "",
299+
"is_breaking_change": False,
300+
"body": "",
301+
"footer": "",
302+
}
303+
304+
commit_mock = mocker.patch("commitizen.git.commit")
305+
commit_mock.return_value = cmd.Command("success", "", b"", b"", 0)
306+
success_mock = mocker.patch("commitizen.out.success")
307+
308+
config.settings["always_signoff"] = True
309+
commands.Commit(config, {"extra_cli_args": "-S"})()
310+
311+
commit_mock.assert_called_once_with(ANY, args="-S -s")
287312
success_mock.assert_called_once()
288313

289314

0 commit comments

Comments
 (0)