mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-11 08:06:25 -04:00
Improve github repo picking UX
We now auto-select a remote if: * it's the only remote * it's named origin Otherwise we prompt the user to specify the remote they want to use.
This commit is contained in:
parent
a9a13619fd
commit
658dbd2bdf
|
|
@ -825,48 +825,57 @@ func (self *RefreshHelper) promptForBaseGithubRepo() (bool, error) {
|
|||
return false, err
|
||||
}
|
||||
|
||||
switch len(self.c.Model().Remotes) {
|
||||
case 0:
|
||||
return false, nil
|
||||
case 1:
|
||||
remote := self.c.Model().Remotes[0]
|
||||
|
||||
if len(remote.Urls) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
repoName, err := self.c.Git().HostingService.GetRepoNameFromRemoteURL(remote.Urls[0])
|
||||
if err != nil {
|
||||
self.c.Log.Error(err)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
_, err = self.c.Git().GitHub.SetBaseRepo(repoName)
|
||||
if err != nil {
|
||||
self.c.Log.Error(err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
default:
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: self.c.Tr.SelectRemoteRepository,
|
||||
InitialContent: "",
|
||||
FindSuggestionsFunc: self.suggestionsHelper.GetRemoteRepoSuggestionsFunc(),
|
||||
HandleConfirm: func(repository string) error {
|
||||
return self.c.WithWaitingStatus(self.c.Tr.LcSelectingRemote, func(gocui.Task) error {
|
||||
// `repository` is something like 'jesseduffield/lazygit'
|
||||
_, err := self.c.Git().GitHub.SetBaseRepo(repository)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.refreshGithubPullRequests()
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
remotes := self.c.Model().Remotes
|
||||
if len(remotes) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// If there's only one remote, or if 'origin' exists, use it automatically
|
||||
remote, hasOrigin := lo.Find(remotes, func(r *models.Remote) bool {
|
||||
return r.Name == "origin"
|
||||
})
|
||||
if !hasOrigin {
|
||||
if len(remotes) == 1 {
|
||||
remote = remotes[0]
|
||||
} else {
|
||||
// Multiple remotes with no 'origin': prompt the user
|
||||
self.c.Prompt(types.PromptOpts{
|
||||
Title: self.c.Tr.SelectRemoteRepository,
|
||||
InitialContent: "",
|
||||
FindSuggestionsFunc: self.suggestionsHelper.GetRemoteRepoSuggestionsFunc(),
|
||||
HandleConfirm: func(repository string) error {
|
||||
return self.c.WithWaitingStatus(self.c.Tr.LcSelectingRemote, func(gocui.Task) error {
|
||||
// `repository` is something like 'jesseduffield/lazygit'
|
||||
_, err := self.c.Git().GitHub.SetBaseRepo(repository)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.refreshGithubPullRequests()
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
if len(remote.Urls) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
repoName, err := self.c.Git().HostingService.GetRepoNameFromRemoteURL(remote.Urls[0])
|
||||
if err != nil {
|
||||
self.c.Log.Error(err)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
_, err = self.c.Git().GitHub.SetBaseRepo(repoName)
|
||||
if err != nil {
|
||||
self.c.Log.Error(err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (self *RefreshHelper) determineGithubCliState() types.GitHubCliState {
|
||||
|
|
|
|||
|
|
@ -1719,6 +1719,8 @@ func EnglishTranslationSet() *TranslationSet {
|
|||
CyclePagersDisabledReason: "No other pagers configured",
|
||||
StartSearch: "Search the current view by text",
|
||||
StartFilter: "Filter the current view by text",
|
||||
SelectRemoteRepository: "Select base repository for pull requests",
|
||||
LcSelectingRemote: "Selecting remote",
|
||||
KeybindingsLegend: "Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b",
|
||||
RenameBranch: "Rename branch",
|
||||
BranchUpstreamOptionsTitle: "Upstream options",
|
||||
|
|
|
|||
Loading…
Reference in a new issue