package repo
import (
"fmt"
"os"
"path/filepath"
)
var hookNames = []string{"pre-receive", "update", "post-receive"}
const hookTemplate = `#!/bin/sh
# AUTO GENERATED BY NUGITEA, DO NOT MODIFY
exec %q hook %s "$@"
`
func installHooks(repoPath, nugiteaBin string) error {
hookDir := filepath.Join(repoPath, "hooks")
if err := os.MkdirAll(hookDir, 0o755); err != nil {
return err
}
for _, name := range hookNames {
script := fmt.Sprintf(hookTemplate, nugiteaBin, name)
path := filepath.Join(hookDir, name)
if err := os.WriteFile(path, []byte(script), 0o755); err != nil {
return fmt.Errorf("write hook %s: %w", name, err)
}
}
return nil
}