#!/usr/bin/env bash
# Refresh the codegraph index after a commit moved the tree.
#
# codegraph-sync.sh backgrounds the rebuild and stamps HEAD plus the dirty-tree
# hash, so tools/codegraph-check.sh can tell "current" from "stale" without
# reindexing on a timer. Never blocks the commit.
set -uo pipefail

root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"

if [ -x "$root/tools/codegraph-sync.sh" ]; then
    "$root/tools/codegraph-sync.sh"
else
    echo "post-commit: tools/codegraph-sync.sh missing or not executable; skipping index" >&2
fi

exit 0
