diff options
author | mjarkk <mkopenga@gmail.com> | 2018-12-10 13:45:03 +0100 |
---|---|---|
committer | mjarkk <mkopenga@gmail.com> | 2018-12-10 13:45:03 +0100 |
commit | 76e9582739c329fa657b327254bf010c560ac5e8 (patch) | |
tree | 3a4aa87e4ff66c986974b792ef68ecefa396f758 | |
parent | 50f20de8f34b53b808710e91fea501cb1e26ff89 (diff) |
Not always git fetch
-rw-r--r-- | pkg/config/app_config.go | 22 | ||||
-rw-r--r-- | pkg/gui/gui.go | 20 | ||||
-rw-r--r-- | pkg/gui/recent_repos_panel.go | 42 |
3 files changed, 45 insertions, 39 deletions
diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 48cf2df35..18aa961bc 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -20,6 +20,7 @@ type AppConfig struct { BuildSource string `long:"build-source" env:"BUILD_SOURCE" default:""` UserConfig *viper.Viper AppState *AppState + IsNewRepo bool } // AppConfigurer interface allows individual app config structs to inherit Fields @@ -36,6 +37,8 @@ type AppConfigurer interface { WriteToUserConfig(string, string) error SaveAppState() error LoadAppState() error + SetIsNewRepo(bool) + GetIsNewRepo() bool } // NewAppConfig makes a new app config @@ -54,6 +57,7 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg BuildSource: buildSource, UserConfig: userConfig, AppState: &AppState{}, + IsNewRepo: false, } if err := appConfig.LoadAppState(); err != nil { @@ -63,6 +67,16 @@ func NewAppConfig(name, version, commit, date string, buildSource string, debugg 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 func (c *AppConfig) GetDebug() bool { return c.Debug @@ -153,7 +167,7 @@ func prepareConfigFile(filename string) (string, error) { } // 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 { configPath, err := prepareConfigFile(filename) if err != nil { @@ -236,16 +250,14 @@ confirmOnQuit: false // AppState stores data between runs of the app like when the last update check // was performed and which other repos have been checked out type AppState struct { - LastUpdateCheck int64 - RecentRepos []string - RecentPrivateRepos []string + LastUpdateCheck int64 + RecentRepos []string } func getDefaultAppState() []byte { return []byte(` lastUpdateCheck: 0 recentRepos: [] - recentPrivateRepos: [] `) } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index a8a393620..3345be560 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -73,7 +73,7 @@ type Gui struct { Updater *updates.Updater statusManager *statusManager credentials credentials - introAgree sync.WaitGroup + waitForIntro sync.WaitGroup } // 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 { return err } + gui.waitForIntro.Done() if _, err := gui.g.SetCurrentView(filesView.Name()); err != nil { 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 // this will let you see these branches as prettified json // gui.Log.Info(utils.AsJson(gui.State.Branches[0:4])) - return gui.resizeCurrentPopupPanel(g) } 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 { - gui.introAgree.Done() + gui.waitForIntro.Done() return gui.Config.WriteToUserConfig("reporting", "on") }, func(g *gocui.Gui, v *gocui.View) error { - gui.introAgree.Done() + gui.waitForIntro.Done() return gui.Config.WriteToUserConfig("reporting", "off") }) } @@ -509,13 +509,19 @@ func (gui *Gui) Run() error { } if gui.Config.GetUserConfig().GetString("reporting") == "undetermined" { - gui.introAgree.Add(1) + gui.waitForIntro.Add(2) + } else { + gui.waitForIntro.Add(1) } go func() { + gui.waitForIntro.Wait() + isNew := gui.Config.GetIsNewRepo() + if !isNew { + time.After(60 * time.Second) + } _, err := gui.fetch(g, g.CurrentView(), false) - if err != nil && strings.Contains(err.Error(), "exit status 128") && gui.IsNewPrivateRepo() { - gui.introAgree.Wait() + if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew { _ = gui.createConfirmationPanel(g, g.CurrentView(), gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), gui.Tr.SLocalize("NoAutomaticGitFetchBody"), nil, nil) } else { gui.goEvery(g, time.Second*60, func(g *gocui.Gui) error { diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index 4ee990076..105d9b9cf 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -14,8 +14,8 @@ type recentRepo struct { path string } -// GetDisplayStrings is a function. -func (r *recentRepo) GetDisplayStrings() []string { +// GetDisplayStrings returns the path from a recent repo. +func (r recentRepo) GetDisplayStrings() []string { yellow := color.New(color.FgMagenta) base := filepath.Base(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 reposCount := utils.Min(len(recentRepoPaths), 20) // we won't show the current repo hence the -1 - recentRepos := make([]*recentRepo, reposCount-1) - for i, path := range recentRepoPaths[1:reposCount] { - recentRepos[i] = &recentRepo{path: path} + recentRepos := make([]string, reposCount-1) + for i, repo := range recentRepoPaths[1:reposCount] { + recentRepos[i] = repo } handleMenuPress := func(index int) error { - repo := recentRepos[index] - if err := os.Chdir(repo.path); err != nil { + repoPath := recentRepos[index] + if err := os.Chdir(repoPath); err != nil { return err } newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr) @@ -55,34 +55,22 @@ func (gui *Gui) updateRecentRepoList() error { if err != nil { 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() } -// 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 -func newRecentReposList(recentRepos []string, currentRepo string) []string { +func newRecentReposList(recentRepos []string, currentRepo string) (bool, []string) { + isNew := true newRepos := []string{currentRepo} for _, repo := range recentRepos { if repo != currentRepo { newRepos = append(newRepos, repo) + } else { + isNew = false } } - return newRepos + return isNew, newRepos } |