mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
pkg/gui: Allow user to select remote and branch when creating a PR
When creating a PR against a selected branch (via O = "create pull request options"), the user will first be asked to select a remote (if there is more than one). After that, the suggestion area is populated with all remote branches at that origin - instead of all local ones. After all, creating a PR against a branch that doesn't exist on the remote won't work. Please note that for the "PR is not filed against 'origin' remote" use case (e.g. when contributing via a fork that is 'origin' to a GitHub project that is 'upstream'), the opened URL will not be correct. This is not a regression and will be fixed in an upcoming PR. Fixes #1826.
This commit is contained in:
committed by
Jesse Duffield
parent
b62546c391
commit
949e131ebe
@ -730,11 +730,23 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra
|
||||
{
|
||||
LabelColumns: fromToLabelColumns(branch.Name, self.c.Tr.SelectBranch),
|
||||
OnPress: func() error {
|
||||
if !branch.IsTrackingRemote() {
|
||||
return errors.New(self.c.Tr.PullRequestNoUpstream)
|
||||
}
|
||||
|
||||
if len(self.c.Model().Remotes) == 1 {
|
||||
toRemote := self.c.Model().Remotes[0].Name
|
||||
self.c.Log.Debugf("PR will target the only existing remote '%s'", toRemote)
|
||||
return self.promptForTargetBranchNameAndCreatePullRequest(branch, toRemote)
|
||||
}
|
||||
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: branch.Name + " →",
|
||||
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRemoteBranchesSuggestionsFunc("/"),
|
||||
HandleConfirm: func(targetBranchName string) error {
|
||||
return self.createPullRequest(branch.Name, targetBranchName)
|
||||
Title: self.c.Tr.SelectTargetRemote,
|
||||
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRemoteSuggestionsFunc(),
|
||||
HandleConfirm: func(toRemote string) error {
|
||||
self.c.Log.Debugf("PR will target remote '%s'", toRemote)
|
||||
|
||||
return self.promptForTargetBranchNameAndCreatePullRequest(branch, toRemote)
|
||||
},
|
||||
})
|
||||
|
||||
@ -764,6 +776,26 @@ func (self *BranchesController) createPullRequestMenu(selectedBranch *models.Bra
|
||||
return self.c.Menu(types.CreateMenuOptions{Title: fmt.Sprint(self.c.Tr.CreatePullRequestOptions), Items: menuItems})
|
||||
}
|
||||
|
||||
func (self *BranchesController) promptForTargetBranchNameAndCreatePullRequest(fromBranch *models.Branch, toRemote string) error {
|
||||
remoteDoesNotExist := lo.NoneBy(self.c.Model().Remotes, func(remote *models.Remote) bool {
|
||||
return remote.Name == toRemote
|
||||
})
|
||||
if remoteDoesNotExist {
|
||||
return fmt.Errorf(self.c.Tr.NoValidRemoteName, toRemote)
|
||||
}
|
||||
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: fmt.Sprintf("%s → %s/", fromBranch.UpstreamBranch, toRemote),
|
||||
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRemoteBranchesForRemoteSuggestionsFunc(toRemote),
|
||||
HandleConfirm: func(toBranch string) error {
|
||||
self.c.Log.Debugf("PR will target branch '%s' on remote '%s'", toBranch, toRemote)
|
||||
return self.createPullRequest(fromBranch.UpstreamBranch, toBranch)
|
||||
},
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *BranchesController) createPullRequest(from string, to string) error {
|
||||
url, err := self.c.Helpers().Host.GetPullRequestURL(from, to)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user