Skip to content

Error with single branch clone with non-master default branch #249

@hairyhenderson

Description

@hairyhenderson

All new GitHub repos are created with a default branch of main, instead of the older master.

If I try to clone such a repo with the SingleBranch option enabled, I see an error like couldn't find remote ref "refs/heads/master".

This code demonstrates the issue (the repo https://github.com/hairyhenderson/hitron_coda.git has a default branch of main):

package main

import (
	"fmt"

	"github.com/go-git/go-billy/v5/memfs"
	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/storage/memory"
)

func main() {
	fs := memfs.New()
	storer := memory.NewStorage()

	opts := &git.CloneOptions{
		URL:          "https://github.com/hairyhenderson/hitron_coda.git",
		SingleBranch: true,
	}

	_, err := git.Clone(storer, fs, opts)
	if err != nil {
		fmt.Println(err)
	}
}
$ go run main.go
couldn't find remote ref "refs/heads/master"

If I set SingleBranch to false it succeeds, but this isn't desirable for my use-case since I want to minimize what I'm pulling down.

The issue seems rooted in this code, which defaults to the plumbing.Master constant when SingleBranch is true and ReferenceName defaults to HEAD.

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