1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-31 14:24:25 +03:00

Not always git fetch

This commit is contained in:
mjarkk
2018-12-10 13:45:03 +01:00
parent 50f20de8f3
commit 76e9582739
3 changed files with 45 additions and 39 deletions

View File

@ -20,6 +20,7 @@ type AppConfig struct {
BuildSource string `long:"build-source" env:"BUILD_SOURCE" default:""` BuildSource string `long:"build-source" env:"BUILD_SOURCE" default:""`
UserConfig *viper.Viper UserConfig *viper.Viper
AppState *AppState AppState *AppState
IsNewRepo bool
} }
// AppConfigurer interface allows individual app config structs to inherit Fields // AppConfigurer interface allows individual app config structs to inherit Fields
@ -36,6 +37,8 @@ type AppConfigurer interface {
WriteToUserConfig(string, string) error WriteToUserConfig(string, string) error
SaveAppState() error SaveAppState() error
LoadAppState() error LoadAppState() error
SetIsNewRepo(bool)
GetIsNewRepo() bool
} }
// NewAppConfig makes a new app config // NewAppConfig makes a new app config
@ -54,6 +57,7 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
BuildSource: buildSource, BuildSource: buildSource,
UserConfig: userConfig, UserConfig: userConfig,
AppState: &AppState{}, AppState: &AppState{},
IsNewRepo: false,
} }
if err := appConfig.LoadAppState(); err != nil { if err := appConfig.LoadAppState(); err != nil {
@ -63,6 +67,16 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg
return appConfig, nil return appConfig, nil
} }
// GetIsNewRepo returns known repo boolean
func (c *AppConfig) GetIsNewRepo() bool {
return c.IsNewRepo
}
// SetIsNewRepo set if the current repo is known
func (c *AppConfig) SetIsNewRepo(toSet bool) {
c.IsNewRepo = toSet
}
// GetDebug returns debug flag // GetDebug returns debug flag
func (c *AppConfig) GetDebug() bool { func (c *AppConfig) GetDebug() bool {
return c.Debug return c.Debug
@ -153,7 +167,7 @@ func prepareConfigFile(filename string) (string, error) {
} }
// LoadAndMergeFile Loads the config/state file, creating // LoadAndMergeFile Loads the config/state file, creating
// the file as an empty one if it does not exist // the file has an empty one if it does not exist
func LoadAndMergeFile(v *viper.Viper, filename string) error { func LoadAndMergeFile(v *viper.Viper, filename string) error {
configPath, err := prepareConfigFile(filename) configPath, err := prepareConfigFile(filename)
if err != nil { if err != nil {
@ -236,16 +250,14 @@ confirmOnQuit: false
// AppState stores data between runs of the app like when the last update check // AppState stores data between runs of the app like when the last update check
// was performed and which other repos have been checked out // was performed and which other repos have been checked out
type AppState struct { type AppState struct {
LastUpdateCheck int64 LastUpdateCheck int64
RecentRepos []string RecentRepos []string
RecentPrivateRepos []string
} }
func getDefaultAppState() []byte { func getDefaultAppState() []byte {
return []byte(` return []byte(`
lastUpdateCheck: 0 lastUpdateCheck: 0
recentRepos: [] recentRepos: []
recentPrivateRepos: []
`) `)
} }

View File

@ -73,7 +73,7 @@ type Gui struct {
Updater *updates.Updater Updater *updates.Updater
statusManager *statusManager statusManager *statusManager
credentials credentials credentials credentials
introAgree sync.WaitGroup waitForIntro sync.WaitGroup
} }
// for now the staging panel state, unlike the other panel states, is going to be // for now the staging panel state, unlike the other panel states, is going to be
@ -387,6 +387,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
if err := gui.updateRecentRepoList(); err != nil { if err := gui.updateRecentRepoList(); err != nil {
return err return err
} }
gui.waitForIntro.Done()
if _, err := gui.g.SetCurrentView(filesView.Name()); err != nil { if _, err := gui.g.SetCurrentView(filesView.Name()); err != nil {
return err return err
@ -422,16 +423,15 @@ func (gui *Gui) layout(g *gocui.Gui) error {
// if you download humanlog and do tail -f development.log | humanlog // if you download humanlog and do tail -f development.log | humanlog
// this will let you see these branches as prettified json // this will let you see these branches as prettified json
// gui.Log.Info(utils.AsJson(gui.State.Branches[0:4])) // gui.Log.Info(utils.AsJson(gui.State.Branches[0:4]))
return gui.resizeCurrentPopupPanel(g) return gui.resizeCurrentPopupPanel(g)
} }
func (gui *Gui) promptAnonymousReporting() error { func (gui *Gui) promptAnonymousReporting() error {
return gui.createConfirmationPanel(gui.g, nil, gui.Tr.SLocalize("AnonymousReportingTitle"), gui.Tr.SLocalize("AnonymousReportingPrompt"), func(g *gocui.Gui, v *gocui.View) error { return gui.createConfirmationPanel(gui.g, nil, gui.Tr.SLocalize("AnonymousReportingTitle"), gui.Tr.SLocalize("AnonymousReportingPrompt"), func(g *gocui.Gui, v *gocui.View) error {
gui.introAgree.Done() gui.waitForIntro.Done()
return gui.Config.WriteToUserConfig("reporting", "on") return gui.Config.WriteToUserConfig("reporting", "on")
}, func(g *gocui.Gui, v *gocui.View) error { }, func(g *gocui.Gui, v *gocui.View) error {
gui.introAgree.Done() gui.waitForIntro.Done()
return gui.Config.WriteToUserConfig("reporting", "off") return gui.Config.WriteToUserConfig("reporting", "off")
}) })
} }
@ -509,13 +509,19 @@ func (gui *Gui) Run() error {
} }
if gui.Config.GetUserConfig().GetString("reporting") == "undetermined" { if gui.Config.GetUserConfig().GetString("reporting") == "undetermined" {
gui.introAgree.Add(1) gui.waitForIntro.Add(2)
} else {
gui.waitForIntro.Add(1)
} }
go func() { go func() {
gui.waitForIntro.Wait()
isNew := gui.Config.GetIsNewRepo()
if !isNew {
time.After(60 * time.Second)
}
_, err := gui.fetch(g, g.CurrentView(), false) _, err := gui.fetch(g, g.CurrentView(), false)
if err != nil && strings.Contains(err.Error(), "exit status 128") && gui.IsNewPrivateRepo() { if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
gui.introAgree.Wait()
_ = gui.createConfirmationPanel(g, g.CurrentView(), gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), gui.Tr.SLocalize("NoAutomaticGitFetchBody"), nil, nil) _ = gui.createConfirmationPanel(g, g.CurrentView(), gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), gui.Tr.SLocalize("NoAutomaticGitFetchBody"), nil, nil)
} else { } else {
gui.goEvery(g, time.Second*60, func(g *gocui.Gui) error { gui.goEvery(g, time.Second*60, func(g *gocui.Gui) error {

View File

@ -14,8 +14,8 @@ type recentRepo struct {
path string path string
} }
// GetDisplayStrings is a function. // GetDisplayStrings returns the path from a recent repo.
func (r *recentRepo) GetDisplayStrings() []string { func (r recentRepo) GetDisplayStrings() []string {
yellow := color.New(color.FgMagenta) yellow := color.New(color.FgMagenta)
base := filepath.Base(r.path) base := filepath.Base(r.path)
path := yellow.Sprint(r.path) path := yellow.Sprint(r.path)
@ -26,14 +26,14 @@ func (gui *Gui) handleCreateRecentReposMenu(g *gocui.Gui, v *gocui.View) error {
recentRepoPaths := gui.Config.GetAppState().RecentRepos recentRepoPaths := gui.Config.GetAppState().RecentRepos
reposCount := utils.Min(len(recentRepoPaths), 20) reposCount := utils.Min(len(recentRepoPaths), 20)
// we won't show the current repo hence the -1 // we won't show the current repo hence the -1
recentRepos := make([]*recentRepo, reposCount-1) recentRepos := make([]string, reposCount-1)
for i, path := range recentRepoPaths[1:reposCount] { for i, repo := range recentRepoPaths[1:reposCount] {
recentRepos[i] = &recentRepo{path: path} recentRepos[i] = repo
} }
handleMenuPress := func(index int) error { handleMenuPress := func(index int) error {
repo := recentRepos[index] repoPath := recentRepos[index]
if err := os.Chdir(repo.path); err != nil { if err := os.Chdir(repoPath); err != nil {
return err return err
} }
newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr) newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr)
@ -55,34 +55,22 @@ func (gui *Gui) updateRecentRepoList() error {
if err != nil { if err != nil {
return err return err
} }
gui.Config.GetAppState().RecentRepos = newRecentReposList(recentRepos, currentRepo) known, recentRepos := newRecentReposList(recentRepos, currentRepo)
gui.Config.SetIsNewRepo(known)
gui.Config.GetAppState().RecentRepos = recentRepos
return gui.Config.SaveAppState() return gui.Config.SaveAppState()
} }
// IsNewPrivateRepo returns true if a private repo is never opend before in lazygit
func (gui *Gui) IsNewPrivateRepo() bool {
repos := gui.Config.GetAppState().RecentPrivateRepos
currentRepo, err := os.Getwd()
if err != nil {
return true
}
for _, repo := range repos {
if currentRepo == repo {
return false
}
}
gui.Config.GetAppState().RecentPrivateRepos = newRecentReposList(repos, currentRepo)
_ = gui.Config.SaveAppState()
return true
}
// 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) []string { func newRecentReposList(recentRepos []string, currentRepo string) (bool, []string) {
isNew := true
newRepos := []string{currentRepo} newRepos := []string{currentRepo}
for _, repo := range recentRepos { for _, repo := range recentRepos {
if repo != currentRepo { if repo != currentRepo {
newRepos = append(newRepos, repo) newRepos = append(newRepos, repo)
} else {
isNew = false
} }
} }
return newRepos return isNew, newRepos
} }