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:""`
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 {
@ -238,14 +252,12 @@ confirmOnQuit: false
type AppState struct {
LastUpdateCheck int64
RecentRepos []string
RecentPrivateRepos []string
}
func getDefaultAppState() []byte {
return []byte(`
lastUpdateCheck: 0
recentRepos: []
recentPrivateRepos: []
`)
}

View File

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

View File

@ -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
}