From c166c57c5da73f9243ac4b4bc7e38fd0b3fa0f46 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 28 Jan 2020 20:35:23 +1100 Subject: make use of branch config when pushing/pulling --- pkg/commands/git.go | 8 ++++---- pkg/commands/git_test.go | 2 +- pkg/gui/files_panel.go | 40 +++++++++++++++++++++++++++++++--------- 3 files changed, 36 insertions(+), 14 deletions(-) (limited to 'pkg') diff --git a/pkg/commands/git.go b/pkg/commands/git.go index fb4ddab79..b1bb9ee6e 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -404,12 +404,12 @@ func (c *GitCommand) AmendHead() (*exec.Cmd, error) { } // Pull pulls from repo -func (c *GitCommand) Pull(ask func(string) string) error { - return c.OSCommand.DetectUnamePass("git pull --no-edit", ask) +func (c *GitCommand) Pull(args string, ask func(string) string) error { + return c.OSCommand.DetectUnamePass("git pull --no-edit "+args, ask) } // Push pushes to a branch -func (c *GitCommand) Push(branchName string, force bool, upstream string, ask func(string) string) error { +func (c *GitCommand) Push(branchName string, force bool, upstream string, args string, ask func(string) string) error { forceFlag := "" if force { forceFlag = "--force-with-lease" @@ -420,7 +420,7 @@ func (c *GitCommand) Push(branchName string, force bool, upstream string, ask fu setUpstreamArg = "--set-upstream " + upstream } - cmd := fmt.Sprintf("git push --follow-tags %s %s", forceFlag, setUpstreamArg) + cmd := fmt.Sprintf("git push --follow-tags %s %s %s", forceFlag, setUpstreamArg, args) return c.OSCommand.DetectUnamePass(cmd, ask) } diff --git a/pkg/commands/git_test.go b/pkg/commands/git_test.go index ceaadc576..de9d2f996 100644 --- a/pkg/commands/git_test.go +++ b/pkg/commands/git_test.go @@ -1015,7 +1015,7 @@ func TestGitCommandPush(t *testing.T) { t.Run(s.testName, func(t *testing.T) { gitCmd := NewDummyGitCommand() gitCmd.OSCommand.command = s.command - err := gitCmd.Push("test", s.forcePush, "", func(passOrUname string) string { + err := gitCmd.Push("test", s.forcePush, "", "", func(passOrUname string) string { return "\n" }) s.test(err) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index a923d56e6..beb913c64 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -393,6 +393,17 @@ func (gui *Gui) handlePullFiles(g *gocui.Gui, v *gocui.View) error { return err } if pullables == "?" { + // see if we have this branch in our config with an upstream + conf, err := gui.GitCommand.Repo.Config() + if err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + for branchName, branch := range conf.Branches { + if branchName == currentBranchName { + return gui.pullFiles(v, fmt.Sprintf("%s %s", branch.Remote, branchName)) + } + } + return gui.createPromptPanel(g, v, gui.Tr.SLocalize("EnterUpstream"), "origin/"+currentBranchName, func(g *gocui.Gui, v *gocui.View) error { upstream := gui.trimmedContent(v) if err := gui.GitCommand.SetUpstreamBranch(upstream); err != nil { @@ -402,21 +413,21 @@ func (gui *Gui) handlePullFiles(g *gocui.Gui, v *gocui.View) error { } return gui.createErrorPanel(gui.g, errorMessage) } - return gui.pullFiles(v) + return gui.pullFiles(v, "") }) } - return gui.pullFiles(v) + return gui.pullFiles(v, "") } -func (gui *Gui) pullFiles(v *gocui.View) error { +func (gui *Gui) pullFiles(v *gocui.View, args string) error { if err := gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("PullWait")); err != nil { return err } go func() { unamePassOpend := false - err := gui.GitCommand.Pull(func(passOrUname string) string { + err := gui.GitCommand.Pull(args, func(passOrUname string) string { unamePassOpend = true return gui.waitForPassUname(gui.g, v, passOrUname) }) @@ -426,14 +437,14 @@ func (gui *Gui) pullFiles(v *gocui.View) error { return nil } -func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool, upstream string) error { +func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool, upstream string, args string) error { if err := gui.createLoaderPanel(gui.g, v, gui.Tr.SLocalize("PushWait")); err != nil { return err } go func() { unamePassOpend := false branchName := gui.getCheckedOutBranch().Name - err := gui.GitCommand.Push(branchName, force, upstream, func(passOrUname string) string { + err := gui.GitCommand.Push(branchName, force, upstream, args, func(passOrUname string) string { unamePassOpend = true return gui.waitForPassUname(g, v, passOrUname) }) @@ -451,14 +462,25 @@ func (gui *Gui) pushFiles(g *gocui.Gui, v *gocui.View) error { } if pullables == "?" { + // see if we have this branch in our config with an upstream + conf, err := gui.GitCommand.Repo.Config() + if err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + for branchName, branch := range conf.Branches { + if branchName == currentBranchName { + return gui.pushWithForceFlag(g, v, false, "", fmt.Sprintf("%s %s", branch.Remote, branchName)) + } + } + return gui.createPromptPanel(g, v, gui.Tr.SLocalize("EnterUpstream"), "origin "+currentBranchName, func(g *gocui.Gui, v *gocui.View) error { - return gui.pushWithForceFlag(g, v, false, gui.trimmedContent(v)) + return gui.pushWithForceFlag(g, v, false, gui.trimmedContent(v), "") }) } else if pullables == "0" { - return gui.pushWithForceFlag(g, v, false, "") + return gui.pushWithForceFlag(g, v, false, "", "") } return gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("ForcePush"), gui.Tr.SLocalize("ForcePushPrompt"), func(g *gocui.Gui, v *gocui.View) error { - return gui.pushWithForceFlag(g, v, true, "") + return gui.pushWithForceFlag(g, v, true, "", "") }, nil) } -- cgit v1.2.3