Skip to content

Cloning with options single branch and ref = HEAD is broken for repo with main base branch #363

@jjalfaro9

Description

@jjalfaro9

Hey y'all ✌️🤠!

Repositories are shifting over to using main as their base branch.
Today go-git does not work as expected when cloning a repo with main = head and the following options:

&git.CloneOptions{
 	URL:          url,
 	Depth:        1,
 	SingleBranch: true,
 	ReferenceName: plumbing.HEAD,
 }

I kind of dug around and noticed that go-git hardcodes to plumbing.Master.Short() here:

go-git/repository.go

Lines 905 to 908 in 4ec1753

case o.SingleBranch && o.ReferenceName == plumbing.HEAD:
return []config.RefSpec{
config.RefSpec(fmt.Sprintf(refspecSingleBranchHEAD, o.RemoteName)),
config.RefSpec(fmt.Sprintf(refspecSingleBranch, plumbing.Master.Short(), o.RemoteName)),

This is the git command equivalent:
git clone --single-branch --depth=1 {REPO_URL_WITH_MAIN_BRANCH_AS_BASE}
The expected behavior is that it clones the repository with HEAD pointing to main. go-git returns an error stating couldn't find remote ref "refs/heads/master".

Is this something that y'all are aware of or on y'all's road map?
I am more than happy to help contribute a fix!
Just would need some guidance & more time to figure out how config.RefSpec works and why it's hardcoded to plumbing.Master.Short() in the switch statement above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy