diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index ebb31e17f..b6cc45664 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -130,23 +130,7 @@ func (gui *Gui) handleGitFetch(g *gocui.Gui, v *gocui.View) error { } go func() { unamePassOpend, err := gui.fetch(g, v, true) - if err != nil { - errMessage := err.Error() - if errMessage == "exit status 128" { - errMessage = gui.Tr.SLocalize("PassUnameWrong") - } - _ = gui.createErrorPanel(g, errMessage) - if unamePassOpend { - _ = g.DeleteView("credentials") - } - } else { - if unamePassOpend { - _ = g.DeleteView("credentials") - } - _ = gui.closeConfirmationPrompt(g) - _ = gui.refreshCommits(g) - _ = gui.refreshStatus(g) - } + gui.HandleCredentialsPopup(g, unamePassOpend, err) }() return nil } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 6e525e006..a89138161 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -388,24 +388,7 @@ func (gui *Gui) pullFiles(g *gocui.Gui, v *gocui.View) error { unamePassOpend = true return gui.waitForPassUname(g, v, passOrUname) }) - if err != nil { - errMessage := err.Error() - if errMessage == "exit status 128" { - errMessage = gui.Tr.SLocalize("PassUnameWrong") - } - _ = gui.createErrorPanel(g, errMessage) - if unamePassOpend { - _ = g.DeleteView("credentials") - } - } else { - if unamePassOpend { - _ = g.DeleteView("credentials") - } - _ = gui.closeConfirmationPrompt(g) - _ = gui.refreshCommits(g) - _ = gui.refreshStatus(g) - } - gui.refreshFiles(g) + gui.HandleCredentialsPopup(g, unamePassOpend, err) }() return nil } @@ -421,22 +404,7 @@ func (gui *Gui) pushWithForceFlag(g *gocui.Gui, v *gocui.View, force bool) error unamePassOpend = true return gui.waitForPassUname(g, v, passOrUname) }) - if err != nil { - errMessage := err.Error() - if errMessage == "exit status 128" { - errMessage = gui.Tr.SLocalize("PassUnameWrong") - } - _ = gui.createErrorPanel(g, errMessage) - if unamePassOpend { - _ = g.DeleteView("credentials") - } - } else { - if unamePassOpend { - _ = g.DeleteView("credentials") - } - _ = gui.closeConfirmationPrompt(g) - _ = gui.refreshSidePanels(g) - } + gui.HandleCredentialsPopup(g, unamePassOpend, err) }() return nil } diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 1046fb32e..298e0be7f 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -309,6 +309,26 @@ func (gui *Gui) resizeCurrentPopupPanel(g *gocui.Gui) error { return nil } +// HandleCredentialsPopup handles the views after executing a command that might ask for credentials +func (gui *Gui) HandleCredentialsPopup(g *gocui.Gui, popupOpened bool, cmdErr error) { + if cmdErr != nil { + errMessage := cmdErr.Error() + if errMessage == "exit status 128" { + errMessage = gui.Tr.SLocalize("PassUnameWrong") + } + _ = gui.createErrorPanel(g, errMessage) + if popupOpened { + _ = g.DeleteView("credentials") + } + } else { + if popupOpened { + _ = g.DeleteView("credentials") + } + _ = gui.closeConfirmationPrompt(g) + _ = gui.refreshSidePanels(g) + } +} + func (gui *Gui) resizePopupPanel(g *gocui.Gui, v *gocui.View) error { // If the confirmation panel is already displayed, just resize the width, // otherwise continue