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

fix: prevent prerelase from creating a bump when there are no commits #307

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 21, 2020
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
14 changes: 14 additions & 0 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ def __call__(self): # noqa: C901
if increment is None:
increment = self.find_increment(commits)

# It may happen that there are commits, but they are not elegible
# for an increment, this generates a problem when using prerelease (#281)
if (
prerelease
and increment is None
and not current_version_instance.is_prerelease
):
raise NoCommitsFoundError(
"[NO_COMMITS_FOUND]\n"
"No commits found to generate a pre-release.\n"
"To avoid this error, manually specify the type of increment with `--increment`"
)

# Increment is removed when current and next version
# are expected to be prereleases.
if prerelease and current_version_instance.is_prerelease:
Expand All @@ -123,6 +136,7 @@ def __call__(self): # noqa: C901
prerelease=prerelease,
is_local_version=is_local_version,
)

new_tag_version = bump.create_tag(new_version, tag_format=tag_format)
message = bump.create_commit_message(
current_version, new_version, bump_commit_message
Expand Down
26 changes: 26 additions & 0 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,29 @@ def test_bump_with_changelog_config(mocker, changelog_path, config_path):
out = f.read()
assert out.startswith("#")
assert "0.2.0" in out


def test_prevent_prerelease_when_no_increment_detected(
mocker, capsys, tmp_commitizen_project
):
create_file_and_commit("feat: new file")

testargs = ["cz", "bump", "--yes"]
mocker.patch.object(sys, "argv", testargs)

cli.main()
out, _ = capsys.readouterr()

assert "0.2.0" in out

create_file_and_commit("test: new file")
testargs = ["cz", "bump", "-pr", "beta"]
mocker.patch.object(sys, "argv", testargs)

with pytest.raises(NoCommitsFoundError) as excinfo:
cli.main()

expected_error_message = (
"[NO_COMMITS_FOUND]\n" "No commits found to generate a pre-release."
)
assert expected_error_message in str(excinfo.value)