diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index c67a381f18..d67fe31c8c 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -51,7 +51,9 @@ def prompt_commit_questions(self) -> str: return cz.message(answers) def __call__(self): - if git.is_staging_clean(): + dry_run: bool = self.arguments.get("dry_run") + + if git.is_staging_clean() and not dry_run: out.write("No files added to staging!") raise SystemExit(NOTHING_TO_COMMIT) @@ -64,8 +66,6 @@ def __call__(self): out.info(f"\n{m}\n") - dry_run: bool = self.arguments.get("dry_run") - if dry_run: raise SystemExit(NOTHING_TO_COMMIT) diff --git a/tests/test_commands.py b/tests/test_commands.py index 3206d28002..dc2cfe0b0d 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -110,11 +110,10 @@ def test_commit_when_nothing_to_commit(mocker): assert err.value.code == commands.commit.NOTHING_TO_COMMIT +@pytest.mark.usefixtures("staging_is_clean") def test_commit_when_customized_expected_raised(mocker, capsys): _err = ValueError() _err.__context__ = CzException("This is the root custom err") - git_mock = mocker.patch("commitizen.git.is_staging_clean") - git_mock.return_value = False prompt_mock = mocker.patch("questionary.prompt") prompt_mock.side_effect = _err