Opening a GitHub PR to a specific branch fails since update
Describe the bug
I've recently upgraded LazyGit from 0.38.2 to 0.43.1. On 0.38.2 I would create a pull request to a specific branch using O, select my branch, and press enter. This would open a url like this: https://github.com/<org>/<repo>/compare/<base>...<compare>?expand=1. Since the update, I've noticed that my options all contain origin/ at the beginning of the base. This results in the following URL: https://github.com/<org>/<repo>/compare/origin%2F<base>...<compare>?expand=1 and GitHub gives me a page saying there is nothing to compare. If I remove the origin%2F then it works as expected.
Is this maybe a config that's changed recently?
To Reproduce Steps to reproduce the behavior:
- Open LazyGit in a directory with an existing git repo with a remote named "origin" hosted on GitHub.
- Create a new branch, push some changes
- Press
Oto open the "View create pull request options" menu - Choose the second option "Select branch"
- Select a branch, they should all be prefixed here with
origin/and press enter - Notice the page from GitHub saying "nothing to compare"
Expected behavior It should open a PR creation page correctly.
Version info:
commit=, build date=, build source=homebrew, version=0.43.1, os=darwin, arch=arm64, git version=2.39.3 (Apple Git-145)
git version 2.39.3 (Apple Git-145)
Just out of curiosity, is this a PR across forks?
The assumption is that the original repo is on the origin remote, whilst the fork is on upstream, if I'm not mistaken.
No this is not across forks.
I have the same problem with bitbucket
After doing some bisecting, issue seems to be introduced by https://github.com/jesseduffield/lazygit/pull/2693
This issue appears to have been resolved by https://github.com/jesseduffield/lazygit/pull/1889 and included in v0.45.0!
The change from using the local branches models.Branch.UpstreamBranch to models.RemoteBranch.Name seems to have changed the value from origin/master to master. I'm no Go expert, but that appears to be because the RemoteBranch Name field comes from this:
https://github.com/jesseduffield/lazygit/blob/40d6800fd35ad2d5c6d96d6f08ffa42d4c764ad3/pkg/commands/git_commands/remote_loader.go#L106-L111
so it does not include the remote's name, whereas the branch UpstreamBranch comes from https://github.com/jesseduffield/lazygit/blob/40d6800fd35ad2d5c6d96d6f08ffa42d4c764ad3/pkg/commands/git_commands/branch_loader.go#L131
which uses the config.Branch.Merge field passed to Short(), whose value is origin/master. Is it is unclear to me if this function Short() is meant to turn the underlying ReferenceNames string from origin/master to master, but it doesn't appear to do that.
https://github.com/jesseduffield/lazygit/blob/53f8249ee150c0a9d0497657f6a27ff990a0879c/vendor/github.com/jesseduffield/go-git/v5/plumbing/reference.go#L113-L124
Regardless, this issue is now fixed, so I think it can be closed? @jesseduffield
I kept digging a little bit because my initial justification for the bug didn't feel complete, and now I think the error came not from the definition of UpstreamBranch, but rather that the Suggestions produced by the ISuggestionsHelper are always going to have matching labels and values, since they are ultimately produced by this matchesToSuggestions. https://github.com/jesseduffield/lazygit/blob/40d6800fd35ad2d5c6d96d6f08ffa42d4c764ad3/pkg/gui/controllers/helpers/suggestions_helper.go#L57-L64
The producer of string[] remote branch names in getRemoteBranchNames likely intended that the concatenated remote name and branch name would be used to identify the item by being the Suggestion's Label, but not its Value.
https://github.com/jesseduffield/lazygit/blob/40d6800fd35ad2d5c6d96d6f08ffa42d4c764ad3/pkg/gui/controllers/helpers/suggestions_helper.go#L157-L163
I retract that last statement about the value produced by getRemoteBranchNames only being useful as an identifier, because in the current context of the diffing menu, the / separated name is correct
https://github.com/jesseduffield/lazygit/blob/40d6800fd35ad2d5c6d96d6f08ffa42d4c764ad3/pkg/gui/controllers/diffing_menu_action.go#L38-L42
Similar point goes with the remote checkout menu, that needs the / separated name when passing it down into the underlying git branch --track <local-name> <remote-name>
https://github.com/jesseduffield/lazygit/blob/40d6800fd35ad2d5c6d96d6f08ffa42d4c764ad3/pkg/gui/controllers/branches_controller.go#L483-L489
/close This was fixed by https://github.com/jesseduffield/lazygit/pull/1889