1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/remotes_panel.go

62 lines
1.5 KiB
Go
Raw Normal View History

2019-11-16 07:38:38 +02:00
package gui
import (
"fmt"
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/style"
2022-01-28 11:44:36 +02:00
"github.com/jesseduffield/lazygit/pkg/gui/types"
2019-11-16 07:38:38 +02:00
)
// list panel functions
2020-09-29 10:41:06 +02:00
func (gui *Gui) getSelectedRemote() *models.Remote {
2020-08-20 00:53:10 +02:00
selectedLine := gui.State.Panels.Remotes.SelectedLineIdx
2019-11-17 04:47:47 +02:00
if selectedLine == -1 || len(gui.State.Remotes) == 0 {
2019-11-16 07:38:38 +02:00
return nil
}
return gui.State.Remotes[selectedLine]
}
func (gui *Gui) remotesRenderToMain() error {
2020-08-18 14:02:35 +02:00
var task updateTask
2019-11-16 07:38:38 +02:00
remote := gui.getSelectedRemote()
2019-11-18 00:38:36 +02:00
if remote == nil {
2021-04-04 15:51:59 +02:00
task = NewRenderStringTask("No remotes")
2020-08-18 14:02:35 +02:00
} else {
task = NewRenderStringTask(fmt.Sprintf("%s\nUrls:\n%s", style.FgGreen.Sprint(remote.Name), strings.Join(remote.Urls, "\n")))
}
2020-08-23 01:46:28 +02:00
return gui.refreshMainViews(refreshMainOpts{
2020-08-18 14:02:35 +02:00
main: &viewUpdateOpts{
title: "Remote",
task: task,
},
})
2019-11-16 07:38:38 +02:00
}
func (gui *Gui) refreshRemotes() error {
2019-11-17 04:47:47 +02:00
prevSelectedRemote := gui.getSelectedRemote()
remotes, err := gui.git.Loaders.Remotes.GetRemotes()
2019-11-16 07:38:38 +02:00
if err != nil {
return gui.c.Error(err)
2019-11-16 07:38:38 +02:00
}
gui.State.Remotes = remotes
2019-11-17 04:47:47 +02:00
// 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)))
2019-12-07 07:20:22 +02:00
}