From 7f83dc3cdc47b774b5e1228597468bee702b25de Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 20 Sep 2021 16:21:08 -0400 Subject: [PATCH] reload repos and config on start and on git push only --- tui/session.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tui/session.go b/tui/session.go index ee7211979..648307358 100644 --- a/tui/session.go +++ b/tui/session.go @@ -13,6 +13,7 @@ import ( func SessionHandler(reposPath string, repoPoll time.Duration) func(ssh.Session) (tea.Model, []tea.ProgramOption) { rs := git.NewRepoSource(reposPath) + // createDefaultConfigRepo runs rs.LoadRepos() err := createDefaultConfigRepo(rs) if err != nil { if err != nil { @@ -25,29 +26,25 @@ func SessionHandler(reposPath string, repoPoll time.Duration) func(ssh.Session) log.Printf("cannot load config: %s", err) } } - go func() { - for { - time.Sleep(repoPoll) + + return func(s ssh.Session) (tea.Model, []tea.ProgramOption) { + cmd := s.Command() + // reload repos and config on git push + if len(cmd) > 0 && cmd[0] == "git-receive-pack" { ct := time.Now() err := rs.LoadRepos() if err != nil { log.Printf("cannot load repos: %s", err) - continue } cfg, err := loadConfig(rs) if err != nil { if err != nil { log.Printf("cannot load config: %s", err) - continue } } - log.Printf("Repos loaded in %s", time.Since(ct)) appCfg = cfg + log.Printf("Repo bubble loaded in %s", time.Since(ct)) } - }() - - return func(s ssh.Session) (tea.Model, []tea.ProgramOption) { - cmd := s.Command() cfg := &SessionConfig{} switch len(cmd) { case 0: