Skip to content
Open
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
7 changes: 6 additions & 1 deletion commitizen/version_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
Increment: TypeAlias = Literal["MAJOR", "MINOR", "PATCH"] # TODO: deprecate
Prerelease: TypeAlias = Literal["alpha", "beta", "rc"]
_DEFAULT_VERSION_PARSER = re.compile(
r"v?(?P<version>([0-9]+)\.([0-9]+)(?:\.([0-9]+))?(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z.]+)?(\w+)?)"
r"v?(?P<version>(?:(?P<epoch>[0-9]+)!)?(?P<release>[0-9]+\.[0-9]+(?:\.[0-9]+)*)"
r"(?P<pre>[-_\.]?(?P<pre_l>a|b|c|rc|alpha|beta|pre|preview|next|dev)[-_\.]?(?P<pre_n>[0-9]+)?)?"
r"(?P<post>(?:-(?P<post_n1>[0-9]+))|(?:[-_\.]?(?P<post_l>post|rev|r)[-_\.]?(?P<post_n2>[0-9]+)?))?"
r"(?P<dev>[-_\.]?(?P<dev_l>dev)[-_\.]?(?P<dev_n>[0-9]+)?)?"
r"(?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))?)",
re.IGNORECASE,
)


Expand Down
32 changes: 32 additions & 0 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,38 @@ def test_changelog_incremental_with_prerelease_version_to_prerelease_version(
file_regression.check(out, extension=".md")


@pytest.mark.usefixtures("tmp_commitizen_project")
@pytest.mark.freeze_time("2021-06-11")
def test_changelog_incremental_with_devrelease(
changelog_path: Path,
file_regression: FileRegressionFixture,
util: UtilFixture,
):
"""Regression test for #1367: bumping with ``--devrelease`` twice must
update the incremental changelog.

The second devrelease bump used to fail with
"No tag found to do an incremental changelog" because the PEP 440
development-release tag (e.g. ``0.2.0.dev0``) was not recognised as a
version tag by the default version parser.
"""
util.create_file_and_commit("irrelevant commit")
util.create_tag("1.0.0", annotated=True)

util.create_file_and_commit("feat: add new output")
util.create_file_and_commit("fix: output glitch")

util.run_cli("bump", "--changelog", "--devrelease", "0", "--yes")

util.create_file_and_commit("feat: add more stuff")

util.run_cli("bump", "--changelog", "--devrelease", "1", "--yes")

out = changelog_path.read_text()

file_regression.check(out, extension=".md")


@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"])
@pytest.mark.usefixtures("tmp_commitizen_project")
@pytest.mark.freeze_time("2025-12-29")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## 0.2.0.dev1 (2021-06-11)

### Feat

- add more stuff

## 0.2.0.dev0 (2021-06-11)

### Feat

- add new output

### Fix

- output glitch

## 1.0.0 (2021-06-11)
20 changes: 20 additions & 0 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ def test_is_version_tag_accepts_dotless_devrelease_in_custom_tag_format():
assert str(extracted) == "1.2.3.dev1"


def test_is_version_tag_accepts_pep440_devrelease_in_default_tag_format():
"""Regression test for #1367: a PEP 440 development release tag such as
``0.2.0.dev1`` (created by ``cz bump --devrelease``) must be recognised as
a version tag. Previously the default version parser only accepted
``.dev`` suffixes after a hyphen, so the tag was dropped and the
incremental changelog failed with "No tag found to do an incremental
changelog".
"""
rules = TagRules()

assert rules.is_version_tag("0.2.0.dev1") is True
assert rules.is_version_tag("0.2.0.dev0") is True
assert rules.is_version_tag("1.2.3.dev1+build.5") is True
assert rules.is_version_tag("1.0.0a2.dev1") is True

extracted = rules.extract_version(_git_tag("0.2.0.dev1"))
assert str(extracted) == "0.2.0.dev1"
assert extracted.dev == 1


def test_monorepo_ignored_tag_formats_keep_own_tags(capsys: pytest.CaptureFixture):
"""Regression test for the monorepo workflow in
``docs/tutorials/monorepo_guidance.md``.
Expand Down
Loading