mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
1dd7307fde
more and more move rebase commit refreshing into existing abstraction and more and more WIP and more handling clicks properly fix merge conflicts update cheatsheet lots more preparation to start moving things into controllers WIP better typing expand on remotes controller moving more code into controllers
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package gui
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
// list panel functions
|
|
|
|
func (gui *Gui) getSelectedRemote() *models.Remote {
|
|
selectedLine := gui.State.Panels.Remotes.SelectedLineIdx
|
|
if selectedLine == -1 || len(gui.State.Remotes) == 0 {
|
|
return nil
|
|
}
|
|
|
|
return gui.State.Remotes[selectedLine]
|
|
}
|
|
|
|
func (gui *Gui) remotesRenderToMain() error {
|
|
var task updateTask
|
|
remote := gui.getSelectedRemote()
|
|
if remote == nil {
|
|
task = NewRenderStringTask("No remotes")
|
|
} else {
|
|
task = NewRenderStringTask(fmt.Sprintf("%s\nUrls:\n%s", style.FgGreen.Sprint(remote.Name), strings.Join(remote.Urls, "\n")))
|
|
}
|
|
|
|
return gui.refreshMainViews(refreshMainOpts{
|
|
main: &viewUpdateOpts{
|
|
title: "Remote",
|
|
task: task,
|
|
},
|
|
})
|
|
}
|
|
|
|
func (gui *Gui) refreshRemotes() error {
|
|
prevSelectedRemote := gui.getSelectedRemote()
|
|
|
|
remotes, err := gui.git.Loaders.Remotes.GetRemotes()
|
|
if err != nil {
|
|
return gui.c.Error(err)
|
|
}
|
|
|
|
gui.State.Remotes = remotes
|
|
|
|
// we need to ensure our selected remote branches aren't now outdated
|
|
if prevSelectedRemote != nil && gui.State.RemoteBranches != nil {
|
|
// find remote now
|
|
for _, remote := range remotes {
|
|
if remote.Name == prevSelectedRemote.Name {
|
|
gui.State.RemoteBranches = remote.Branches
|
|
}
|
|
}
|
|
}
|
|
|
|
return gui.c.PostRefreshUpdate(gui.mustContextForContextKey(types.ContextKey(gui.Views.Branches.Context)))
|
|
}
|