feat(hooks): make git hooks sync.branch aware (bd-8ib)

When sync.branch is configured, .beads changes are committed to a
separate branch via worktree rather than the current branch. Updated
both hooks to detect this configuration and skip the uncommitted
.beads check in that scenario.

Changes:
- pre-push: Skip uncommitted .beads check when sync.branch is set
- pre-commit: Skip flush and auto-staging when sync.branch is set
- Both: Use --json output for reliable config value detection
- Bump version to 0.22.2

🤖 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-30 10:46:27 -08:00
parent 6da8763100
commit cfe7d14ac4
2 changed files with 30 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
#!/bin/sh
# bd-hooks-version: 0.22.1
# bd-hooks-version: 0.22.2
#
# bd (beads) pre-push hook
#
@@ -8,6 +8,9 @@
# 2. Checking for uncommitted changes (staged, unstaged, untracked, deleted)
# 3. Failing the push with clear instructions if changes found
#
# When sync.branch is configured, .beads changes are committed to a separate
# branch via worktree, so the uncommitted check is skipped for the main branch.
#
# The pre-commit hook already exports changes, but this catches:
# - Changes made between commit and push
# - Pending debounced flushes (5s daemon delay)
@@ -25,6 +28,18 @@ if [ ! -d .beads ]; then
exit 0
fi
# Check if sync.branch is configured - if so, .beads changes go to a separate
# branch via worktree, not the current branch, so skip the uncommitted check
if command -v bd >/dev/null 2>&1; then
# Use --json to get clean output (human-readable format prints "(not set)")
SYNC_BRANCH=$(bd config get sync.branch --json 2>/dev/null | grep -o '"value": *"[^"]*"' | sed 's/"value": *"\([^"]*\)"/\1/')
if [ -n "$SYNC_BRANCH" ]; then
# sync.branch is configured, skip .beads uncommitted check
# Changes are synced to the separate branch, not this one
exit 0
fi
fi
# Optionally flush pending bd changes so they surface in JSONL
# This prevents the race where a debounced flush lands after the check
if command -v bd >/dev/null 2>&1; then