# Block commits containing local absolute paths (e.g. /Users/clemens/...)
# Exclude this hook and CI config (they legitimately reference the pattern)
ADDED_LINES=$(git diff --cached --diff-filter=d -U0 -- ':!.husky/' ':!.github/' | grep '^+' | grep -v '^+++' || true)
if echo "$ADDED_LINES" | grep -qE '/Users/|C:/Users/'; then
  echo "❌ Staged changes contain a local absolute path (/Users/... or C:/Users/...)."
  echo "   These should not be committed to the repo."
  echo ""
  echo "$ADDED_LINES" | grep -nE '/Users/|C:/Users/'
  exit 1
fi

# If HOME is not writable (e.g. OrbStack containers where HOME is overridden to a
# root-owned path), point pnpm to the user's actual writable home directory.
# On macOS/Windows HOME is always writable, so this block never runs there.
if [ ! -w "$HOME" ]; then
  export PNPM_HOME="/home/$(id -un)/.local/share/pnpm"
  mkdir -p "$PNPM_HOME"
fi

npx lint-staged
