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 (requires bd version bump to take effect).

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-27 00:55:06 -08:00
parent 1c2aa6159b
commit 99fff192eb
2 changed files with 22 additions and 8 deletions

View File

@@ -1,11 +1,11 @@
#!/bin/sh
# bd-hooks-version: 0.25.1
# 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' to import changes
# 2. Runs 'bd sync --import-only --no-git-history' to import changes
#
# Arguments provided by git:
# $1 = ref of previous HEAD
@@ -19,6 +19,12 @@ 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
@@ -34,8 +40,9 @@ if ! ls .beads/*.jsonl >/dev/null 2>&1; then
exit 0
fi
# Run bd sync --import-only to import the updated JSONL
if ! output=$(bd sync --import-only 2>&1); then
# 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

View File

@@ -1,11 +1,11 @@
#!/bin/sh
# bd-hooks-version: 0.25.1
# bd-hooks-version: 0.26.0
#
# bd (beads) post-merge hook
#
# This hook syncs the bd database after a git pull or merge:
# 1. Checks if any .beads/*.jsonl file was updated
# 2. Runs 'bd sync --import-only' to import changes
# 2. Runs 'bd sync --import-only --no-git-history' to import changes
#
# Installation:
# cp examples/git-hooks/post-merge .git/hooks/post-merge
@@ -14,6 +14,12 @@
# Or use the install script:
# examples/git-hooks/install.sh
# Skip during rebase - git may run post-merge during rebase operations
# and we must not modify working tree files 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
echo "Warning: bd command not found, skipping post-merge sync" >&2
@@ -31,10 +37,11 @@ if ! ls .beads/*.jsonl >/dev/null 2>&1; then
exit 0
fi
# Run bd sync --import-only to import the updated JSONL
# Run bd sync --import-only --no-git-history to import the updated JSONL
# --no-git-history prevents writes to deletions.jsonl during hook operations
# This is more robust than direct import as it handles all edge cases
# Capture both stdout and stderr to show user what went wrong
if ! output=$(bd sync --import-only 2>&1); then
if ! output=$(bd sync --import-only --no-git-history 2>&1); then
echo "Warning: Failed to sync bd changes after merge" >&2
echo "$output" >&2
echo "" >&2