aperion_shield/hooks/
templates.rs1pub const APERION_HOOK_MARKER: &str = "# APERION-SHIELD-HOOK v1 -- managed by `aperion-shield --install-hooks`";
32
33pub fn pre_commit_script() -> String {
37 format!(
38 r#"#!/bin/sh
39{marker}
40#
41# What this does:
42# * Asks `aperion-shield --check-staged` to scan the lines being
43# ADDED / MODIFIED in this commit.
44# * Blocks the commit (exit 1) if any line trips a destructive rule
45# (DROP DATABASE, rm -rf /, git push --force, etc.).
46# * No-ops cleanly when `aperion-shield` isn't on $PATH.
47#
48# Bypass switches (in order of preference):
49# git commit --no-verify # skip all hooks for this commit
50# SHIELD_HOOKS_DISABLE=1 git ... # env override; works in CI
51#
52# To remove this hook entirely:
53# aperion-shield --uninstall-hooks
54
55set -e
56
57if [ "${{SHIELD_HOOKS_DISABLE:-}}" = "1" ]; then
58 exit 0
59fi
60
61if ! command -v aperion-shield >/dev/null 2>&1; then
62 echo "[aperion-shield] binary not on \$PATH; skipping pre-commit guardrail" >&2
63 echo "[aperion-shield] install: brew install AperionAI/tap/aperion-shield" >&2
64 exit 0
65fi
66
67exec aperion-shield --check-staged
68"#,
69 marker = APERION_HOOK_MARKER,
70 )
71}
72
73pub fn pre_push_script() -> String {
77 format!(
78 r#"#!/bin/sh
79{marker}
80#
81# What this does:
82# * Reads git's standard pre-push stdin (one `local_ref local_sha
83# remote_ref remote_sha` line per ref being pushed).
84# * Asks `aperion-shield --check-pushed-refs` whether any ref is a
85# destructive force-push or branch-deletion of a protected branch
86# (main, master, prod, release/*, by default).
87# * Blocks the push (exit 1) if any ref is destructive.
88# * No-ops cleanly when `aperion-shield` isn't on $PATH.
89#
90# Bypass switches:
91# git push --no-verify
92# SHIELD_HOOKS_DISABLE=1 git push ...
93#
94# To remove this hook entirely:
95# aperion-shield --uninstall-hooks
96
97set -e
98
99if [ "${{SHIELD_HOOKS_DISABLE:-}}" = "1" ]; then
100 exit 0
101fi
102
103if ! command -v aperion-shield >/dev/null 2>&1; then
104 echo "[aperion-shield] binary not on \$PATH; skipping pre-push guardrail" >&2
105 exit 0
106fi
107
108# git supplies pre-push refs on stdin; pipe straight through.
109exec aperion-shield --check-pushed-refs
110"#,
111 marker = APERION_HOOK_MARKER,
112 )
113}