fix: fetching and cloning with refspecs that are tags (in shallow clones)#2556
Draft
Sebastian Thiel (Byron) wants to merge 1 commit intomainfrom
Draft
fix: fetching and cloning with refspecs that are tags (in shallow clones)#2556Sebastian Thiel (Byron) wants to merge 1 commit intomainfrom
Sebastian Thiel (Byron) wants to merge 1 commit intomainfrom
Conversation
…nes) Fix shallow clone refspecs for explicit tag refs When a shallow clone was created with `with_ref_name()`, the clone setup treated the requested name as a branch and generated a refspec under `refs/heads/`. For tag names this produced an unmatched required mapping like `+refs/heads/<tag>:refs/remotes/origin/<tag>`. Resolve the requested ref name against the remote before constructing the shallow single-ref refspec. Branches continue to map to `refs/remotes/<remote>/*`, while tags and other non-branch refs map to themselves. Baseline Git behavior was checked with `/Users/byron/dev/github.com/git/git`: non-shallow `--branch <tag>` clones keep the normal branch wildcard fetch refspec, while shallow `--depth 1 --branch <tag>` clones store `+refs/tags/<tag>:refs/tags/<tag>`. Extend the annotated tag clone test to cover both full and shallow lones, and assert the shallow tag refspec shape.
3928781 to
3abf658
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #2554.
Tasks
Summary
Fix shallow clones with an explicit tag ref by resolving the requested ref name against the remote before constructing the shallow single-ref refspec.
This addresses #2554, where
PrepareFetch::with_shallow(...).with_ref_name(Some("tag"))incorrectly treated the requested name as a local branch and generated a refspec like:That refspec does not match tag-only refs and now fails once fetch refspec validation rejects unmatched required mappings.
Research
I checked baseline Git behavior using the local Git checkout at:
For a non-shallow clone with
--branch <tag>, Git keeps the normal wildcard fetch refspec:For a shallow clone with
--depth 1 --branch <tag>, Git writes a tag-to-tag refspec instead:The fix follows that behavior: shallow tag clones fetch the selected tag into
refs/tags/*, while shallow branch clones continue to fetch intorefs/remotes/<remote>/*.Changes
with_ref_name()against the remote refs when using the shallow single-ref clone optimization.refs/heads/<name>torefs/remotes/<remote>/<name>.