diff options
author | mjarkk <mkopenga@gmail.com> | 2018-11-25 13:15:36 +0100 |
---|---|---|
committer | mjarkk <mkopenga@gmail.com> | 2018-11-25 13:15:36 +0100 |
commit | 9da1382e09c2e3c43c8e979e26d7614c139d12dd (patch) | |
tree | 3ede904373f36aa583f27a8155684c3468f3f174 /pkg/gui/gui.go | |
parent | adfc00bcdcaaaab2e1102509d604017c74e97fba (diff) |
Added credentials popup
Diffstat (limited to 'pkg/gui/gui.go')
-rw-r--r-- | pkg/gui/gui.go | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 6d42aee48..52826c4d7 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -11,10 +11,12 @@ import ( "os" "os/exec" "strings" + "sync" "time" // "strings" + "github.com/fatih/color" "github.com/golang-collections/collections/stack" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands" @@ -350,9 +352,50 @@ func (gui *Gui) promptAnonymousReporting() error { } func (gui *Gui) fetch(g *gocui.Gui) error { - gui.GitCommand.Fetch() + err := gui.GitCommand.Fetch(func(passOrUname string) string { + if !gui.GitCommand.SavedCredentials.HasAsked { + var wg sync.WaitGroup + wg.Add(1) + gui.GitCommand.SavedCredentials.HasAsked = true + close := func(g *gocui.Gui, v *gocui.View) error { + wg.Done() + return nil + } + _ = gui.createConfirmationPanel( + g, + g.CurrentView(), + gui.Tr.SLocalize("RepoRequiresCredentialsTitle"), + gui.Tr.SLocalize("RepoRequiresCredentialsBody"), + close, + close, + ) + wg.Wait() + } + return gui.waitForPassUname(gui.g, gui.g.CurrentView(), passOrUname) + }, false) + + var reTryErr error + if err != nil && strings.Contains(err.Error(), "exit status 128") { + var wg sync.WaitGroup + wg.Add(1) + + currentView := g.CurrentView() + colorFunction := color.New(color.FgRed).SprintFunc() + coloredMessage := colorFunction(strings.TrimSpace(gui.Tr.SLocalize("PassUnameWrong"))) + close := func(g *gocui.Gui, v *gocui.View) error { + wg.Done() + return nil + } + _ = gui.createConfirmationPanel(g, currentView, gui.Tr.SLocalize("Error"), coloredMessage, close, close) + wg.Wait() + reTryErr = gui.fetch(g) + } + gui.refreshStatus(g) - return nil + if reTryErr != nil { + return reTryErr + } + return err } func (gui *Gui) updateLoader(g *gocui.Gui) error { @@ -407,7 +450,12 @@ func (gui *Gui) Run() error { return err } - gui.goEvery(g, time.Second*60, gui.fetch) + go func() { + err := gui.fetch(g) + if err == nil { + gui.goEvery(g, time.Second*10, gui.fetch) + } + }() gui.goEvery(g, time.Second*10, gui.refreshFiles) gui.goEvery(g, time.Millisecond*50, gui.updateLoader) gui.goEvery(g, time.Millisecond*50, gui.renderAppStatus) |