Skip to content

feature: fetch tag pointing to HEAD in shallow clone#3617

Open
gnought wants to merge 3 commits intopre-commit:mainfrom
gnought:feat/shadow-clone-fetch-tag
Open

feature: fetch tag pointing to HEAD in shallow clone#3617
gnought wants to merge 3 commits intopre-commit:mainfrom
gnought:feat/shadow-clone-fetch-tag

Conversation

@gnought
Copy link

@gnought gnought commented Feb 6, 2026

pre-commit shallow clones do not fetch tags, which leads to errors when a repository depends on tag metadata (see golangci/golangci-lint#6347).

This PR adds logic to resolve and fetch the remote tag associated with FETCH_HEAD when present.

@asottile
Copy link
Member

unless you can make this happen in a single fetch I can't accept this. I've tried but have been unable to get the right refspec

as written this invokes 3 remote operations which from some local testing is often slower than the full clone which defeats the entire purpose of shallow fetching in the first place

@gnought
Copy link
Author

gnought commented Feb 13, 2026

@asottile Thank you for your feedback.

I understand that there is no simple way to fetch a single remote tag efficiently. For repositories that require version metadata, and where most rev values correspond to tags, I have added a small workaround that creates a local tag pointing to FETCH_HEAD.

Although the rev may occasionally be a commit hash rather than a tag, this approach ensures that we can support these repositories in most cases. 😄

git_config = 'protocol.version=2'
git_cmd('-c', git_config, 'fetch', 'origin', ref, '--depth=1')
git_cmd('checkout', 'FETCH_HEAD')
git_cmd('tag', '-a', '-m', '""', ref, 'FETCH_HEAD')
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is good either. this will tag non-tags (and invoke signing mechanisms)

Copy link
Author

@gnought gnought Feb 14, 2026

Choose a reason for hiding this comment

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

Yes, this will tag non-tag revisions but limit to local. As long as pre-commit does not push changes, this will not affect the remote or introduce signing issues.

Copy link
Member

Choose a reason for hiding this comment

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

-m invokes signing. and if this tags things differently than the actual repo that's not ok

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants