Skip to content

fix: commit dry-run doesnt require staging to be clean #75

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

Merged
merged 1 commit into from
Nov 19, 2019
Merged
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
6 changes: 3 additions & 3 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down