question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pre-commit shallow cloning strategy fails to grab the tag (git itself does)

See original GitHub issue

search 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:closed
  • Created 10 months ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
asottilecommented, Nov 22, 2022

feel free to send a patch – but everything else seems to work fine without needing the actual tag metadata

clone --branch doesn’t work because rev can be things other than named refs / branches

0reactions
webknjazcommented, Nov 23, 2022

Oh, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hook installs an ancient version of black · Issue #1593 - GitHub
When I run pre-commit run -v for my black hook, ... Pre-commit shallow cloning strategy fails to grab the tag (git itself does)...
Read more >
Convert shallow repo to normal repo - git - Stack Overflow
The repo is local for the time being. That is, I am trying to push to a new remote, which has no history,...
Read more >
Get up to speed with partial clone and shallow clone
Shallow clones are the fastest way to get a copy of the working directory at the tip commit with the additional cost that...
Read more >
Diff - pub/scm/git/git - Git repositories on kernel
Merge branch 'nd/shallow-deepen' The existing "git fetch --depth=<n>" option was hard to use correctly when making the history of an existing shallow clone...
Read more >
GitMigration - GNOME Wiki!
See GitMigration/Translators. Is the checkout time and disk space usage reasonable? The clone time is longer with git compared to SVN checkouts.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found