GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feature: fetch tag pointing to HEAD in shallow clone by gnought · Pull Request #3617 · pre-commit/pre-commit

Conversation

@gnought

@gnought gnought commented Feb 6, 2026

Copy link
Copy Markdown

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

LarsArtmann reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@gnought
fetch tag pointing to HEAD in shallow clone
c6b4874
@asottile

asottile commented Feb 12, 2026

Copy link
Copy Markdown
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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gnought added 2 commits February 14, 2026 01:28
@gnought
Revert "fetch tag pointing to HEAD in shallow clone"
19b60a6
This reverts commit c6b4874.
@gnought
add local tag in shallow clone
5c9f50b
@gnought

gnought commented Feb 13, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

@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. 😄

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

asottile
asottile reviewed Feb 13, 2026
View reviewed changes
Comment thread pre_commit/store.py Outdated
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')

@asottile asottile Feb 13, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gnought gnought Feb 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@asottile asottile Feb 14, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@gnought gnought Feb 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

My understanding is that -m does not trigger signing unless -s is used.

git does not provide a direct way to fetch a specific tag at a particular commit. The only single-command option is to use --tags with git fetch, but that would retrieve all tags and be slower than creating a fake local tag.

What do you think about the 3rd proposal on git_cmd('-c', git_config, 'fetch', 'origin', ref, '--depth=1', '--tags') ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@asottile asottile Feb 14, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

your understanding is slightly wrong. and no --tags will not work that will fetch a bunch of unnecessary stuff

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gnought added 2 commits February 14, 2026 21:32
@gnought
Revert "add local tag in shallow clone"
da18066
This reverts commit 5c9f50b.
@gnought
best-effort fetch tag for HEAD in shallow clone
55f9ae7
@gnought

gnought commented Feb 14, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Author

Try an alternative approach by using git fetch origin refs/tags on a best-effort basis. If rev contains a tag, it will be fetched as well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gnought added 2 commits February 18, 2026 11:23
@gnought
lint fix
8fd50fc
@gnought
lint fix
0287f07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@asottile asottile asottile left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@gnought @asottile
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.