diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-06 22:05:18 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-07 10:52:51 +1100 |
commit | 0d3e5e6a1dc7d131cd714a260b4f365380a033c6 (patch) | |
tree | fd857cfd3f65c63119c8eace5917374818abf26e | |
parent | 93729ba61bc374c1ffa3d8a521ff75796fb899a2 (diff) |
simplify fetch
-rw-r--r-- | pkg/gui/branches_panel.go | 3 | ||||
-rw-r--r-- | pkg/gui/global_handlers.go | 23 | ||||
-rw-r--r-- | pkg/gui/gui.go | 4 |
3 files changed, 19 insertions, 11 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 7481104cf..dbb2ae8da 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -127,8 +127,9 @@ func (gui *Gui) handleGitFetch() error { if err := gui.createLoaderPanel(gui.Tr.FetchWait); err != nil { return err } + go utils.Safe(func() { - err := gui.fetch(true, "Fetch") + err := gui.fetch() gui.handleCredentialsPopup(err) _ = gui.refreshSidePanels(refreshOptions{mode: ASYNC}) }) diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index 8b437e6e0..68f2b6402 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -210,19 +210,15 @@ func (gui *Gui) handleMouseDownSecondary() error { return nil } -func (gui *Gui) fetch(canPromptForCredentials bool, action string) (err error) { +func (gui *Gui) fetch() (err error) { gui.Mutexes.FetchMutex.Lock() defer gui.Mutexes.FetchMutex.Unlock() - fetchOpts := commands.FetchOptions{} - if canPromptForCredentials { - gui.logAction(action) - fetchOpts.PromptUserForCredential = gui.promptUserForCredential - } + gui.logAction("Fetch") - err = gui.GitCommand.Fetch(fetchOpts) + err = gui.GitCommand.Fetch(commands.FetchOptions{PromptUserForCredential: gui.promptUserForCredential}) - if canPromptForCredentials && err != nil && strings.Contains(err.Error(), "exit status 128") { + if err != nil && strings.Contains(err.Error(), "exit status 128") { _ = gui.createErrorPanel(gui.Tr.PassUnameWrong) } @@ -231,6 +227,17 @@ func (gui *Gui) fetch(canPromptForCredentials bool, action string) (err error) { return err } +func (gui *Gui) backgroundFetch() (err error) { + gui.Mutexes.FetchMutex.Lock() + defer gui.Mutexes.FetchMutex.Unlock() + + err = gui.GitCommand.Fetch(commands.FetchOptions{}) + + _ = gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, COMMITS, REMOTES, TAGS}, mode: ASYNC}) + + return err +} + func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error { // important to note that this assumes we've selected an item in a side context itemId := gui.getSideContextSelectedItemId() diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 456a62a6c..9b4279f29 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -718,7 +718,7 @@ func (gui *Gui) startBackgroundFetch() { if !isNew { time.After(time.Duration(userConfig.Refresher.FetchInterval) * time.Second) } - err := gui.fetch(false, "") + err := gui.backgroundFetch() if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew { _ = gui.ask(askOpts{ title: gui.Tr.NoAutomaticGitFetchTitle, @@ -726,7 +726,7 @@ func (gui *Gui) startBackgroundFetch() { }) } else { gui.goEvery(time.Second*time.Duration(userConfig.Refresher.FetchInterval), gui.stopChan, func() error { - err := gui.fetch(false, "") + err := gui.backgroundFetch() gui.render() return err }) |