Skip to content

Commit 08d86ad

Browse files
committed
fix(cli): prints deprecated warning after prompt questions when cz commit -s
It's a bad dev experience getting warning/failures after all questions answered.
1 parent 8cc46cd commit 08d86ad

4 files changed

+61
-17
lines changed

commitizen/commands/commit.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,24 @@ def prompt_commit_questions(self) -> str:
7373
return message
7474

7575
def __call__(self):
76+
signoff: bool = (
77+
self.arguments.get("signoff") or self.config.settings["always_signoff"]
78+
)
7679
dry_run: bool = self.arguments.get("dry_run")
7780
write_message_to_file: bool = self.arguments.get("write_message_to_file")
78-
81+
retry: bool = self.arguments.get("retry")
82+
no_retry: bool = self.arguments.get("no_retry")
83+
retry_after_failure: bool = self.config.settings.get("retry_after_failure")
7984
is_all: bool = self.arguments.get("all")
85+
86+
if signoff:
87+
out.warn(
88+
"signoff mechanic is deprecated, please use `cz commit -- -s` instead.\n"
89+
)
90+
extra_args = self.arguments.get("extra_cli_args", "--") + " -s"
91+
else:
92+
extra_args = self.arguments.get("extra_cli_args", "")
93+
8094
if is_all:
8195
c = git.add("-u")
8296

@@ -86,10 +100,6 @@ def __call__(self):
86100
if write_message_to_file is not None and write_message_to_file.is_dir():
87101
raise NotAllowed(f"{write_message_to_file} is a directory")
88102

89-
retry: bool = self.arguments.get("retry")
90-
no_retry: bool = self.arguments.get("no_retry")
91-
retry_after_failure: bool = self.config.settings.get("retry_after_failure")
92-
93103
if retry:
94104
m = self.read_backup_message()
95105
if m is None:
@@ -110,18 +120,6 @@ def __call__(self):
110120
if dry_run:
111121
raise DryRunExit()
112122

113-
signoff: bool = (
114-
self.arguments.get("signoff") or self.config.settings["always_signoff"]
115-
)
116-
117-
if signoff:
118-
out.warn(
119-
"signoff mechanic is deprecated, please use `cz commit -- -s` instead."
120-
)
121-
extra_args = self.arguments.get("extra_cli_args", "--") + " -s"
122-
else:
123-
extra_args = self.arguments.get("extra_cli_args", "")
124-
125123
c = git.commit(m, args=extra_args)
126124

127125
if c.return_code != 0:

tests/commands/test_commit_command.py

+44
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,50 @@ def test_commit_command_with_always_signoff_enabled(config, mocker: MockFixture)
287287
success_mock.assert_called_once()
288288

289289

290+
@pytest.mark.usefixtures("staging_is_clean")
291+
def test_commit_command_with_signoff_option_prints_deprecated_warning(
292+
config, mocker: MockFixture, capsys, file_regression
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+
commands.Commit(config, {"signoff": True})()
307+
308+
_, err = capsys.readouterr()
309+
file_regression.check(err, extension=".txt")
310+
311+
312+
@pytest.mark.usefixtures("staging_is_clean")
313+
def test_commit_command_without_signoff_option_dont_prints_deprecated_warning(
314+
config, mocker: MockFixture, capsys, file_regression
315+
):
316+
prompt_mock = mocker.patch("questionary.prompt")
317+
prompt_mock.return_value = {
318+
"prefix": "feat",
319+
"subject": "user created",
320+
"scope": "",
321+
"is_breaking_change": False,
322+
"body": "",
323+
"footer": "",
324+
}
325+
326+
commit_mock = mocker.patch("commitizen.git.commit")
327+
commit_mock.return_value = cmd.Command("success", "", b"", b"", 0)
328+
commands.Commit(config, {"signoff": False})()
329+
330+
_, err = capsys.readouterr()
331+
file_regression.check(err, extension=".txt")
332+
333+
290334
@pytest.mark.usefixtures("tmp_git_project")
291335
def test_commit_when_nothing_to_commit(config, mocker: MockFixture):
292336
is_staging_clean_mock = mocker.patch("commitizen.git.is_staging_clean")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
signoff mechanic is deprecated, please use `cz commit -- -s` instead.
2+

tests/commands/test_commit_command/test_commit_command_without_signoff_option_dont_prints_deprecated_warning.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)