mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-07 07:19:57 +02:00
Simplify startBackgroundFetch
This code had a lot of logic that (fortunately) didn't work because it was buggy: - it was supposed to wait for the auto-fetch delay before fetching for the first time in case we start with a repo that we had open in a previous session (i.e. that appears in the recent repos list). This code actually ran always, not just for known repos, because the IsNewRepo flag is only set later, after this function runs. Fortunately, the code didn't work, because time.After starts a timer but doesn't wait for it (to do that, it would have to be `<-time.After`). - if the first fetch fails with error 128, it was supposed to show an error message and not start the background fetch loop. Fortunately, this didn't work because 1) it was guarded by isNew which is always false here, and 2) because git's error message in this case is actually "exit code: 128", not "exit status 128" (maybe this has changed in git at some point). I find both of these undesirable. Whenever I open a repo I want an auto-fetch to be triggered immediately to get my branch information up to date as quickly as possible. And if the initial fetch fails (e.g. because one of my remotes is offline or doesn't exist any more), then that's no reason not to start the auto-fetch loop anyway. So let's simplify the code to do what it did before, but with much fewer lines of code.
This commit is contained in:
parent
62e31efd0f
commit
59303981f9
@ -3,7 +3,6 @@ package gui
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
@ -76,21 +75,18 @@ func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
|
||||
func (self *BackgroundRoutineMgr) startBackgroundFetch() {
|
||||
self.gui.waitForIntro.Wait()
|
||||
|
||||
isNew := self.gui.IsNewRepo
|
||||
fetch := func() error {
|
||||
err := self.backgroundFetch()
|
||||
self.gui.c.Render()
|
||||
return err
|
||||
}
|
||||
|
||||
// We want an immediate fetch at startup, and since goEvery starts by
|
||||
// waiting for the interval, we need to trigger one manually first
|
||||
_ = fetch()
|
||||
|
||||
userConfig := self.gui.UserConfig()
|
||||
if !isNew {
|
||||
time.After(time.Duration(userConfig.Refresher.FetchInterval) * time.Second)
|
||||
}
|
||||
err := self.backgroundFetch()
|
||||
if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
|
||||
self.gui.c.Alert(self.gui.c.Tr.NoAutomaticGitFetchTitle, self.gui.c.Tr.NoAutomaticGitFetchBody)
|
||||
} else {
|
||||
self.goEvery(time.Second*time.Duration(userConfig.Refresher.FetchInterval), self.gui.stopChan, func() error {
|
||||
err := self.backgroundFetch()
|
||||
self.gui.c.Render()
|
||||
return err
|
||||
})
|
||||
}
|
||||
self.goEvery(time.Second*time.Duration(userConfig.Refresher.FetchInterval), self.gui.stopChan, fetch)
|
||||
}
|
||||
|
||||
func (self *BackgroundRoutineMgr) startBackgroundFilesRefresh(refreshInterval int) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user