Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tags_only autoupdate picks first (alphabetical?) tag when multiple on SHA #2311

Closed
mblayman opened this issue Mar 30, 2022 · 1 comment · Fixed by #2312
Closed

tags_only autoupdate picks first (alphabetical?) tag when multiple on SHA #2311

mblayman opened this issue Mar 30, 2022 · 1 comment · Fixed by #2312
Labels

Comments

@mblayman
Copy link
Contributor

mblayman commented Mar 30, 2022

describe your issue

I got an autoupdate PR from pre-commit.ci at https://github.com/mblayman/atlas/pull/29/files

The autoupdate is trying to update the luacheck hook from v0.26.0 to latest. This is not ideal because latest is a moving target while v0.26.0 is fixed.

As of this writing, luacheck has three tags on the latest tagged release:
image

I inspected the autoupdate command and found the source of this issue at

tag_cmd = (
*git_cmd, 'describe',
'FETCH_HEAD', '--tags', '--abbrev=0',
)

autoupdate basically runs git describe FETCH_HEAD --tags --abbrev=0. In the case of the luacheck repo, this returns latest.

➜  luacheck git:(master) git describe FETCH_HEAD --tags --abbrev=0
latest

I was able to replicate the behavior of this command in the pre-commit repo itself by adding a latest tag to the same SHA as v2.17.0.

git tag latest d3bdf1403d92f8cf2dc77bd99a5da42f0a6cef17
git describe --tags FETCH_HEAD --abbrev=0 
latest

While git describe FETCH_HEAD --tags --abbrev=0 is elegant in its simplicity, it can only return a single tag, so it's limited in this multiple tags case.

Possible solution

pre-commit could look for the latest tag, then check to see if there are multiple tags on that SHA. If so, a tag could be preferred if it looks more "version-y." Maybe that's a semver style regex or something like that.

One of the tricks, I think, is to figure out how to check for multiple tags. I think the simplest way would be to get the output from tag_cmd and run that through git tag --points-at <tag_cmd output>. If there are multiple lines, then the version checking kind of stuff could occur.

Before trying this out, I wanted to check if this seems like a reasonable path or if there are other preferential ways to tackle this kind of thing.

pre-commit --version

pre-commit 2.17.0

.pre-commit-config.yaml

ci:
  # The compilation time is too long so CI hits a timeout.
  skip: [luaformatter]

repos:
- repo: https://github.com/lunarmodules/luacheck
  rev: "v0.26.0"
  hooks:
  - id: luacheck
- repo: https://github.com/mblayman/LuaFormatter
  rev: "ad94bea01ca027ca46541af727e15d002aa5ce74"
  hooks:
  - id: luaformatter

~/.cache/pre-commit/pre-commit.log (if present)

No response

@asottile
Copy link
Member

this is currently what pre-commit uses to consider a "version-y" string -- so that could probably be chosen preferentially (unless no such tag matches for the latest) --

if '.' not in rev and not re.match(r'^[a-fA-F0-9]+$', rev):

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

Successfully merging a pull request may close this issue.

2 participants