diff --git a/.config/hooks/post-checkout b/.config/hooks/post-checkout index a637ad9c6..660157cd2 100755 --- a/.config/hooks/post-checkout +++ b/.config/hooks/post-checkout @@ -16,6 +16,17 @@ # 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 + # Resolve the vault to THIS checkout explicitly. pql otherwise finds the vault + # by walking up for a `.git` *directory* — but a linked worktree's `.git` is a + # *file*, so a bare `pql` invoked from a worktree resolves to the MAIN checkout + # and rebuilds main's pql.db, leaving the worktree's own empty (the symptom that + # broke ticket/decision reads inside worktrees). `git rev-parse --show-toplevel` + # returns this worktree's root; on the main checkout it is the repo root, so + # this is a no-op there and a correctness fix in worktrees. (Upstream pql bug — + # ~/Projects/pql/feature-request.md FR-4; drop the --vault once it lands.) + vault="$(git rev-parse --show-toplevel 2>/dev/null)" + if [ -n "$vault" ]; then + pql --vault "$vault" plan rebuild >/dev/null 2>&1 || true + pql --vault "$vault" decisions sync >/dev/null 2>&1 || true + fi fi