code-limits: mkdir -m 700 without -p as the atomic proof, else one find test (ours, dir, 700). session-start: one runner, timeout then gtimeout then perl alarm (exec, no shell). pre-commit (generator + both copies): a git diff or grep error blocks. memory.sh line rewrap; claude-stub reads its log path from the env. Tests T16, SD19, PC1-4.
57 lines
2.7 KiB
Bash
Executable File
57 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# gitflow pre-commit — generated by gitflow_init. Do not hand-edit.
|
|
# Mirrors gitflow_protected_base (lib/gitflow.sh). Drift caught by T10.
|
|
gd=$(git rev-parse --git-dir)
|
|
br=$(git symbolic-ref --short -q HEAD 2>/dev/null)
|
|
|
|
git rev-parse --verify -q HEAD >/dev/null 2>&1 || exit 0 # root commit — allow
|
|
[ -f "$gd/MERGE_HEAD" ] && exit 0 # merge in progress — allow
|
|
|
|
# Secret backstop (job7) — any branch, not just protected ones. Non-blocking
|
|
# if gitleaks isn't installed; auto-discovers ./.gitleaks.toml (repo root).
|
|
# gitleaks >= 8.19 scans the index with `git --staged`; older builds (Ubuntu's
|
|
# 8.16 package) only know `protect --staged`, and `git` exits 1 there as an
|
|
# unknown command — which would block every commit. Probe the subcommand first.
|
|
if command -v gitleaks >/dev/null 2>&1; then
|
|
gl_sub=git
|
|
gitleaks git --help >/dev/null 2>&1 || gl_sub=protect
|
|
if ! gitleaks "$gl_sub" --staged --no-banner >/dev/null 2>&1; then
|
|
echo "gitflow pre-commit: BLOCKED — gitleaks found a secret in staged changes." >&2
|
|
echo " Details: gitleaks $gl_sub --staged --no-banner" >&2
|
|
echo " Genuine false-positive? add an allowlist rule to .gitleaks.toml — never bypass with --no-verify." >&2
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "gitflow pre-commit: gitleaks not installed — secret scan skipped (https://github.com/gitleaks/gitleaks)." >&2
|
|
fi
|
|
|
|
# Per-repo opt-out of the branch model (a clone of a foreign project):
|
|
# git config gitflow.protect false
|
|
[ "$(git config --bool --default true gitflow.protect)" = false ] && exit 0
|
|
|
|
case "$br" in
|
|
main|develop) ;; # protected — keep checking
|
|
*) exit 0 ;; # working branch — allow
|
|
esac
|
|
|
|
# whitelist: every staged path under .claude/{memory,tasks,audits,deploy}/ or
|
|
# .githooks/ (memory/doc/deploy helpers, the hooks themselves) — allow. Rules,
|
|
# settings, agents, skills stay blocked. --no-renames lists a rename's source
|
|
# too, so a git mv out of a blocked path cannot hide.
|
|
staged=$(git diff --cached --name-only --no-renames) || {
|
|
echo "gitflow pre-commit: cannot list staged paths: BLOCKED" >&2
|
|
exit 1
|
|
}
|
|
[ -n "$staged" ] || exit 0
|
|
printf '%s\n' "$staged" | grep -qvE '^(\.claude/(memory|tasks|audits|deploy)|\.githooks)/'
|
|
case $? in
|
|
0) ;;
|
|
1) exit 0 ;;
|
|
*) echo "gitflow pre-commit: cannot filter staged paths: BLOCKED" >&2; exit 1 ;;
|
|
esac
|
|
|
|
echo "gitflow pre-commit: BLOCKED — direct commit on '$br'." >&2
|
|
echo " Branch from the right base (feature/bugfix->develop, hotfix->main), or merge." >&2
|
|
echo " (.claude/{memory,tasks,audits,deploy}/ and .githooks/ commits are exempt; foreign clone? git config gitflow.protect false)" >&2
|
|
exit 1
|