Skip to content

Choose a semver tag over the last tag in a repo - #3732

Closed
pjaselin wants to merge 5 commits into
pre-commit:mainfrom
pjaselin:main
Closed

Choose a semver tag over the last tag in a repo#3732
pjaselin wants to merge 5 commits into
pre-commit:mainfrom
pjaselin:main

Conversation

@pjaselin

@pjaselin pjaselin commented Aug 2, 2026

Copy link
Copy Markdown

Problem: I'm (and it looks like others) are seeing this pop up with pre-commit hooks coming from repos like: https://github.com/crate-ci/typos where a tag like "v1" is maintained for the latest release along with a semver tag like "v1.Y.Z". When running pre-commit autoupdate, you always get the "v1" tag instead of the latest "v1.Y.Z" tag. This is reported with a workaround here: crate-ci/typos#390 but it seems like the fix should actually be at the pre-commit level and not to go around mirroring repos to get a clean set of tags.

Solution: I believe the intention of the git.get_best_candidate_tag function is to choose a semver-compliant tag instead of necessarily the most recent one, where these tags may be off the same commit SHA. This PR gets the commit for the last found tag, then gets all tags associated with that commit SHA, and finally allows for returning that commit if there's a period in it. I've added tests for the git and autoupdate module to support the changes.

Edit: I'm reading your comments in #2366 and I'm seeing how there's a tradeoff between repeatability here in getting the right tags so this might not be an improvement even if it appears to fix what I've experienced. Happy to close this if so and take it as an opportunity to learn about the internals of pre-commit.

Comment thread pre_commit/git.py

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Does NO_FS_MONITOR need to be in L240?

@asottile

asottile commented Aug 2, 2026

Copy link
Copy Markdown
Member

search the issue tracker next time

@asottile asottile closed this Aug 2, 2026
@pre-commit pre-commit locked as off-topic and limited conversation to collaborators Aug 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants