fix(hooks): pre-commit no longer blocks when .beads removed (GH#483)
Two fixes to make pre-commit hook more resilient: 1. Check if beads is actually initialized (has db, config, or jsonl) - Empty .beads directory no longer triggers sync attempt - Handles case where .beads was removed from git but dir lingers 2. Make sync failure a warning instead of blocking error - Beads issues shouldn't prevent code commits - User can still run 'bd sync --flush-only' manually Also synced examples/git-hooks/pre-commit with template (worktree handling). Closes #483 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,12 +23,20 @@ if ! command -v bd >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if we're in a bd workspace
|
||||
# Check if we're in a bd workspace with an actual database
|
||||
# Just having a .beads directory isn't enough - it must be properly initialized
|
||||
if [ ! -d .beads ]; then
|
||||
# Not a bd workspace, nothing to do
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Verify beads is actually initialized (has database or config)
|
||||
# This handles the case where .beads was removed from git but directory lingers
|
||||
if [ ! -f .beads/beads.db ] && [ ! -f .beads/config.yaml ] && [ ! -f .beads/issues.jsonl ]; then
|
||||
# Directory exists but beads not initialized, nothing to do
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if sync-branch is configured in config.yaml or env var
|
||||
# If so, .beads changes go to a separate branch via worktree, not the current branch
|
||||
SYNC_BRANCH="${BEADS_SYNC_BRANCH:-}"
|
||||
@@ -46,10 +54,11 @@ fi
|
||||
# Flush pending changes to JSONL
|
||||
# Use --flush-only to skip git operations (we're already in a git hook)
|
||||
# Suppress output unless there's an error
|
||||
# Note: We don't block commits on flush failure - beads issues shouldn't prevent code commits
|
||||
if ! bd sync --flush-only >/dev/null 2>&1; then
|
||||
echo "Error: Failed to flush bd changes to JSONL" >&2
|
||||
echo "Warning: Failed to flush bd changes to JSONL" >&2
|
||||
echo "Run 'bd sync --flush-only' manually to diagnose" >&2
|
||||
exit 1
|
||||
# Continue with commit - don't block code changes due to beads issues
|
||||
fi
|
||||
|
||||
# Stage all tracked JSONL files (issues.jsonl is canonical, beads.jsonl for backward compat, deletions.jsonl for deletion propagation)
|
||||
|
||||
Reference in New Issue
Block a user