#!/usr/bin/env bash
# Hook devflow — promotion automatique vers ~/.claude/ sur checkout develop.
# Déclenché uniquement pour un checkout de branche (flag $3 = 1).

set -u

prev_ref=$1
new_ref=$2
branch_checkout=$3

# Ignore les checkout de fichiers (ex: git checkout -- file)
[ "$branch_checkout" = "1" ] || exit 0

# Ignore si la HEAD n'a pas changé (no-op rebase steps)
[ "$prev_ref" != "$new_ref" ] || exit 0

branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
[ "$branch" = "develop" ] || exit 0

if ! command -v devflow >/dev/null 2>&1; then
  echo "[devflow hooks] devflow CLI introuvable dans le PATH — promotion ignorée." >&2
  exit 0
fi

echo "[devflow hooks] checkout develop → devflow init --here --force"
devflow init --here --force
