Files
beads/examples/git-hooks/post-checkout
Steve Yegge 101f094c91 fix(hooks): prevent rebase failures from deletions.jsonl writes
Two fixes to prevent git pull --rebase from failing:

1. Skip hook execution during rebase operations by detecting
   .git/rebase-merge or .git/rebase-apply directories

2. Use --no-git-history flag to prevent git-history-backfill
   from writing to deletions.jsonl during imports

The root cause was that post-checkout hooks were running during
rebase, triggering the git-history-backfill which appends to
deletions.jsonl. This created uncommitted changes that blocked
the rebase from continuing.

Bump hooks version to 0.26.0.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-27 00:51:07 -08:00

58 lines
1.6 KiB
Bash
Executable File

#!/bin/sh
# bd-hooks-version: 0.26.0
#
# bd (beads) post-checkout hook
#
# This hook syncs the bd database after a branch checkout:
# 1. Checks if any .beads/*.jsonl file was updated
# 2. Runs 'bd sync --import-only --no-git-history' to import changes
#
# Arguments provided by git:
# $1 = ref of previous HEAD
# $2 = ref of new HEAD
# $3 = flag (1 if branch checkout, 0 if file checkout)
#
# Install: cp examples/git-hooks/post-checkout .git/hooks/post-checkout && chmod +x .git/hooks/post-checkout
# Only run on branch checkouts
if [ "$3" != "1" ]; then
exit 0
fi
# Skip during rebase - git checks out commits during rebase and we must not
# modify working tree files (like deletions.jsonl) or the rebase will fail
if [ -d .git/rebase-merge ] || [ -d .git/rebase-apply ]; then
exit 0
fi
# Check if bd is available
if ! command -v bd >/dev/null 2>&1; then
exit 0
fi
# Check if we're in a bd workspace
if [ ! -d .beads ]; then
exit 0
fi
# Check if any JSONL file exists in .beads/
if ! ls .beads/*.jsonl >/dev/null 2>&1; then
exit 0
fi
# Run bd sync --import-only --no-git-history to import the updated JSONL
# --no-git-history prevents writes to deletions.jsonl (critical during rebase)
if ! output=$(bd sync --import-only --no-git-history 2>&1); then
echo "Warning: Failed to sync bd changes after checkout" >&2
echo "$output" >&2
echo "" >&2
echo "Run 'bd doctor --fix' to diagnose and repair" >&2
# Don't fail the checkout, just warn
fi
# Run quick health check (silent on success, hints if issues found)
# This catches version mismatches, outdated hooks, etc.
bd doctor --check-health 2>/dev/null || true
exit 0