Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

fix(bump): send changelog to stdout when dry-run is paired with changelog-to-stdout #539

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
Jul 27, 2022
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
22 changes: 11 additions & 11 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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