Skip to content

Commit

Permalink
feat(git): UpdateServerInfo on push
Browse files Browse the repository at this point in the history
git update-server-info generates the repository's refs needed for the
git http server
  • Loading branch information
aymanbagabas committed Mar 4, 2022
1 parent 68feddf commit 32bdd5b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
13 changes: 6 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"bytes"
"log"
"strings"
"sync"
"text/template"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions internal/config/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
}

Expand Down
7 changes: 7 additions & 0 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"log"
"os"
"os/exec"
"path/filepath"
"sort"
"sync"
Expand Down Expand Up @@ -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()
}

0 comments on commit 32bdd5b

Please sign in to comment.