From 7b7b0c97a3371ea105833b5862592a45d02d6d51 Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Wed, 29 Sep 2021 18:37:54 +0200 Subject: [PATCH 1/2] feat: add signoff parameter to commit command command to sign off the commit, equivalent to git commit -s --- commitizen/cli.py | 5 +++++ commitizen/commands/commit.py | 7 ++++++- tests/commands/test_commit_command.py | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index e1bad367e7..215d8faf82 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -49,6 +49,11 @@ "action": "store_true", "help": "show output to stdout, no commit, no modified files", }, + { + "name": "--signoff", + "action": "store_true", + "help": "Sign off the commit", + }, ], }, { diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index bad47dd572..a4c0301732 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -78,7 +78,12 @@ def __call__(self): if dry_run: raise DryRunExit() - c = git.commit(m) + signoff: bool = self.arguments.get("signoff") + + if signoff: + c = git.commit(m, "-s") + else: + c = git.commit(m) if c.return_code != 0: out.error(c.err) diff --git a/tests/commands/test_commit_command.py b/tests/commands/test_commit_command.py index 7d56f08752..8544833c8f 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -107,6 +107,26 @@ def test_commit_command_with_dry_run_option(config, mocker): commit_cmd() +@pytest.mark.usefixtures("staging_is_clean") +def test_commit_command_with_signoff_option(config, mocker): + 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", "", "", "", 0) + success_mock = mocker.patch("commitizen.out.success") + + commands.Commit(config, {"signoff": True})() + success_mock.assert_called_once() + + def test_commit_when_nothing_to_commit(config, mocker): is_staging_clean_mock = mocker.patch("commitizen.git.is_staging_clean") is_staging_clean_mock.return_value = True From 5e220401f510f394129b5d2f11c6a987229c92de Mon Sep 17 00:00:00 2001 From: Angelo Mantellini Date: Wed, 6 Oct 2021 20:10:37 +0200 Subject: [PATCH 2/2] feat(cli.py): add shortcut for signoff command add -s shortcut for the --signoff command --- commitizen/cli.py | 2 +- docs/README.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 215d8faf82..d582a27a18 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -50,7 +50,7 @@ "help": "show output to stdout, no commit, no modified files", }, { - "name": "--signoff", + "name": ["-s", "--signoff"], "action": "store_true", "help": "Sign off the commit", }, diff --git a/docs/README.md b/docs/README.md index f8482f4a69..f7c3127a9e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -86,6 +86,20 @@ or the shortcut cz c ``` +#### Sign off the commit + +Run in the terminal + +```bash +cz commit --signoff +``` + +or the shortcut + +```bash +cz commit -s +``` + ### Integrating with Pre-commit Commitizen can lint your commit message for you with `cz check`. You can integrate this in your [pre-commit](https://pre-commit.com/) config with: