From 66e6369c284e96ed5af5b6d178b9270f59b99e56 Mon Sep 17 00:00:00 2001
From: Jesse Duffield <jessedduffield@gmail.com>
Date: Tue, 18 Feb 2020 20:53:46 +1100
Subject: [PATCH] allow fastforwarding the current branch

---
 pkg/commands/git.go       |  5 +++++
 pkg/gui/branches_panel.go | 13 ++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/pkg/commands/git.go b/pkg/commands/git.go
index ca0c83501..7f9849041 100644
--- a/pkg/commands/git.go
+++ b/pkg/commands/git.go
@@ -408,6 +408,11 @@ func (c *GitCommand) Pull(args string, ask func(string) string) error {
 	return c.OSCommand.DetectUnamePass("git pull --no-edit "+args, ask)
 }
 
+// PullWithoutPasswordCheck assumes that the pull will not prompt the user for a password
+func (c *GitCommand) PullWithoutPasswordCheck(args string) error {
+	return c.OSCommand.RunCommand("git pull --no-edit " + args)
+}
+
 // Push pushes to a branch
 func (c *GitCommand) Push(branchName string, force bool, upstream string, args string, ask func(string) string) error {
 	forceFlag := ""
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index e4e7a432f..a683a2342 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -372,12 +372,19 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error {
 	go func() {
 		_ = gui.createLoaderPanel(gui.g, v, message)
 
-		if err := gui.GitCommand.FastForward(branch.Name, remoteName, remoteBranchName); err != nil {
-			_ = gui.createErrorPanel(gui.g, err.Error())
+		if gui.State.Panels.Branches.SelectedLine == 0 {
+			if err := gui.GitCommand.PullWithoutPasswordCheck("--ff-only"); err != nil {
+				_ = gui.createErrorPanel(gui.g, err.Error())
+			}
+			_ = gui.refreshSidePanels(gui.g)
 		} else {
-			_ = gui.closeConfirmationPrompt(gui.g, true)
+			if err := gui.GitCommand.FastForward(branch.Name, remoteName, remoteBranchName); err != nil {
+				_ = gui.createErrorPanel(gui.g, err.Error())
+			}
 			_ = gui.RenderSelectedBranchUpstreamDifferences()
 		}
+
+		_ = gui.closeConfirmationPrompt(gui.g, true)
 	}()
 	return nil
 }