#!/bin/sh
# Haystack pre-push hook
# Haystack's own hooks never need the push credential the CLI exports for
# `git push`; drop it so nothing these hooks run can read it.
unset HAYSTACK_GIT_TOKEN
# $1 is the remote name (e.g., "origin")

# Check if pushing a non-haystack branch and remind about haystack submit
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ -n "$current_branch" ] && [ "$current_branch" != "main" ] && [ "$current_branch" != "master" ]; then
  case "$current_branch" in
    haystack/*)
      # Already a haystack branch, no reminder needed
      ;;
    *)
      # Check if this is an AI agent session (set by agent-context detector)
      if [ -n "$HAYSTACK_AGENT_SESSION" ] || [ -n "$CLAUDE_CODE" ] || [ -n "$CODEX_CLI" ] || [ -n "$CODEX_SHELL" ] || [ -n "$CODEX_THREAD_ID" ] || [ -n "$CODEX_CI" ]; then
        echo ""
        echo "💡 Tip: Use 'haystack submit' to create PRs through Haystack's submit workflow."
        echo "   This enables automatic analysis and merge when approved."
        echo ""
      fi
      ;;
  esac
fi
