#!/usr/bin/env bash
# git post-checkout hook — full reindex after a branch switch.
# Args: $1=previous HEAD, $2=new HEAD, $3=1 if branch checkout / 0 if file checkout
# Only fires on branch checkouts, not `git checkout -- <file>`.

CHECKOUT_TYPE="$3"
[[ "$CHECKOUT_TYPE" != "1" ]] && exit 0  # file checkout, not a branch switch

REPO_ROOT="$(git rev-parse --show-toplevel)"
REINDEX="$REPO_ROOT/.venv/bin/codemind-reindex"

[[ ! -x "$REINDEX" ]] && exit 0

"$REINDEX" --repo "$REPO_ROOT" --full 2>/dev/null || true
