diff --git a/commitizen/cli.py b/commitizen/cli.py index 1d1ebe1f68..4bc38d7a11 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -149,7 +149,7 @@ def __call__( { "name": ["-s", "--signoff"], "action": "store_true", - "help": "sign off the commit", + "help": "sign off the commit (deprecated: use `cz commit -- -s` instead)", }, { "name": ["-a", "--all"], diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index 0816b2e508..1aecacc4dc 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -73,10 +73,24 @@ def prompt_commit_questions(self) -> str: return message def __call__(self): + signoff: bool = ( + self.arguments.get("signoff") or self.config.settings["always_signoff"] + ) dry_run: bool = self.arguments.get("dry_run") write_message_to_file: bool = self.arguments.get("write_message_to_file") - + retry: bool = self.arguments.get("retry") + no_retry: bool = self.arguments.get("no_retry") + retry_after_failure: bool = self.config.settings.get("retry_after_failure") is_all: bool = self.arguments.get("all") + + if signoff: + out.warn( + "signoff mechanic is deprecated, please use `cz commit -- -s` instead.\n" + ) + extra_args = self.arguments.get("extra_cli_args", "--") + " -s" + else: + extra_args = self.arguments.get("extra_cli_args", "") + if is_all: c = git.add("-u") @@ -86,10 +100,6 @@ def __call__(self): if write_message_to_file is not None and write_message_to_file.is_dir(): raise NotAllowed(f"{write_message_to_file} is a directory") - retry: bool = self.arguments.get("retry") - no_retry: bool = self.arguments.get("no_retry") - retry_after_failure: bool = self.config.settings.get("retry_after_failure") - if retry: m = self.read_backup_message() if m is None: @@ -110,18 +120,6 @@ def __call__(self): if dry_run: raise DryRunExit() - signoff: bool = ( - self.arguments.get("signoff") or self.config.settings["always_signoff"] - ) - - if signoff: - out.warn( - "signoff mechanic is deprecated, please use `cz commit -- -s` instead." - ) - extra_args = self.arguments.get("extra_cli_args", "--") + " -s" - else: - extra_args = self.arguments.get("extra_cli_args", "") - c = git.commit(m, args=extra_args) if c.return_code != 0: diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 8ae7568a9d..a19d35b3a9 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -287,6 +287,50 @@ def test_commit_command_with_always_signoff_enabled(config, mocker: MockFixture) success_mock.assert_called_once() +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_command_with_signoff_option_prints_deprecated_warning( + config, mocker: MockFixture, capsys, file_regression +): + prompt_mock = mocker.patch("questionary.prompt") + prompt_mock.return_value = { + "prefix": "feat", + "subject": "user created", + "scope": "", + "is_breaking_change": False, + "body": "", + "footer": "", + } + + commit_mock = mocker.patch("commitizen.git.commit") + commit_mock.return_value = cmd.Command("success", "", b"", b"", 0) + commands.Commit(config, {"signoff": True})() + + _, err = capsys.readouterr() + file_regression.check(err, extension=".txt") + + +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_command_without_signoff_option_dont_prints_deprecated_warning( + config, mocker: MockFixture, capsys, file_regression +): + prompt_mock = mocker.patch("questionary.prompt") + prompt_mock.return_value = { + "prefix": "feat", + "subject": "user created", + "scope": "", + "is_breaking_change": False, + "body": "", + "footer": "", + } + + commit_mock = mocker.patch("commitizen.git.commit") + commit_mock.return_value = cmd.Command("success", "", b"", b"", 0) + commands.Commit(config, {"signoff": False})() + + _, err = capsys.readouterr() + file_regression.check(err, extension=".txt") + + @pytest.mark.usefixtures("tmp_git_project") def test_commit_when_nothing_to_commit(config, mocker: MockFixture): is_staging_clean_mock = mocker.patch("commitizen.git.is_staging_clean") diff --git a/tests/commands/test_commit_command/test_commit_command_shows_description_when_use_help_option.txt b/tests/commands/test_commit_command/test_commit_command_shows_description_when_use_help_option.txt index ebdb68446e..d1c7fcd7f0 100644 --- a/tests/commands/test_commit_command/test_commit_command_shows_description_when_use_help_option.txt +++ b/tests/commands/test_commit_command/test_commit_command_shows_description_when_use_help_option.txt @@ -12,7 +12,8 @@ options: --write-message-to-file FILE_PATH write message to file before committing (can be combined with --dry-run) - -s, --signoff sign off the commit + -s, --signoff sign off the commit (deprecated: use `cz commit -- -s` + instead) -a, --all Tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected. diff --git a/tests/commands/test_commit_command/test_commit_command_with_signoff_option_prints_deprecated_warning.txt b/tests/commands/test_commit_command/test_commit_command_with_signoff_option_prints_deprecated_warning.txt new file mode 100644 index 0000000000..96fdb806c3 --- /dev/null +++ b/tests/commands/test_commit_command/test_commit_command_with_signoff_option_prints_deprecated_warning.txt @@ -0,0 +1,2 @@ +signoff mechanic is deprecated, please use `cz commit -- -s` instead. + diff --git a/tests/commands/test_commit_command/test_commit_command_without_signoff_option_dont_prints_deprecated_warning.txt b/tests/commands/test_commit_command/test_commit_command_without_signoff_option_dont_prints_deprecated_warning.txt new file mode 100644 index 0000000000..e69de29bb2