diff --git a/internal/config/config.go b/internal/config/config.go index 972fe1e4c..10c9ed360 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,7 @@ package config import ( "bytes" + "log" "strings" "sync" "text/template" @@ -130,6 +131,10 @@ func (cfg *Config) Reload() error { } for _, r := range cfg.Source.AllRepos() { name := r.Name() + err = r.UpdateServerInfo() + if err != nil { + log.Printf("error updating server info for %s: %s", name, err) + } pat := "README*" rp := "" for _, rr := range cfg.Repos { @@ -186,7 +191,7 @@ func (cfg *Config) createDefaultConfigRepo(yaml string) error { if err != nil { return err } - r, err := rs.GetRepo(cn) + _, err = rs.GetRepo(cn) if err == git.ErrMissingRepo { cr, err := rs.InitRepo(cn, true) if err != nil { @@ -234,12 +239,6 @@ func (cfg *Config) createDefaultConfigRepo(yaml string) error { if err != nil { return err } - cmd := exec.Command("git", "update-server-info") - cmd.Dir = filepath.Join(rs.Path, cn) - err = cmd.Run() - if err != nil { - return err - } } else if err != nil { return err } diff --git a/internal/config/git.go b/internal/config/git.go index e7f39248e..9e6c89540 100644 --- a/internal/config/git.go +++ b/internal/config/git.go @@ -18,6 +18,15 @@ func (cfg *Config) Push(repo string, pk ssh.PublicKey) { if cfg.Cfg.Callbacks != nil { cfg.Cfg.Callbacks.Push(repo) } + r, err := cfg.Source.GetRepo(repo) + if err != nil { + log.Printf("error getting repo after push: %s", err) + return + } + err = r.UpdateServerInfo() + if err != nil { + log.Printf("error updating server info after push: %s", err) + } }() } diff --git a/internal/git/git.go b/internal/git/git.go index 500847772..1762d57d7 100644 --- a/internal/git/git.go +++ b/internal/git/git.go @@ -5,6 +5,7 @@ import ( "errors" "log" "os" + "os/exec" "path/filepath" "sort" "sync" @@ -385,3 +386,9 @@ func (r *Repo) LatestTree(path string) (*object.Tree, error) { return r.Tree(r.head, path) } +// UpdateServerInfo updates the server info for the repository. +func (r *Repo) UpdateServerInfo() error { + cmd := exec.Command("git", "update-server-info") + cmd.Dir = r.path + return cmd.Run() +}