Skip to content

Commit

Permalink
fix: Force creation of git hooks folder (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Feb 27, 2023
1 parent 3f4eca1 commit 34708b5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/lefthook/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func (l *Lefthook) Add(args *AddArgs) error {
return err
}

if err = l.ensureHooksDirExists(); err != nil {
return err
}

err = l.addHook(args.Hook, "")
if err != nil {
return err
Expand Down
17 changes: 17 additions & 0 deletions internal/lefthook/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
const (
configFileMode = 0o666
checksumFileMode = 0o644
hooksDirMode = 0o755
configGlob = "lefthook.y*ml"
timestampBase = 10
timestampBitsize = 64
Expand Down Expand Up @@ -117,6 +118,10 @@ func (l *Lefthook) createHooksIfNeeded(cfg *config.Config, force bool) error {
return err
}

if err = l.ensureHooksDirExists(); err != nil {
return err
}

hookNames := make([]string, 0, len(cfg.Hooks)+1)
for hook := range cfg.Hooks {
hookNames = append(hookNames, hook)
Expand Down Expand Up @@ -244,3 +249,15 @@ func (l *Lefthook) addChecksumFile(checksum string) error {
func (l *Lefthook) checksumFilePath() string {
return filepath.Join(l.repo.InfoPath, config.ChecksumFileName)
}

func (l *Lefthook) ensureHooksDirExists() error {
exists, err := afero.Exists(l.Fs, l.repo.HooksPath)
if !exists || err != nil {
err = l.Fs.MkdirAll(l.repo.HooksPath, hooksDirMode)
if err != nil {
return err
}
}

return nil
}

0 comments on commit 34708b5

Please sign in to comment.