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>
This commit is contained in:
2026-06-16 12:42:08 +02:00
co-authored by Claude Opus 4.8
parent 34ffcda86f
commit b24a3596b5
+11 -14
View File
@@ -6,19 +6,16 @@
# in sync with the changelog. File-level checkouts ($3 == 0) are skipped. # in sync with the changelog. File-level checkouts ($3 == 0) are skipped.
# Args: <prev-HEAD> <new-HEAD> <branch-flag>. # Args: <prev-HEAD> <new-HEAD> <branch-flag>.
# #
# prev-HEAD == new-HEAD means the working-tree content did not change — a branch # Only a real branch *switch* (prev-HEAD != new-HEAD) loads a different changelog
# *creation* (`git checkout -b`) or a no-op checkout. pql.db is already correct # and needs a rebuild. On a branch *creation* (`git checkout -b`) or no-op checkout
# for this content, so a `plan rebuild` here would only DROP uncommitted ticket # (prev == new) the working-tree content is unchanged, so pql.db already holds the
# mutations that have not reached the changelog yet (e.g. a just-activated # committed state AND any uncommitted ticket mutation set just before the branch was
# in_progress status set right before the branch was cut). Instead, flush + stage # cut (e.g. a just-activated in_progress status) — so do NOTHING. A rebuild there
# them — the same changelog capture the pre-commit hook does — so the activation # would drop that mutation; the next commit's pre-commit hook flushes it normally.
# is durable across the checkout. A real branch *switch* (prev != new) loads a # Doing nothing (rather than an eager `export --stage`) also avoids staging changelog
# different changelog, so rebuild pql.db to match the branch we moved to. # rows mid-checkout — those could otherwise leak onto the wrong branch when a later
if [ "${3:-0}" = "1" ] && command -v pql >/dev/null 2>&1; then # switch rebuilds by replaying the working-tree changelog.
if [ "$1" = "$2" ]; then if [ "${3:-0}" = "1" ] && [ "$1" != "$2" ] && command -v pql >/dev/null 2>&1; then
pql plan export --stage >/dev/null 2>&1 || true pql plan rebuild >/dev/null 2>&1 || true
else
pql plan rebuild >/dev/null 2>&1 || true
fi
pql decisions sync >/dev/null 2>&1 || true pql decisions sync >/dev/null 2>&1 || true
fi fi