Skip to content

Commit 26be522

Browse files
AdrianDCLee-W
authored andcommitted
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 d017869 commit 26be522

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

commitizen/commands/commit.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ def __call__(self):
138138
self.arguments.get("signoff") or self.config.settings["always_signoff"]
139139
)
140140

141+
extra_args = self.arguments.get("extra_cli_args", "")
142+
141143
if signoff:
142144
out.warn(
143145
"signoff mechanic is deprecated, please use `cz commit -- -s` instead."
144146
)
145-
extra_args = self.arguments.get("extra_cli_args", "--") + " -s"
146-
else:
147-
extra_args = self.arguments.get("extra_cli_args", "")
147+
extra_args = f"{extra_args} -s".strip()
148148

149149
c = git.commit(m, args=extra_args)
150150

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)