From 53c66f642d630dacb44fbeefd73e5d33f59d095f Mon Sep 17 00:00:00 2001 From: Dave Barnow Date: Tue, 26 Jul 2022 13:19:58 -0400 Subject: [PATCH] fix(bump): send changelog to stdout when `dry-run` is paired with `changelog-to-stdout` Closes #538 --- commitizen/commands/bump.py | 22 +++++++++++----------- tests/commands/test_bump_command.py | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 17f929bdb6..cbc5266dd8 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -180,17 +180,6 @@ def __call__(self): # noqa: C901 "The commits found are not elegible to be bumped" ) - # Do not perform operations over files or git. - if dry_run: - raise DryRunExit() - - bump.update_version_in_files( - current_version, - str(new_version), - version_files, - check_consistency=self.check_consistency, - ) - if self.changelog: if self.changelog_to_stdout: changelog_cmd = Changelog( @@ -216,6 +205,17 @@ def __call__(self): # noqa: C901 changelog_cmd() c = cmd.run(f"git add {changelog_cmd.file_name} {' '.join(version_files)}") + # Do not perform operations over files or git. + if dry_run: + raise DryRunExit() + + bump.update_version_in_files( + current_version, + str(new_version), + version_files, + check_consistency=self.check_consistency, + ) + self.config.set_key("version", str(new_version)) if is_files_only: diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index daf3d42bac..927a719010 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -500,3 +500,21 @@ def test_bump_with_changelog_to_stdout_arg(mocker, capsys, changelog_path): out = f.read() assert out.startswith("#") assert "0.2.0" in out + + +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_bump_with_changelog_to_stdout_dry_run_arg(mocker, capsys, changelog_path): + create_file_and_commit( + "feat(user): this should appear in stdout with dry-run enabled" + ) + testargs = ["cz", "bump", "--yes", "--changelog-to-stdout", "--dry-run"] + mocker.patch.object(sys, "argv", testargs) + with pytest.raises(DryRunExit): + cli.main() + out, _ = capsys.readouterr() + + tag_exists = git.tag_exist("0.2.0") + assert tag_exists is False + assert out.startswith("#") + assert "this should appear in stdout with dry-run enabled" in out + assert "0.2.0" in out