Files
settled-reach/.config/hooks/post-checkout
T
jpmschweitzerandClaude Opus 4.8 b24a3596b5 fix(config): post-checkout does nothing on same-HEAD instead of export --stage
Refines 34ffcda86. The export --stage approach preserved the mutation but did more
than the bug needs: it eagerly stages changelog rows mid-checkout (surprising in
git status), and those staged rows can leak onto the wrong branch when a later
switch rebuilds by replaying the working-tree changelog.

Minimal fix: on a branch *creation* / no-op checkout (prev-HEAD == new-HEAD) the
working tree is unchanged, so pql.db already holds the committed state plus any
uncommitted mutation — just skip the whole block (do nothing). The mutation stays
in pql.db untouched and the next commit's pre-commit hook flushes it normally. Only
a real branch *switch* (prev != new) rebuilds. No git-index side effects, no leak.

Verified: same-HEAD invocation preserves an uncommitted status mutation and stages
nothing. (Credit: pql-clide's review of the upstream feature request.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 12:42:08 +02:00

22 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# 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), keep the local planning cache (pql.db)
# in sync with the changelog. File-level checkouts ($3 == 0) are skipped.
# Args: <prev-HEAD> <new-HEAD> <branch-flag>.
#
# Only a real branch *switch* (prev-HEAD != new-HEAD) loads a different changelog
# and needs a rebuild. On a branch *creation* (`git checkout -b`) or no-op checkout
# (prev == new) the working-tree content is unchanged, so pql.db already holds the
# committed state AND any uncommitted ticket mutation set just before the branch was
# cut (e.g. a just-activated in_progress status) — so do NOTHING. A rebuild there
# would drop that mutation; the next commit's pre-commit hook flushes it normally.
# Doing nothing (rather than an eager `export --stage`) also avoids staging changelog
# rows mid-checkout — those could otherwise leak onto the wrong branch when a later
# switch rebuilds by replaying the working-tree changelog.
if [ "${3:-0}" = "1" ] && [ "$1" != "$2" ] && command -v pql >/dev/null 2>&1; then
pql plan rebuild >/dev/null 2>&1 || true
pql decisions sync >/dev/null 2>&1 || true
fi