Skip to content

Commit e2c6e0c

Browse files
authored
Merge pull request #75 from Woile/56-dry-run
fix: commit dry-run doesnt require staging to be clean
2 parents 83a1de6 + 425197a commit e2c6e0c

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

commitizen/commands/commit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ def prompt_commit_questions(self) -> str:
5151
return cz.message(answers)
5252

5353
def __call__(self):
54-
if git.is_staging_clean():
54+
dry_run: bool = self.arguments.get("dry_run")
55+
56+
if git.is_staging_clean() and not dry_run:
5557
out.write("No files added to staging!")
5658
raise SystemExit(NOTHING_TO_COMMIT)
5759

@@ -64,8 +66,6 @@ def __call__(self):
6466

6567
out.info(f"\n{m}\n")
6668

67-
dry_run: bool = self.arguments.get("dry_run")
68-
6969
if dry_run:
7070
raise SystemExit(NOTHING_TO_COMMIT)
7171

tests/test_commands.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ def test_commit_when_nothing_to_commit(mocker):
110110
assert err.value.code == commands.commit.NOTHING_TO_COMMIT
111111

112112

113+
@pytest.mark.usefixtures("staging_is_clean")
113114
def test_commit_when_customized_expected_raised(mocker, capsys):
114115
_err = ValueError()
115116
_err.__context__ = CzException("This is the root custom err")
116-
git_mock = mocker.patch("commitizen.git.is_staging_clean")
117-
git_mock.return_value = False
118117
prompt_mock = mocker.patch("questionary.prompt")
119118
prompt_mock.side_effect = _err
120119

0 commit comments

Comments
 (0)