From b42202ea1c82d93d828fec38ddfdc073c041dec9 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 17 Nov 2019 14:28:38 +1100 Subject: [PATCH] better fast forward --- pkg/commands/git.go | 10 ++++------ pkg/gui/branches_panel.go | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 912483b84..c2e12491d 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -272,12 +272,11 @@ func (c *GitCommand) ResetAndClean() error { } func (c *GitCommand) GetCurrentBranchUpstreamDifferenceCount() (string, string) { - return c.GetCommitDifferences("HEAD", "@{u}") + return c.GetCommitDifferences("HEAD", "HEAD@{u}") } func (c *GitCommand) GetBranchUpstreamDifferenceCount(branchName string) (string, string) { - upstream := "origin" // hardcoded for now - return c.GetCommitDifferences(branchName, fmt.Sprintf("%s/%s", upstream, branchName)) + return c.GetCommitDifferences(branchName, branchName+"@{u}") } // GetCommitDifferences checks how many pushables/pullables there are for the @@ -643,9 +642,8 @@ func (c *GitCommand) ApplyPatch(patch string, flags ...string) error { return c.OSCommand.RunCommand(fmt.Sprintf("git apply %s %s", flagStr, c.OSCommand.Quote(filepath))) } -func (c *GitCommand) FastForward(branchName string) error { - upstream := "origin" // hardcoding for now - return c.OSCommand.RunCommand(fmt.Sprintf("git fetch %s %s:%s", upstream, branchName, branchName)) +func (c *GitCommand) FastForward(branchName string, remoteName string, remoteBranchName string) error { + return c.OSCommand.RunCommand(fmt.Sprintf("git fetch %s %s:%s", remoteName, remoteBranchName, branchName)) } func (c *GitCommand) RunSkipEditorCommand(command string) error { diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index c3fd37f26..28f16562a 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -342,17 +342,27 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error { if branch.Pushables != "0" { return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("FwdCommitsToPush")) } - upstream := "origin" // hardcoding for now + + upstream, err := gui.GitCommand.GetUpstreamForBranch(branch.Name) + if err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + + split := strings.Split(upstream, "/") + remoteName := split[0] + remoteBranchName := strings.Join(split[1:], "/") + message := gui.Tr.TemplateLocalize( "Fetching", Teml{ - "from": fmt.Sprintf("%s/%s", upstream, branch.Name), + "from": fmt.Sprintf("%s/%s", remoteName, remoteBranchName), "to": branch.Name, }, ) go func() { _ = gui.createLoaderPanel(gui.g, v, message) - if err := gui.GitCommand.FastForward(branch.Name); err != nil { + + if err := gui.GitCommand.FastForward(branch.Name, remoteName, remoteBranchName); err != nil { _ = gui.createErrorPanel(gui.g, err.Error()) } else { _ = gui.closeConfirmationPrompt(gui.g, true)