Summary
Using GitHub CLI gh ( https://github.com/cli/cli ), I often checkout pull-request.
But go-git fails to parse the config in the repository that has a branch created by gh.
To reproduce:
- Prepare a repository
$ git clone https://github.com/go-git/go-git
$ gh pr checkout 330
- Try to get the remote URLs from the repository with
go-git
repo, err := git.PlainOpen("./go-git")
if err != nil {
return nil, fmt.Errorf("open local repository: %w", err)
}
remote, err := repo.Remote("origin")
if err != nil {
return nil, fmt.Errorf("get remote %s: %w", name, err)
}
return remote.Config().URLs, nil
It fails.
Supplement
gh pr checkout xxx creates a branch like below.
[branch "foo/bar"]
remote = origin
merge = refs/pull/330/head
go-git says "branch config: invalid merge".
|
if b.Merge != "" && !b.Merge.IsBranch() { |
|
return errBranchInvalidMerge |
|
} |
|
errBranchInvalidMerge = errors.New("branch config: invalid merge") |
|
func (r ReferenceName) IsBranch() bool { |
|
return strings.HasPrefix(string(r), refHeadPrefix) |
|
} |
|
refHeadPrefix = refPrefix + "heads/" |
Summary
Using GitHub CLI
gh( https://github.com/cli/cli ), I often checkout pull-request.gh pr checkout 330But go-git fails to parse the config in the repository that has a branch created by
gh.To reproduce:
go-gitIt fails.
Supplement
gh pr checkout xxxcreates a branch like below.go-gitsays "branch config: invalid merge".go-git/config/branch.go
Lines 39 to 41 in da81027
go-git/config/branch.go
Line 12 in da81027
go-git/plumbing/reference.go
Lines 89 to 91 in da81027
go-git/plumbing/reference.go
Line 11 in da81027