Skip to content

Commit a50712b

Browse files
authored
Cleanup background fetch (#4084)
2 parents 62e31ef + 64cebfc commit a50712b

File tree

4 files changed

+14
-28
lines changed

4 files changed

+14
-28
lines changed

pkg/gui/background.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gui
33
import (
44
"fmt"
55
"runtime"
6-
"strings"
76
"time"
87

98
"github.com/jesseduffield/gocui"
@@ -76,21 +75,18 @@ func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
7675
func (self *BackgroundRoutineMgr) startBackgroundFetch() {
7776
self.gui.waitForIntro.Wait()
7877

79-
isNew := self.gui.IsNewRepo
80-
userConfig := self.gui.UserConfig()
81-
if !isNew {
82-
time.After(time.Duration(userConfig.Refresher.FetchInterval) * time.Second)
83-
}
84-
err := self.backgroundFetch()
85-
if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
86-
self.gui.c.Alert(self.gui.c.Tr.NoAutomaticGitFetchTitle, self.gui.c.Tr.NoAutomaticGitFetchBody)
87-
} else {
88-
self.goEvery(time.Second*time.Duration(userConfig.Refresher.FetchInterval), self.gui.stopChan, func() error {
89-
err := self.backgroundFetch()
90-
self.gui.c.Render()
91-
return err
92-
})
78+
fetch := func() error {
79+
err := self.backgroundFetch()
80+
self.gui.c.Render()
81+
return err
9382
}
83+
84+
// We want an immediate fetch at startup, and since goEvery starts by
85+
// waiting for the interval, we need to trigger one manually first
86+
_ = fetch()
87+
88+
userConfig := self.gui.UserConfig()
89+
self.goEvery(time.Second*time.Duration(userConfig.Refresher.FetchInterval), self.gui.stopChan, fetch)
9490
}
9591

9692
func (self *BackgroundRoutineMgr) startBackgroundFilesRefresh(refreshInterval int) {

pkg/gui/gui.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ type Gui struct {
108108

109109
PopupHandler types.IPopupHandler
110110

111-
IsNewRepo bool
112-
113111
IsRefreshingFiles bool
114112

115113
// we use this to decide whether we'll return to the original directory that

pkg/gui/recent_repos_panel.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,23 @@ func (gui *Gui) updateRecentRepoList() error {
2121
if err != nil {
2222
return err
2323
}
24-
known, recentRepos := newRecentReposList(recentRepos, currentRepo)
25-
gui.IsNewRepo = known
24+
recentRepos = newRecentReposList(recentRepos, currentRepo)
2625
// TODO: migrate this file to use forward slashes on all OSes for consistency
2726
// (windows uses backslashes at the moment)
2827
gui.c.GetAppState().RecentRepos = recentRepos
2928
return gui.c.SaveAppState()
3029
}
3130

3231
// newRecentReposList returns a new repo list with a new entry but only when it doesn't exist yet
33-
func newRecentReposList(recentRepos []string, currentRepo string) (bool, []string) {
34-
isNew := true
32+
func newRecentReposList(recentRepos []string, currentRepo string) []string {
3533
newRepos := []string{currentRepo}
3634
for _, repo := range recentRepos {
3735
if repo != currentRepo {
3836
if _, err := os.Stat(filepath.Join(repo, ".git")); err != nil {
3937
continue
4038
}
4139
newRepos = append(newRepos, repo)
42-
} else {
43-
isNew = false
4440
}
4541
}
46-
return isNew, newRepos
42+
return newRepos
4743
}

pkg/i18n/english.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ type TranslationSet struct {
249249
NoBranchOnRemote string
250250
Fetch string
251251
FetchTooltip string
252-
NoAutomaticGitFetchTitle string
253-
NoAutomaticGitFetchBody string
254252
FileEnter string
255253
FileEnterTooltip string
256254
FileStagingRequirements string
@@ -1235,8 +1233,6 @@ func EnglishTranslationSet() *TranslationSet {
12351233
NoBranchOnRemote: `This branch doesn't exist on remote. You need to push it to remote first.`,
12361234
Fetch: `Fetch`,
12371235
FetchTooltip: "Fetch changes from remote.",
1238-
NoAutomaticGitFetchTitle: `No automatic git fetch`,
1239-
NoAutomaticGitFetchBody: `Lazygit can't use "git fetch" in a private repo; use 'f' in the files panel to run "git fetch" manually`,
12401236
FileEnter: `Stage lines / Collapse directory`,
12411237
FileEnterTooltip: "If the selected item is a file, focus the staging view so you can stage individual hunks/lines. If the selected item is a directory, collapse/expand it.",
12421238
FileStagingRequirements: `Can only stage individual lines for tracked files`,

0 commit comments

Comments
 (0)