diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-12-07 18:52:31 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2018-12-08 11:51:47 +1100 |
commit | ff856b763033a241370bfde98d7386b43b7d0893 (patch) | |
tree | 9818a3b50f815051a309882e6c48c482bfd7ef3a /pkg/gui/branches_panel.go | |
parent | ca3afa2a3905365ec79624e0c9b08865e9ab27ae (diff) |
fetching branches without checking out
Diffstat (limited to 'pkg/gui/branches_panel.go')
-rw-r--r-- | pkg/gui/branches_panel.go | 70 |
1 files changed, 57 insertions, 13 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 809deaa7d..a0e3448f6 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -7,7 +7,6 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/git" - "github.com/jesseduffield/lazygit/pkg/utils" ) // list panel functions @@ -32,6 +31,9 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error { return err } go func() { + _ = gui.RenderSelectedBranchUpstreamDifferences() + }() + go func() { graph, err := gui.GitCommand.GetBranchGraph(branch.Name) if err != nil && strings.HasPrefix(graph, "fatal: ambiguous argument") { graph = gui.Tr.SLocalize("NoTrackingThisBranch") @@ -41,14 +43,23 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error { return nil } +func (gui *Gui) RenderSelectedBranchUpstreamDifferences() error { + // here we tell the selected branch that it is selected. + // this is necessary for showing stats on a branch that is selected, because + // the displaystring function doesn't have access to gui state to tell if it's selected + for i, branch := range gui.State.Branches { + branch.Selected = i == gui.State.Panels.Branches.SelectedLine + } + + branch := gui.getSelectedBranch() + branch.Pushables, branch.Pullables = gui.GitCommand.GetBranchUpstreamDifferenceCount(branch.Name) + return gui.renderListPanel(gui.getBranchesView(gui.g), gui.State.Branches) +} + // gui.refreshStatus is called at the end of this because that's when we can // be sure there is a state.Branches array to pick the current branch from func (gui *Gui) refreshBranches(g *gocui.Gui) error { g.Update(func(g *gocui.Gui) error { - v, err := g.View("branches") - if err != nil { - panic(err) - } builder, err := git.NewBranchListBuilder(gui.Log, gui.GitCommand) if err != nil { return err @@ -56,16 +67,13 @@ func (gui *Gui) refreshBranches(g *gocui.Gui) error { gui.State.Branches = builder.Build() gui.refreshSelectedLine(&gui.State.Panels.Branches.SelectedLine, len(gui.State.Branches)) - - v.Clear() - list, err := utils.RenderList(gui.State.Branches) - if err != nil { + if err := gui.resetOrigin(gui.getBranchesView(gui.g)); err != nil { + return err + } + if err := gui.RenderSelectedBranchUpstreamDifferences(); err != nil { return err } - fmt.Fprint(v, list) - - gui.resetOrigin(v) return gui.refreshStatus(g) }) return nil @@ -74,7 +82,6 @@ func (gui *Gui) refreshBranches(g *gocui.Gui) error { func (gui *Gui) handleBranchesNextLine(g *gocui.Gui, v *gocui.View) error { panelState := gui.State.Panels.Branches gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.Branches), false) - return gui.handleBranchSelect(gui.g, v) } @@ -99,7 +106,10 @@ func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error { if err := gui.createErrorPanel(g, err.Error()); err != nil { return err } + } else { + gui.State.Panels.Branches.SelectedLine = 0 } + return gui.refreshSidePanels(g) } @@ -213,3 +223,37 @@ func (gui *Gui) handleMerge(g *gocui.Gui, v *gocui.View) error { } return nil } + +func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error { + branch := gui.getSelectedBranch() + if branch == nil { + return nil + } + if branch.Pushables == "" { + return nil + } + if branch.Pushables == "?" { + return gui.createErrorPanel(gui.g, "Cannot fast-forward a branch with no upstream") + } + if branch.Pushables != "0" { + return gui.createErrorPanel(gui.g, "Cannot fast-forward a branch with commits to push") + } + upstream := "origin" // hardcoding for now + message := gui.Tr.TemplateLocalize( + "Fetching", + Teml{ + "from": fmt.Sprintf("%s/%s", upstream, branch.Name), + "to": branch.Name, + }, + ) + go func() { + _ = gui.createMessagePanel(gui.g, v, "", message) + if err := gui.GitCommand.FastForward(branch.Name); err != nil { + _ = gui.createErrorPanel(gui.g, err.Error()) + } else { + _ = gui.closeConfirmationPrompt(gui.g) + _ = gui.RenderSelectedBranchUpstreamDifferences() + } + }() + return nil +} |