Skip to content

Commit

Permalink
fix: don't block on git push waiting for config reload
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 18, 2022
1 parent 6b86cf7 commit 61a8eb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"sync"

"golang.org/x/crypto/ssh"
"gopkg.in/yaml.v2"
Expand All @@ -28,6 +29,7 @@ type Config struct {
Repos []Repo `yaml:"repos"`
Source *git.RepoSource
Cfg *config.Config
reloadMtx sync.Mutex
}

// User contains user-level configuration for a repository.
Expand Down Expand Up @@ -107,6 +109,8 @@ func NewConfig(cfg *config.Config) (*Config, error) {

// Reload reloads the configuration.
func (cfg *Config) Reload() error {
cfg.reloadMtx.Lock()
defer cfg.reloadMtx.Unlock()
err := cfg.Source.LoadRepos()
if err != nil {
return err
Expand Down
16 changes: 9 additions & 7 deletions internal/config/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import (

// Push registers Git push functionality for the given repo and key.
func (cfg *Config) Push(repo string, pk ssh.PublicKey) {
err := cfg.Reload()
if err != nil {
log.Printf("error reloading after push: %s", err)
}
if cfg.Cfg.Callbacks != nil {
cfg.Cfg.Callbacks.Push(repo)
}
go func() {
err := cfg.Reload()
if err != nil {
log.Printf("error reloading after push: %s", err)
}
if cfg.Cfg.Callbacks != nil {
cfg.Cfg.Callbacks.Push(repo)
}
}()
}

// Fetch registers Git fetch functionality for the given repo and key.
Expand Down

0 comments on commit 61a8eb1

Please sign in to comment.