Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shows deprecated warning before prompt questions #1146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
32 changes: 15 additions & 17 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Comment on lines +81 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a default value to these get?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, we can add a explicit default value but .get has a default value to None if not specified.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but None is not a bool, False would be better 🙂

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use f-string here

else:
extra_args = self.arguments.get("extra_cli_args", "")

if is_all:
c = git.add("-u")

Expand All @@ -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:
Expand All @@ -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:
Expand Down
44 changes: 44 additions & 0 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
signoff mechanic is deprecated, please use `cz commit -- -s` instead.

Loading