summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-11-17 14:28:38 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-21 22:07:14 +1100
commitb42202ea1c82d93d828fec38ddfdc073c041dec9 (patch)
treec495aaf3ff26b1f12110a66381918cbde2f9f056
parent8347dcd67149e329d3c23c7453a59b12e2d5533d (diff)
better fast forward
-rw-r--r--pkg/commands/git.go10
-rw-r--r--pkg/gui/branches_panel.go16
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)