Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go-git fails to parse branches with refs/pull as their merge target #530

Open
georgettica opened this issue May 17, 2022 · 3 comments
Open

Comments

@georgettica
Copy link

as a user of go-git, it seems the command https://pkg.go.dev/github.com/go-git/go-git/v5#Repository.ConfigScoped fails for gh pr checkout remote branches (from other users)

tools used for test:

$ gh repo fork --clone 
$ gh pr checkout ${PR_NUMBER}
...
$ cat .git/config
...
[branch "master"]
        remote = upstream
        pushRemote = upstream
        merge = refs/pull/${PR_NUMBER}/head
...
$ gogitmail
panic: branch config: invalid merge

the issue stems from the fact that refs/pull is not a valid merge target, but is what cli/cli pushes.

LOC that fails in go-git

return strings.HasPrefix(string(r), refHeadPrefix)

LOC that fails in my code https://github.com/georgettica/gogitmail/blob/38ccca86d8503101686497c63b21a48c71f81380/pkg/utils/utils.go#L24


I cannot check the error for the string there as it's an internal error

@Skarlso
Copy link

Skarlso commented Oct 5, 2022

This works fine:

	if err := r.Fetch(&git.FetchOptions{
		RefSpecs: []config.RefSpec{"refs/pull/3741/head:suspend_asg_processes"},
		Depth:    1,
	}); err != nil {
		fmt.Println("fetch err: ", err)
		os.Exit(1)
	}

@georgettica
Copy link
Author

Lost context on this a long time ago, I hope this doesn't happen to anyone else bit if it does now there is a snippet :)

I'll see if I get to testing this in my code :)

@MichaelMure
Copy link
Contributor

It happened to me as well in the context of https://github.com/MichaelMure/git-bug, where I don't control the user git config, yet want to read or add values there.

chris-laplante added a commit to chris-laplante/act that referenced this issue Sep 25, 2023
Thanks to go-git/go-git#530, act will spam the
console/log with a billion warnings like this:

WARN[0000] unable to get git repo: branch config: invalid merge

when a GitHub PR branch is checked out.
chris-laplante added a commit to chris-laplante/act that referenced this issue Sep 25, 2023
Thanks to go-git/go-git#530, act will spam the
console/log with a billion warnings like this:

WARN[0000] unable to get git repo: branch config: invalid merge

when a GitHub PR branch is checked out.
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

No branches or pull requests

3 participants