1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-10 22:42:00 +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 ( import (
"fmt" "fmt"
"runtime" "runtime"
"strings"
"time" "time"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
@@ -76,21 +75,18 @@ func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
func (self *BackgroundRoutineMgr) startBackgroundFetch() { func (self *BackgroundRoutineMgr) startBackgroundFetch() {
self.gui.waitForIntro.Wait() 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() userConfig := self.gui.UserConfig()
if !isNew { self.goEvery(time.Second*time.Duration(userConfig.Refresher.FetchInterval), self.gui.stopChan, fetch)
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
})
}
} }
func (self *BackgroundRoutineMgr) startBackgroundFilesRefresh(refreshInterval int) { func (self *BackgroundRoutineMgr) startBackgroundFilesRefresh(refreshInterval int) {

View File

@@ -108,8 +108,6 @@ type Gui struct {
PopupHandler types.IPopupHandler PopupHandler types.IPopupHandler
IsNewRepo bool
IsRefreshingFiles bool IsRefreshingFiles bool
// we use this to decide whether we'll return to the original directory that // 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 { if err != nil {
return err return err
} }
known, recentRepos := newRecentReposList(recentRepos, currentRepo) recentRepos = newRecentReposList(recentRepos, currentRepo)
gui.IsNewRepo = known
// TODO: migrate this file to use forward slashes on all OSes for consistency // TODO: migrate this file to use forward slashes on all OSes for consistency
// (windows uses backslashes at the moment) // (windows uses backslashes at the moment)
gui.c.GetAppState().RecentRepos = recentRepos 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 // 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) { func newRecentReposList(recentRepos []string, currentRepo string) []string {
isNew := true
newRepos := []string{currentRepo} newRepos := []string{currentRepo}
for _, repo := range recentRepos { for _, repo := range recentRepos {
if repo != currentRepo { if repo != currentRepo {
@@ -39,9 +37,7 @@ func newRecentReposList(recentRepos []string, currentRepo string) (bool, []strin
continue continue
} }
newRepos = append(newRepos, repo) newRepos = append(newRepos, repo)
} else {
isNew = false
} }
} }
return isNew, newRepos return newRepos
} }

View File

@@ -249,8 +249,6 @@ type TranslationSet struct {
NoBranchOnRemote string NoBranchOnRemote string
Fetch string Fetch string
FetchTooltip string FetchTooltip string
NoAutomaticGitFetchTitle string
NoAutomaticGitFetchBody string
FileEnter string FileEnter string
FileEnterTooltip string FileEnterTooltip string
FileStagingRequirements 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.`, NoBranchOnRemote: `This branch doesn't exist on remote. You need to push it to remote first.`,
Fetch: `Fetch`, Fetch: `Fetch`,
FetchTooltip: "Fetch changes from remote.", 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`, 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.", 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`, FileStagingRequirements: `Can only stage individual lines for tracked files`,