Visitar URL original
clone: support tags and explicit branch references by hakarrr · Pull Request #7475 · libgit2/libgit2 · GitHub
Skip to content

clone: support tags and explicit branch references - #7475

Open
hakarrr wants to merge 3 commits into
libgit2:mainfrom
hakarrr:clone-checkout-tags
Open

hakarrr wants to merge 3 commits into
libgit2:mainfrom
hakarrr:clone-checkout-tags

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 10, 2026

Copy link
Copy Markdown

Fixes #3218.

checkout_branch currently treats every selection as a remote branch name, so a tag or an explicit refs/heads/... reference cannot be selected when cloning.

This keeps branch-first lookup for short names and falls back to a tag only when the branch is absent. Explicit refs/heads/... selects only a branch; explicit refs/tags/... selects only a tag. Tag selections use the existing HEAD setter to peel annotated tags and detach HEAD at the target commit. Normal branch tracking and the remote's default HEAD are preserved.

The API documentation now describes these choices. Twelve local regression tests cover lightweight and nested annotated tags, branch/tag collisions, explicit references, bare clones, the non-optimized file transport, missing selections and non-commit tags. They also check tracking configuration, detached HEAD and cleanup on failure. Arbitrary revision expressions are not added.

Validation on Linux, based on 42a89d7cc9374a19e72fa57011e5fe3a99c7b3bf:

  • Debug and Release builds with ENABLE_WERROR=ON pass. HTTPS, SSH, NTLM and Negotiate were disabled because their development dependencies are unavailable here.
  • All 12 new tests pass in Debug, Release and ASan+UBSan with leak detection. With the original clone.c, seven positive regression cases fail and five control cases pass.
  • Thirty local clone tests, run individually in each of Debug and Release, pass. bad_urls was not included because its network attempts timed out.
  • The remaining offline Release selection (-xonline -xclone::nonetwork) reports 3,103 executions, 45 skips and no failures. The same Debug selection has one structinit padding failure, reproduced after restoring the original clone.c.

No shallow HTTP/SSH, Windows or macOS validation is claimed.

hakarrr and others added 3 commits November 11, 2026 03:38
Keep branch-first lookup for short names and fall back to a tag only when
no branch exists. Use the existing HEAD setter to peel tags and detach,
and accept explicit refs/heads/ and refs/tags/ selections.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Describe explicit branch and tag references, branch-first short names,
and detached HEAD behavior when selecting a tag.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Cover lightweight and nested annotated tags, explicit refs, branch/tag
collisions, bare and transported clones, and invalid checkout cleanup.
Check detached HEAD, tracking configuration and preserved remote HEAD.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
@hakarrr

hakarrr commented Nov 13, 2026

Copy link
Copy Markdown
Author

Could a maintainer review this clone support for tags and explicit branch references? Please let me know whether this behavior is wanted or if changes or additional cases are needed before review. Thanks.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clone's branch option should take a ref or DWIM it

1 participant