diff --git a/.config/hooks/post-checkout b/.config/hooks/post-checkout index 179beb252..41593f932 100755 --- a/.config/hooks/post-checkout +++ b/.config/hooks/post-checkout @@ -2,10 +2,23 @@ # Post-checkout hook. Folds in pql's planning logic (its .pql/hooks installer is # dead under core.hooksPath=.config/hooks). # -# On a branch checkout (third arg == 1), rebuild pql.db from the changelog so the -# local planning cache reflects the new branch's state. File-level checkouts -# ($3 == 0) are skipped. Args: . +# On a branch checkout (third arg == 1), keep the local planning cache (pql.db) +# in sync with the changelog. File-level checkouts ($3 == 0) are skipped. +# Args: . +# +# prev-HEAD == new-HEAD means the working-tree content did not change — a branch +# *creation* (`git checkout -b`) or a no-op checkout. pql.db is already correct +# for this content, so a `plan rebuild` here would only DROP uncommitted ticket +# mutations that have not reached the changelog yet (e.g. a just-activated +# in_progress status set right before the branch was cut). Instead, flush + stage +# them — the same changelog capture the pre-commit hook does — so the activation +# is durable across the checkout. A real branch *switch* (prev != new) loads a +# different changelog, so rebuild pql.db to match the branch we moved to. if [ "${3:-0}" = "1" ] && command -v pql >/dev/null 2>&1; then - pql plan rebuild >/dev/null 2>&1 || true + if [ "$1" = "$2" ]; then + pql plan export --stage >/dev/null 2>&1 || true + else + pql plan rebuild >/dev/null 2>&1 || true + fi pql decisions sync >/dev/null 2>&1 || true fi