2019-11-16 07:38:38 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2020-09-29 12:28:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2021-07-27 15:00:37 +02:00
|
|
|
"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]
|
|
|
|
}
|
|
|
|
|
2021-11-21 03:48:49 +02:00
|
|
|
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 {
|
2021-07-27 15:00:37 +02:00
|
|
|
task = NewRenderStringTask(fmt.Sprintf("%s\nUrls:\n%s", style.FgGreen.Sprint(remote.Name), strings.Join(remote.Urls, "\n")))
|
2020-03-29 05:34:17 +02:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
remotes, err := gui.git.Loaders.Remotes.GetRemotes()
|
2019-11-16 07:38:38 +02:00
|
|
|
if err != nil {
|
2022-01-16 05:46:53 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.PostRefreshUpdate(gui.mustContextForContextKey(types.ContextKey(gui.Views.Branches.Context)))
|
2019-12-07 07:20:22 +02:00
|
|
|
}
|