Skip to content

fix(scm-provider): prefer full version over floating tags - #2116

Merged
woile merged 1 commit into
commitizen-tools:masterfrom
pujitha24:auto/issue-1863
Oct 24, 2026
Merged

woile merged 1 commit into
commitizen-tools:masterfrom
pujitha24:auto/issue-1863

Conversation

@pujitha24

Copy link
Copy Markdown
Contributor

Description

Fix version_provider = "scm" returning 1.0 instead of 1.0.0 when floating tags (v1.0, v1) exist next to v1.0.0. The tags compare equal and max() kept the newest one. Now the longest spelling wins among equal versions.

Checklist

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

  • Yes (please specify the tool below)

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
    • Ran pytest (all pass), ruff check, ruff format --check, mypy commitizen/providers. Not the full poe all.
  • 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 (not needed: bug fix)

Documentation Changes

  • Run uv run poe doc locally to ensure the documentation pages renders correctly
  • Check and fix any broken links (internal or external)

Expected Behavior

cz version --project prints 1.0.0 when tags v1.0.0, v1.0 and v1 exist.

Steps to Test This Pull Request

  1. uv run pytest tests/providers/test_scm_provider.py
  2. The new test test_scm_provider_prefers_full_version_over_floating_tags fails on master and passes with this change.

Additional Context

Fixes #1863


AI assistance: this change was drafted with Claude Code.

Motivation: With tags v1.0.0, v1.0 and v1 on one commit, the scm version
provider returned "1.0". The three versions compare equal, and max()
kept the first one, which is the newest tag by date. The patch part was
dropped from the project version.

Approach: Break ties between equal versions by choosing the longest
spelling, so 1.0.0 wins over 1.0 and 1. Ordering of unequal versions is
unchanged.

Validation: `uv run pytest -n0` passed (1331 passed, 2 skipped,
2 xfailed). The new test fails without the change and passes with it.
`ruff check`, `ruff format --check` and `mypy commitizen/providers`
pass. `uv run poe all` was not run in full.

Impact: Only affects `version_provider = "scm"` when equal-valued tags
with different lengths exist. Only the version printed or used was
wrong; nothing else changed.

Report: commitizen-tools#1863

Assisted By: AI

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Assisted-by: claude-sonnet-5-5 (via Claude Code)
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.28%. Comparing base (2ebac02) to head (bbe6f73).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2116   +/-   ##
=======================================
  Coverage   98.28%   98.28%           
=======================================
  Files          61       61           
  Lines        2864     2864           
=======================================
  Hits         2815     2815           
  Misses         49       49           

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

@woile

woile commented Oct 24, 2026

Copy link
Copy Markdown
Member

Thanks! 🎉

@woile
woile merged commit 0f5fe53 into commitizen-tools:master Oct 24, 2026
21 checks passed
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.

Version tags with patch version zero ignored if floating tags exist

2 participants