Skip to content

fix(tags): find current tag matched by a regex-only legacy tag format - #2089

Open
ethanstoner wants to merge 1 commit into
commitizen-tools:masterfrom
ethanstoner:fix/find-tag-for-legacy-build-metadata
Open

ethanstoner wants to merge 1 commit into
commitizen-tools:masterfrom
ethanstoner:fix/find-tag-for-legacy-build-metadata

Conversation

@ethanstoner

Copy link
Copy Markdown

Description

Closes #2015

With version_provider = "scm" and a legacy tag format such as '$major.$minor.$patch$prerelease\+.*', a tag like 1.0.1rc0+gha is recognised and its version is extracted as 1.0.1rc0. cz bump then calls TagRules.find_tag_for, which only compares tag names against normalize_tag(version, fmt) for each format. The \+.* part is regex-only and can't be rendered back into a tag name, so nothing matched. Bump reported "No tag matching configuration could be found." and computed the next version from the whole history.

Fix: when no tag name matches exactly, find_tag_for now falls back to tags whose extracted version equals the requested version. A small private helper, _parse_tag_versions, yields (version, tag) pairs and skips tags that fail to parse. The existing partial-version branch now uses it too, replacing its inline try/except loop.

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (Claude Code)

Generated-by: Claude Code following the guidelines

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes (no user-facing option or documented behavior changed)

Expected Behavior

Using the reproduction from the issue, cz bump --prerelease rc --build-metadata gha --get-next finds 1.0.1rc0+gha as the current tag and prints 1.0.1rc1+gha. Before this change it printed 1.1.0rc0+gha.

Steps to Test This Pull Request

  1. uv run pytest tests/test_tags.py tests/commands/test_bump_command.py -k "regex_only_legacy_tag_format or legacy_tag_with_build_metadata". Both new tests fail on master and pass with this change.
  2. Manually, in an empty directory, follow the steps from scm provider cant find current tag with build metadata if matched by legacy_tag_formats #2015 (scm provider, pep440 scheme, tag_format = "$version", the legacy format above, tag 1.0.1rc0+gha, then a fix: commit) and run cz bump --prerelease rc --build-metadata gha --get-next. On master the output is 1.1.0rc0+gha; on this branch it is 1.0.1rc1+gha.

uv run poe all passes locally (1311 passed, 2 skipped, 2 xfailed; commitizen/tags.py at 100% coverage).

Additional Context

The fallback only runs when no exact tag name matches, so existing lookups are unchanged. It can also find tags that differ only in how the version is written (e.g. 1.0.0-rc0 for 1.0.0rc0). If several tags share a version but carry different build metadata, the existing "Multiple tags found" warning is emitted and the first tag is used, same as for exact matches.

@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.26%. Comparing base (4967717) to head (2676152).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2089   +/-   ##
=======================================
  Coverage   98.26%   98.26%           
=======================================
  Files          61       61           
  Lines        2829     2829           
=======================================
  Hits         2780     2780           
  Misses         49       49           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scm provider cant find current tag with build metadata if matched by legacy_tag_formats

1 participant