Pre-commit shallow cloning strategy fails to grab the tag (git itself does)
See original GitHub issuesearch you tried in the issue tracker
yes, found two related closed issues
describe your issue
As a user of ansible-lint reported that the hook reported its own version incorrectly as 0.1dev1
I had to research what happens. This allowed me to find #2354 and #1593 which reported the same kind of issue across different python projects using setuptools-scm.
I did look at the cloning logic of pre-commit tool which attempts to perform a shallow cloning first and only if this fails tries to make a full one. I manually repeated the steps and discovered that its operation does not created any local tags, so not surprise that any project using setuptools-scm would have wrong versioning:
Test using pre-commit internal cloning strategy
git init --template= ansible-lint
cd ansible-lint
git remote add origin https://github.com/ansible/ansible-lint
git -c protocol.version=2 fetch origin v6.8.7 --depth=1
git checkout FETCH_HEAD
git -c protocol.version=2 submodule update --init --recursive --depth=1
# done, now testing if we have any tags:
git tag --points-at HEAD
# ... ooops, no tag.
Test using official git shallow cloning:
git clone --depth=1 --branch v6.8.7 https://github.com/ansible/ansible-lint
cd ansible-lint
git tag --points-at HEAD
v6.8.7
# So it worked fine as tag is present!
As seen, is not the shallow-cloning that is the source of the problem but the absence of the tag . When using a single git command to clone, this is added, but with the more complex logic of pre-commit, this is not added.
I guess that this issue could be avoided by including the tag addition in pre-commit internal shallow cloning strategy.
pre-commit --version
2.20.0
.pre-commit-config.yaml
- repo: https://github.com/ansible/ansible-lint
rev: v6.8.7
hooks:
- id: ansible-lint
~/.cache/pre-commit/pre-commit.log (if present)
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:9 (4 by maintainers)
Top GitHub Comments
feel free to send a patch – but everything else seems to work fine without needing the actual tag metadata
clone --branch
doesn’t work becauserev
can be things other than named refs / branchesOh, I haven’t thought about it, that should work. Although, it wouldn’t be the same and may break expectations of some tools that would attempt to read something from that tag’s description.