Skip to content

fix(cmd-version): scope forced bumps to branch history - #1469

Open
floze-the-genius wants to merge 2 commits into
python-semantic-release:masterfrom
floze-the-genius:agent/fix-forced-bump-branch-history
Open

fix(cmd-version): scope forced bumps to branch history#1469
floze-the-genius wants to merge 2 commits into
python-semantic-release:masterfrom
floze-the-genius:agent/fix-forced-bump-branch-history

Conversation

@floze-the-genius

Copy link
Copy Markdown

Purpose

Fixes #1392.

Forced version --patch, --minor, --major, and --prerelease calculations now use only release tags reachable from the active branch. A higher tag on a divergent branch no longer causes maintenance or hotfix branches to over-bump.

Rationale

The dynamic next_version() path already filtered tags against the active branch history, but version_from_forced_level() called tags_and_versions() directly and therefore selected the highest semantic version anywhere in the repository.

This change extracts the existing reachability filter into tags_and_versions_in_history() and reuses it for both dynamic and forced calculations. Shallow repositories retain the previous tag-name behavior when the graph is intentionally unavailable, such as --noop reporting an unshallow operation.

How did you test?

  • Added an E2E regression test with a v1.0.0 tag on a divergent branch and verified version --print --patch returns 0.1.2 from the active branch's v0.1.1 history.
  • Verified the regression test failed on current master with 1.0.1 before the fix.
  • Ran the focused regression and shallow-noop tests.
  • Ran all unit tests: 4264 passed, 15 skipped.
  • Ran all E2E tests: 265 passed, 708 skipped.
  • Ran Ruff lint and format checks across the repository.
  • Ran mypy across all 185 source files under Python 3.8, matching CI.

How to Verify

pytest -q tests/e2e/cmd_version/test_version_print.py::test_version_print_forced_bump_ignores_tags_outside_branch_history
pytest -q tests/e2e/cmd_version/test_version_shallow.py::test_version_noop_w_shallow_repo

AI Assistance Disclosure

OpenAI Codex was used to investigate the issue, implement the change, and run the validation workflow. The final diff and test results were reviewed during the contribution process.

DCO

Both commits include a Signed-off-by trailer.


PR Completion Checklist

  • Reviewed & followed the Contributor Guidelines
  • Changes implemented and local validation succeeds
  • Commits follow Conventional Commits and are separated test-first, then fix
  • Appropriate unit tests added/updated (E2E coverage directly exercises the CLI regression)
  • Appropriate End-to-End tests added/updated
  • Documentation not required because user-facing configuration and CLI options are unchanged

Resolves: python-semantic-release#1392
Signed-off-by: Floze <88098863+floze-the-genius@users.noreply.github.com>
Resolves: python-semantic-release#1392
Signed-off-by: Floze <88098863+floze-the-genius@users.noreply.github.com>
@floze-the-genius

Copy link
Copy Markdown
Author

The remaining Python 3.14 E2E failure appears unrelated to this change: the new forced-bump regression and the shallow-repository test both passed, while two existing test_version_bump.py cases failed with transient Git object errors (fatal: unable to read tree / unable to read <object>). The run is https://github.com/python-semantic-release/python-semantic-release/actions/runs/29651155334/job/88370507488. I cannot rerun it without repository admin permission; could a maintainer please rerun the failed job?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forcing the next version to be a (patch|minor|major) release always uses the highest existing tag

1 participant