1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/env bash # Case 02: 'git --version' outside any .hg/.git context must be allowed. set -u tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT input=$(jq -n --arg cwd "$tmp" --arg cmd "git --version" '{ cwd: $cwd, hook_event_name: "PreToolUse", tool_name: "Bash", tool_input: { command: $cmd } }') if ! echo "$input" | "$HOOK_SCRIPT" >/dev/null 2>&1; then echo "expected exit 0 (allow), got non-zero" exit 1 fi