diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-16 17:35:59 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-21 22:07:14 +1100 |
commit | 986abc1e45e314e68beb7c0ba92804e60c99310b (patch) | |
tree | 788b7f689a051c414bec231489279f0f41a949bd /pkg/gui/remote_branches_panel.go | |
parent | 61dac10bb94874800d7b955c875cbcc3b3efa546 (diff) |
support viewing a remote branch
Diffstat (limited to 'pkg/gui/remote_branches_panel.go')
-rw-r--r-- | pkg/gui/remote_branches_panel.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go new file mode 100644 index 000000000..93978bc3c --- /dev/null +++ b/pkg/gui/remote_branches_panel.go @@ -0,0 +1,69 @@ +package gui + +import ( + "fmt" + "strings" + + "github.com/fatih/color" + "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazygit/pkg/commands" + "github.com/jesseduffield/lazygit/pkg/utils" +) + +// list panel functions + +func (gui *Gui) getSelectedRemoteBranch() *commands.Branch { + selectedLine := gui.State.Panels.RemoteBranches.SelectedLine + if selectedLine == -1 || len(gui.State.RemoteBranches) == 0 { + return nil + } + + return gui.State.RemoteBranches[selectedLine] +} + +func (gui *Gui) handleRemoteBranchesClick(g *gocui.Gui, v *gocui.View) error { + itemCount := len(gui.State.RemoteBranches) + handleSelect := gui.handleRemoteBranchSelect + selectedLine := &gui.State.Panels.RemoteBranches.SelectedLine + + return gui.handleClick(v, itemCount, selectedLine, handleSelect) +} + +func (gui *Gui) handleRemoteBranchSelect(g *gocui.Gui, v *gocui.View) error { + if gui.popupPanelFocused() { + return nil + } + + gui.State.SplitMainPanel = false + + if _, err := gui.g.SetCurrentView(v.Name()); err != nil { + return err + } + + gui.getMainView().Title = "Remote Branch" + + remote := gui.getSelectedRemote() + remoteBranch := gui.getSelectedRemoteBranch() + if remoteBranch == nil { + return gui.renderString(g, "main", "No branches for this remote") + } + + gui.focusPoint(0, gui.State.Panels.Menu.SelectedLine, gui.State.MenuItemCount, v) + if err := gui.focusPoint(0, gui.State.Panels.RemoteBranches.SelectedLine, len(gui.State.RemoteBranches), v); err != nil { + return err + } + + go func() { + graph, err := gui.GitCommand.GetBranchGraph(fmt.Sprintf("%s/%s", remote.Name, remoteBranch.Name)) + if err != nil && strings.HasPrefix(graph, "fatal: ambiguous argument") { + graph = gui.Tr.SLocalize("NoTrackingThisBranch") + } + _ = gui.renderString(g, "main", fmt.Sprintf("%s/%s\n\n%s", utils.ColoredString(remote.Name, color.FgRed), utils.ColoredString(remoteBranch.Name, color.FgGreen), graph)) + }() + + return nil +} + +func (gui *Gui) handleRemoteBranchesEscape(g *gocui.Gui, v *gocui.View) error { + return gui.switchBranchesPanelContext("remotes") +} |