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: 7 additions & 0 deletions commitizen/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ def normalize_tag(

major, minor, patch = (list(version.release) + [0, 0, 0])[:3]
prerelease = version.prerelease or ""
# `dev` is the integer dev-release number (e.g. 1 for "0.1.0.dev1")
# or None if this version isn't a dev release. We render it as
# `dev<N>` to match how dev releases appear in PEP-440 / SemVer
# version strings.
dev = getattr(version, "dev", None)
devrelease = f"dev{dev}" if dev is not None else ""
Comment on lines +217 to +220
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — this is exactly what PR #1972 (#1972) addresses by widening the devrelease tag-regex to \.?dev\d+ (optional leading dot), so $prerelease.$devrelease formats round-trip even when the substituted devrelease has no leading dot. The two PRs should land together (or be squash-merged in the right order). I'll leave this thread for the reviewer to resolve once they've cross-checked #1972.


t = Template(tag_format)
return t.safe_substitute(
Expand All @@ -220,6 +226,7 @@ def normalize_tag(
minor=minor,
patch=patch,
prerelease=prerelease,
devrelease=devrelease,
)

def find_tag_for(
Expand Down
5 changes: 5 additions & 0 deletions tests/test_bump_normalize_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
(("1.2.3+1.0.0", "v$version"), "v1.2.3+1.0.0"),
(("1.2.3+1.0.0", "v$version-local"), "v1.2.3+1.0.0-local"),
(("1.2.3+1.0.0", "ver$major.$minor.$patch"), "ver1.2.3"),
# `${devrelease}` substitution (#1615): rendered as `dev<N>` when the
# version has a dev release, and as the empty string otherwise.
(("1.2.3.dev1", "v$major.$minor.$patch.$devrelease"), "v1.2.3.dev1"),
(("1.2.3.dev0", "$major.$minor.$patch$devrelease"), "1.2.3dev0"),
(("1.2.3", "$major.$minor.$patch$devrelease"), "1.2.3"),
]


Expand Down
Loading