1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-26 09:00:57 +02:00

Removed a lot of duplicated code

This commit is contained in:
mjarkk 2018-12-10 08:22:52 +01:00
parent 8e3f5e19e0
commit 50f20de8f3
3 changed files with 23 additions and 51 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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