1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-08 22:36:49 +02:00

Cleanup background fetch (#4084)

This commit is contained in:
Stefan Haller
2024-12-01 10:47:43 +01:00
committed by GitHub
4 changed files with 14 additions and 28 deletions

View File

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

View File

@@ -108,8 +108,6 @@ type Gui struct {
PopupHandler types.IPopupHandler
IsNewRepo bool
IsRefreshingFiles bool
// we use this to decide whether we'll return to the original directory that

View File

@@ -21,8 +21,7 @@ func (gui *Gui) updateRecentRepoList() error {
if err != nil {
return err
}
known, recentRepos := newRecentReposList(recentRepos, currentRepo)
gui.IsNewRepo = known
recentRepos = newRecentReposList(recentRepos, currentRepo)
// TODO: migrate this file to use forward slashes on all OSes for consistency
// (windows uses backslashes at the moment)
gui.c.GetAppState().RecentRepos = recentRepos
@@ -30,8 +29,7 @@ func (gui *Gui) updateRecentRepoList() error {
}
// newRecentReposList returns a new repo list with a new entry but only when it doesn't exist yet
func newRecentReposList(recentRepos []string, currentRepo string) (bool, []string) {
isNew := true
func newRecentReposList(recentRepos []string, currentRepo string) []string {
newRepos := []string{currentRepo}
for _, repo := range recentRepos {
if repo != currentRepo {
@@ -39,9 +37,7 @@ func newRecentReposList(recentRepos []string, currentRepo string) (bool, []strin
continue
}
newRepos = append(newRepos, repo)
} else {
isNew = false
}
}
return isNew, newRepos
return newRepos
}

View File

@@ -249,8 +249,6 @@ type TranslationSet struct {
NoBranchOnRemote string
Fetch string
FetchTooltip string
NoAutomaticGitFetchTitle string
NoAutomaticGitFetchBody string
FileEnter string
FileEnterTooltip string
FileStagingRequirements string
@@ -1235,8 +1233,6 @@ func EnglishTranslationSet() *TranslationSet {
NoBranchOnRemote: `This branch doesn't exist on remote. You need to push it to remote first.`,
Fetch: `Fetch`,
FetchTooltip: "Fetch changes from remote.",
NoAutomaticGitFetchTitle: `No automatic git fetch`,
NoAutomaticGitFetchBody: `Lazygit can't use "git fetch" in a private repo; use 'f' in the files panel to run "git fetch" manually`,
FileEnter: `Stage lines / Collapse directory`,
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.",
FileStagingRequirements: `Can only stage individual lines for tracked files`,