#!/usr/bin/env bash
# Case 07: 'cd /tmp && git init' inside an .hg repo must be allowed
# (only the leading token is inspected — this is the documented escape valve).
set -u

tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT

mkdir -p "$tmp/repo/.hg"

input=$(jq -n --arg cwd "$tmp/repo" --arg cmd "cd /tmp && git init" '{
  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
