Merge GH#532

This commit is contained in:
Steve Yegge
2025-12-16 01:19:14 -08:00
7 changed files with 9777 additions and 32 deletions

View File

@@ -23,20 +23,12 @@ if ! command -v bd >/dev/null 2>&1; then
exit 0
fi
# 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
# Check if we're in a bd workspace
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:-}"
@@ -54,36 +46,18 @@ 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
<<<<<<< HEAD
# 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 "Warning: Failed to flush bd changes to JSONL" >&2
echo "Run 'bd sync --flush-only' manually to diagnose" >&2
# Continue with commit - don't block code changes due to beads issues
=======
# Note: We warn but don't fail - this allows commits to proceed even if
# beads has issues (e.g., user removed .beads from their branch)
if ! bd sync --flush-only >/dev/null 2>&1; then
echo "Warning: Failed to flush bd changes to JSONL" >&2
echo "Run 'bd sync --flush-only' manually to diagnose" >&2
# Don't block the commit - user may have removed beads or have other issues
>>>>>>> origin/bd-l0pg-slit
fi
# Stage all tracked JSONL files (issues.jsonl is canonical, beads.jsonl for backward compat, deletions.jsonl for deletion propagation)
# For worktrees, .beads is in the main repo's working tree, not the worktree,
# so we can't use git add. Skip staging for worktrees.
if [ "$(git rev-parse --git-dir)" = "$(git rev-parse --git-common-dir)" ]; then
# Regular repo: files are in the working tree, safe to add
# git add is harmless if file doesn't exist
for f in .beads/beads.jsonl .beads/issues.jsonl .beads/deletions.jsonl; do
[ -f "$f" ] && git add "$f" 2>/dev/null || true
done
else
# Worktree: .beads is in the main repo's working tree, not this worktree
# Git rejects adding files outside the worktree, so we skip it.
# The main repo will see the changes on the next pull/sync.
: # do nothing
fi
# Stage all tracked JSONL files (beads.jsonl, issues.jsonl for backward compat, deletions.jsonl for deletion propagation)
# git add is harmless if file doesn't exist
for f in .beads/beads.jsonl .beads/issues.jsonl .beads/deletions.jsonl; do
[ -f "$f" ] && git add "$f" 2>/dev/null || true
done
exit 0

View File

@@ -28,6 +28,12 @@ if [ ! -d .beads ]; then
exit 0
fi
# Skip if bd sync is already in progress (GH#532: prevents circular error)
# bd sync sets this env var when pushing from worktree
if [ -n "$BD_SYNC_IN_PROGRESS" ]; then
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:-}"