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

Commit 53c66f6

Browse files
author
Dave Barnow
committed
fix(bump): send changelog to stdout when dry-run is paired with changelog-to-stdout
Closes #538
1 parent dee73f0 commit 53c66f6

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

commitizen/commands/bump.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,6 @@ def __call__(self): # noqa: C901
180180
"The commits found are not elegible to be bumped"
181181
)
182182

183-
# Do not perform operations over files or git.
184-
if dry_run:
185-
raise DryRunExit()
186-
187-
bump.update_version_in_files(
188-
current_version,
189-
str(new_version),
190-
version_files,
191-
check_consistency=self.check_consistency,
192-
)
193-
194183
if self.changelog:
195184
if self.changelog_to_stdout:
196185
changelog_cmd = Changelog(
@@ -216,6 +205,17 @@ def __call__(self): # noqa: C901
216205
changelog_cmd()
217206
c = cmd.run(f"git add {changelog_cmd.file_name} {' '.join(version_files)}")
218207

208+
# Do not perform operations over files or git.
209+
if dry_run:
210+
raise DryRunExit()
211+
212+
bump.update_version_in_files(
213+
current_version,
214+
str(new_version),
215+
version_files,
216+
check_consistency=self.check_consistency,
217+
)
218+
219219
self.config.set_key("version", str(new_version))
220220

221221
if is_files_only:

tests/commands/test_bump_command.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,21 @@ def test_bump_with_changelog_to_stdout_arg(mocker, capsys, changelog_path):
500500
out = f.read()
501501
assert out.startswith("#")
502502
assert "0.2.0" in out
503+
504+
505+
@pytest.mark.usefixtures("tmp_commitizen_project")
506+
def test_bump_with_changelog_to_stdout_dry_run_arg(mocker, capsys, changelog_path):
507+
create_file_and_commit(
508+
"feat(user): this should appear in stdout with dry-run enabled"
509+
)
510+
testargs = ["cz", "bump", "--yes", "--changelog-to-stdout", "--dry-run"]
511+
mocker.patch.object(sys, "argv", testargs)
512+
with pytest.raises(DryRunExit):
513+
cli.main()
514+
out, _ = capsys.readouterr()
515+
516+
tag_exists = git.tag_exist("0.2.0")
517+
assert tag_exists is False
518+
assert out.startswith("#")
519+
assert "this should appear in stdout with dry-run enabled" in out
520+
assert "0.2.0" in out

0 commit comments

Comments
 (0)