From bea2ae5ff53d16305c3f47ed5dfbc0b4d1d56b05 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Tue, 11 Aug 2020 21:38:59 +1000 Subject: [PATCH] stop pulling in general --- pkg/commands/git.go | 10 ------- pkg/gui/branches_panel.go | 7 ++--- pkg/gui/files_panel.go | 59 ++++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 89c903cc5..4bfd50437 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -510,16 +510,6 @@ func (c *GitCommand) AmendHead() (*exec.Cmd, error) { return nil, c.OSCommand.RunCommand(command) } -// Pull pulls from repo -func (c *GitCommand) Pull(args string, promptUserForCredential func(string) string) error { - return c.OSCommand.DetectUnamePass("git pull --no-edit --rebase ", promptUserForCredential) -} - -// 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, promptUserForCredential func(string) string) error { forceFlag := "" diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index eedbb619c..042613330 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -399,11 +399,8 @@ func (gui *Gui) handleFastForward(g *gocui.Gui, v *gocui.View) error { _ = gui.createLoaderPanel(gui.g, v, message) if gui.State.Panels.Branches.SelectedLine == 0 { - if err := gui.GitCommand.PullWithoutPasswordCheck("--ff-only"); err != nil { - _ = gui.surfaceError(err) - return - } - _ = gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + _ = gui.pullWithMode("ff-only", PullFilesOptions{}) + return } else { if err := gui.GitCommand.FastForward(branch.Name, remoteName, remoteBranchName); err != nil { _ = gui.surfaceError(err) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 0085ebf5a..49b5150ef 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -476,40 +476,41 @@ func (gui *Gui) pullFiles(opts PullFilesOptions) error { return err } - strategy := gui.Config.GetUserConfig().GetString("git.pull.mode") + mode := gui.Config.GetUserConfig().GetString("git.pull.mode") - go func() { - err := gui.GitCommand.Fetch( - commands.FetchOptions{ - PromptUserForCredential: gui.promptUserForCredential, - RemoteName: opts.RemoteName, - BranchName: opts.BranchName, - }, - ) - gui.HandleCredentialsPopup(err) - if err != nil { - _ = gui.refreshSidePanels(refreshOptions{mode: ASYNC}) - return - } - - switch strategy { - case "rebase": - err := gui.GitCommand.RebaseBranch("FETCH_HEAD") - _ = gui.handleGenericMergeCommandResult(err) - case "merge": - err := gui.GitCommand.Merge("FETCH_HEAD", commands.MergeOpts{}) - _ = gui.handleGenericMergeCommandResult(err) - case "ff-only": - err := gui.GitCommand.Merge("FETCH_HEAD", commands.MergeOpts{FastForwardOnly: true}) - _ = gui.handleGenericMergeCommandResult(err) - default: - _ = gui.createErrorPanel(fmt.Sprintf("git pull strategy '%s' unrecognised", strategy)) - } - }() + go gui.pullWithMode(mode, opts) return nil } +func (gui *Gui) pullWithMode(mode string, opts PullFilesOptions) error { + err := gui.GitCommand.Fetch( + commands.FetchOptions{ + PromptUserForCredential: gui.promptUserForCredential, + RemoteName: opts.RemoteName, + BranchName: opts.BranchName, + }, + ) + gui.HandleCredentialsPopup(err) + if err != nil { + return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + } + + switch mode { + case "rebase": + err := gui.GitCommand.RebaseBranch("FETCH_HEAD") + return gui.handleGenericMergeCommandResult(err) + case "merge": + err := gui.GitCommand.Merge("FETCH_HEAD", commands.MergeOpts{}) + return gui.handleGenericMergeCommandResult(err) + case "ff-only": + err := gui.GitCommand.Merge("FETCH_HEAD", commands.MergeOpts{FastForwardOnly: true}) + return gui.handleGenericMergeCommandResult(err) + default: + return gui.createErrorPanel(fmt.Sprintf("git pull mode '%s' unrecognised", mode)) + } +} + 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