#!/usr/bin/env bash # Tests for plugins/git/.apm/hooks/refuse-push-to-main.py, the PreToolUse hook # that refuses a `git push` to `main` (#178). # # The hook acts only when run from a .claude/hooks/ path, so it is copied to the # path apm deploys it to and driven with real payloads against fixture repos. set -euo pipefail unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR unset GIT_ALLOW_PUSH_TO_MAIN REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" HOOKS_DIR="$REPO_ROOT/plugins/git/.apm/hooks" SRC="$HOOKS_DIR/refuse-push-to-main.py" PASS=0 FAIL=0 pass() { PASS=$((PASS + 1)); } fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); } command -v python3 > /dev/null 2>&1 || { echo "python3 required"; exit 77; } [[ -f "$SRC" ]] || { echo "FAIL: $SRC does not exist"; exit 1; } WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT for d in .claude/hooks/git/.apm/hooks .github/hooks/scripts/git/.apm/hooks \ .codex/hooks/git/.apm/hooks elsewhere; do mkdir -p "$WORK/$d" cp "$SRC" "$WORK/$d/" done HOOK="$WORK/.claude/hooks/git/.apm/hooks/refuse-push-to-main.py" git init -q -b main "$WORK/on-main" git init -q -b feat "$WORK/on-feat" # decision