package repo import ( "fmt" "os" "path/filepath" ) // hookNames are the git server-side hooks nugitea installs a delegator for. // Each delegator just execs `nugitea hook ` and passes stdin through, // mirroring Gitea's hooks/ -> hooks/.d/gitea delegation (see // modules/gitrepo/hooks.go) but flattened to a single script since nugitea // has no per-hook custom-script fan-out to support. var hookNames = []string{"pre-receive", "update", "post-receive"} const hookTemplate = `#!/bin/sh # AUTO GENERATED BY NUGITEA, DO NOT MODIFY exec %q hook %s "$@" ` // installHooks writes the hook delegator scripts into repoPath/hooks. // nugiteaBin is the absolute path to the running nugitea binary, so the // hook can call back into it regardless of $PATH. 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 }