diff --git a/commitizen/cli.py b/commitizen/cli.py index 264bddb2f..921424114 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -66,6 +66,11 @@ "action": "store_true", "help": "Sign off the commit", }, + { + "name": "--allow-empty", + "action": "store_true", + "help": "Allow to create commit on an empty staging", + }, ], }, { diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index 79aec74de..376850d61 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -62,10 +62,14 @@ def prompt_commit_questions(self) -> str: return cz.message(answers) def __call__(self): - dry_run: bool = self.arguments.get("dry_run") - + args = [] allow_empty: bool = self.arguments.get("allow_empty") + if allow_empty: + args.append("--allow-empty") + + dry_run: bool = self.arguments.get("dry_run") + if git.is_staging_clean() and not (dry_run or allow_empty): raise NothingToCommitError("No files added to staging!") @@ -84,9 +88,9 @@ def __call__(self): signoff: bool = self.arguments.get("signoff") if signoff: - c = git.commit(m, "-s") - else: - c = git.commit(m) + args.append("-s") + + c = git.commit(m, *args) 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 4f9b295cc..8544833c8 100644 --- a/tests/commands/test_commit_command.py +++ b/tests/commands/test_commit_command.py @@ -38,7 +38,7 @@ def test_commit(config, mocker): success_mock = mocker.patch("commitizen.out.success") commands.Commit(config, {})() - success_mock.assert_called_once() + success_mock.assert_called_once() @pytest.mark.usefixtures("staging_is_clean")