// Package hooks wires git hook invocations back into the simplegit daemon. // // Git hooks are scripts git runs at fixed points in an operation (push, commit, // ...). For a bare hosting repo only the server-side hooks fire during a push, // but the same forwarding script is installed for every git-defined hook name so // whichever one git runs is captured -- the bus listens to every hook type. // // Pipeline: // // git (during a push) -> hooks/ (rendered shell script) -> // `simplegit hook --root=... [args]` (this package's client) -> // unix socket /hook.sock -> daemon Listener -> buffered bus chan -> // Updater (logs now; future: forwards to a subscribed URL or MQ). // // Hooks fail open: if the socket is absent or the daemon is unreachable the // client exits 0, so a git operation (push) is never blocked by the event bus. // Enforcement (pre-receive reject) is a future layer on the same response // protocol; today the listener observes only. package hooks // HookEvent is one hook invocation forwarded by a hook script. type HookEvent struct { Type string `json:"type"` // hook name, e.g. "pre-receive" Repo string `json:"repo"` // "ns/name" resolved from the repo path, "" if unknown RepoPath string `json:"repo_path"` // absolute bare repo path (the hook's cwd) Args []string `json:"args"` // hook argv after the hook name Stdin string `json:"stdin"` // raw stdin (ref-update lines for receive hooks) Env map[string]string `json:"env"` // captured GIT_* env vars } // hookNames is every hook git looks for in $GIT_DIR/hooks. Only the server-side // ones fire on a bare hosting repo during a push, but installing all of them // means whichever git runs is forwarded -- and a hook name git does not use is // simply ignored, so the full set is harmless. Keep this list in sync with // githooks(5). var hookNames = []string{ // server-side (fire during a push to a bare repo) "pre-receive", "update", "post-receive", "post-update", "proc-receive", "push-to-checkout", "reference-transaction", // client-side (fire in a working repo; dormant on a bare host) "pre-applypatch", "post-applypatch", "pre-commit", "pre-merge-commit", "prepare-commit-msg", "commit-msg", "post-commit", "pre-rebase", "post-checkout", "post-merge", "pre-push", "pre-auto-gc", "post-rewrite", "sendemail-validate", "fsmonitor-watchman", "p4-pre-submit", "p4-post-changelist", "p4-prepare-changelist", "p4-changelist", }