Skip to content

Commit

Permalink
fix: Panic in git config cache ⚓ (#90)
Browse files Browse the repository at this point in the history
- Wrongly initialized config cache produces a panic when `git config ...` produces an error. 
  (exactly why this happens is still unclear, probably leaking Git env. variables)
  • Loading branch information
gabyx authored Apr 4, 2022
1 parent 6b37a2d commit c2609ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions githooks/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ func NewCtxSanitized() *Context {
}

// SetConfigCache sets the Git config cache to use.
func (c *Context) InitConfigCache(filter func(string) bool) (err error) {
func (c *Context) InitConfigCache(filter func(string) bool) error {
cache, err := NewConfigCache(*c, filter)

if err != nil {
return err
}

c.cache = &cache

return
return nil
}

// GetConfig gets a Git configuration value for key `key`.
Expand Down
2 changes: 1 addition & 1 deletion githooks/git/gitconfig-cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewConfigCache(gitx Context, filterFunc func(string) bool) (ConfigCache, er

conf, err := gitx.Get("config", "--includes", "--list", "--null", "--show-scope")
if err != nil {
return ConfigCache{}, nil
return ConfigCache{}, err
}

return parseConfig(conf, filterFunc)
Expand Down

0 comments on commit c2609ed

Please sign in to comment.