#!/bin/sh
# Refuse commits whose bug records (.wolf/bugs/*.md) do not meet
# .claude/skills/buglog/bug-record.md, or whose .wolf/buglog.json index is stale;
# and commits whose staged C sources break the no-fork rule
# (.kiro/steering/tech.md, "Process creation"; scripts/check-no-fork.py).
# Install: ln -sf ../../scripts/git-hooks/pre-commit .git/hooks/pre-commit
top="$(git rev-parse --show-toplevel)"
if git diff --cached --name-only -- .wolf/bugs/ .wolf/buglog.json | grep -q .; then
    python3 "$top/scripts/buglog.py" check --staged || exit 1
fi
c_files="$(git diff --cached --name-only --diff-filter=ACMR -- '*.c' '*.h')"
if [ -n "$c_files" ]; then
    # shellcheck disable=SC2086 # one path per word; repo paths have no spaces
    python3 "$top/scripts/check-no-fork.py" "$top" $c_files >/dev/null || {
        python3 "$top/scripts/check-no-fork.py" "$top" $c_files
        exit 1
    }
fi
exit 0
