7f83dc3cdc47b774b5e1228597468bee702b25de

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

reload repos and config on start and on git push only

Diff

 1diff --git a/tui/session.go b/tui/session.go
 2index ee72119792bc9d4dadb9dd28af8d817511fd9b51..648307358c4cefc8a2cd9ffe512d08780be8eaa0 100644
 3--- a/tui/session.go
 4+++ b/tui/session.go
 5@@ -13,6 +13,7 @@ import (
 6 
 7 func SessionHandler(reposPath string, repoPoll time.Duration) func(ssh.Session) (tea.Model, []tea.ProgramOption) {
 8 	rs := git.NewRepoSource(reposPath)
 9+	// createDefaultConfigRepo runs rs.LoadRepos()
10 	err := createDefaultConfigRepo(rs)
11 	if err != nil {
12 		if err != nil {
13@@ -25,29 +26,25 @@ func SessionHandler(reposPath string, repoPoll time.Duration) func(ssh.Session)
14 			log.Printf("cannot load config: %s", err)
15 		}
16 	}
17-	go func() {
18-		for {
19-			time.Sleep(repoPoll)
20+
21+	return func(s ssh.Session) (tea.Model, []tea.ProgramOption) {
22+		cmd := s.Command()
23+		// reload repos and config on git push
24+		if len(cmd) > 0 && cmd[0] == "git-receive-pack" {
25 			ct := time.Now()
26 			err := rs.LoadRepos()
27 			if err != nil {
28 				log.Printf("cannot load repos: %s", err)
29-				continue
30 			}
31 			cfg, err := loadConfig(rs)
32 			if err != nil {
33 				if err != nil {
34 					log.Printf("cannot load config: %s", err)
35-					continue
36 				}
37 			}
38-			log.Printf("Repos loaded in %s", time.Since(ct))
39 			appCfg = cfg
40+			log.Printf("Repo bubble loaded in %s", time.Since(ct))
41 		}
42-	}()
43-
44-	return func(s ssh.Session) (tea.Model, []tea.ProgramOption) {
45-		cmd := s.Command()
46 		cfg := &SessionConfig{}
47 		switch len(cmd) {
48 		case 0: