diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 0b212b1ef..1b4ec57f5 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -328,8 +328,8 @@ func (c *GitCommand) Commit(message string, amend bool) (*exec.Cmd, error) { } // Pull pulls from repo -func (c *GitCommand) Pull() error { - return c.OSCommand.RunCommand("git pull --no-edit") +func (c *GitCommand) Pull(ask func(string) string) error { + return c.OSCommand.DetectUnamePass("git pull --no-edit", ask) } // Push pushes to a branch diff --git a/pkg/commands/os.go b/pkg/commands/os.go index dca0c8eae..8a36d9851 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -87,9 +87,8 @@ func (c *OSCommand) DetectUnamePass(command string, ask func(string) string) err return "" }) if err != nil { - errorCode := err.Error() - if errorCode == "exit status 128" { - errMessage = errorCode + if errorCode := err.Error(); strings.Contains("exit status 128", errorCode) { + errMessage = "exit status 128" } return errors.New(errMessage) } diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index 3f2225a7b..13ff074bc 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -84,6 +84,7 @@ func (gui *Gui) waitForPassUname(g *gocui.Gui, currentView *gocui.View, passOrUn // wait for username/passwords input waitForGroup.Wait() + _ = gui.switchFocus(g, pushPassUnameView, currentView) return unamePassMessage } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 5c957d217..cdd619425 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -341,31 +341,50 @@ func (gui *Gui) refreshFiles(g *gocui.Gui) error { } func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error { - gui.createMessagePanel(g, v, "", gui.Tr.SLocalize("PullWait")) + if err := gui.createMessagePanel(gui.g, v, "", gui.Tr.SLocalize("PullWait")); err != nil { + return err + } go func() { - if err := gui.GitCommand.Pull(); err != nil { - gui.createErrorPanel(g, err.Error()) + unamePassOpend := false + err := gui.GitCommand.Pull(func(passOrUname string) string { + unamePassOpend = true + return gui.waitForPassUname(g, v, passOrUname) + }) + if unamePassOpend { + _, _ = g.SetViewOnBottom("pushPassUname") + _ = g.DeleteView("pushPassUname") + } + if err != nil { + errMessage := err.Error() + if errMessage == "exit status 128" { + errMessage = gui.Tr.SLocalize("PassUnameWrong") + } + gui.createErrorPanel(gui.g, errMessage) } else { - gui.closeConfirmationPrompt(g) - gui.refreshCommits(g) - gui.refreshStatus(g) + _ = gui.closeConfirmationPrompt(gui.g) + _ = gui.refreshCommits(gui.g) + _ = gui.refreshStatus(gui.g) } gui.refreshFiles(g) }() return nil } -func (gui *Gui) pushWithForceFlag(g *gocui.Gui, currentView *gocui.View, force bool) error { - if err := gui.createMessagePanel(gui.g, currentView, "", gui.Tr.SLocalize("PushWait")); err != nil { +func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool) error { + if err := gui.createMessagePanel(gui.g, v, "", gui.Tr.SLocalize("PushWait")); err != nil { return err } go func() { + unamePassOpend := false branchName := gui.State.Branches[0].Name err := gui.GitCommand.Push(branchName, force, func(passOrUname string) string { - return gui.waitForPassUname(g, currentView, passOrUname) + unamePassOpend = true + return gui.waitForPassUname(g, v, passOrUname) }) - _, _ = g.SetViewOnBottom("pushPassUname") - _ = g.DeleteView("pushPassUname") + if unamePassOpend { + _, _ = g.SetViewOnBottom("pushPassUname") + _ = g.DeleteView("pushPassUname") + } if err != nil { errMessage := err.Error() if errMessage == "exit status 128" {