From d02905a4faae21b2e3af1f30652e7e8c0ebdc20b Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Sun, 30 Nov 2025 10:52:07 -0800 Subject: [PATCH] feat(hooks): make template hooks sync.branch aware (bd-8ib) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update the embedded template hooks (used by bd init) to also check for sync.branch configuration. This complements the earlier update to examples/git-hooks/. Changes: - templates/hooks/pre-push: Skip uncommitted check when sync.branch set - templates/hooks/pre-commit: Skip flush/staging when sync.branch set - Bump version to 0.27.1 for all hooks - Add sync.branch hooks change to --whats-new 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- cmd/bd/info.go | 5 +++-- cmd/bd/templates/hooks/post-checkout | 2 +- cmd/bd/templates/hooks/post-merge | 2 +- cmd/bd/templates/hooks/pre-commit | 15 ++++++++++++++- cmd/bd/templates/hooks/pre-push | 17 ++++++++++++++++- cmd/bd/version.go | 2 +- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/cmd/bd/info.go b/cmd/bd/info.go index df36421b..db12b7b6 100644 --- a/cmd/bd/info.go +++ b/cmd/bd/info.go @@ -288,9 +288,10 @@ type VersionChange struct { // versionChanges contains agent-actionable changes for recent versions var versionChanges = []VersionChange{ { - Version: "0.27.0", - Date: "2025-11-29", + Version: "0.27.1", + Date: "2025-11-30", Changes: []string{ + "Git hooks now sync.branch aware - pre-commit/pre-push skip .beads checks when sync.branch configured", "Custom Status States - Define project-specific statuses via config (testing, blocked, review)", "Contributor Fork Workflows - `bd init --contributor` auto-configures sync.remote=upstream", "Git Worktree Support - Full support for worktrees in hooks and detection", diff --git a/cmd/bd/templates/hooks/post-checkout b/cmd/bd/templates/hooks/post-checkout index e708a517..60947fc7 100755 --- a/cmd/bd/templates/hooks/post-checkout +++ b/cmd/bd/templates/hooks/post-checkout @@ -1,5 +1,5 @@ #!/bin/sh -# bd-hooks-version: 0.27.0 +# bd-hooks-version: 0.27.1 # # bd (beads) post-checkout hook # diff --git a/cmd/bd/templates/hooks/post-merge b/cmd/bd/templates/hooks/post-merge index f8ea22ea..57d10b70 100755 --- a/cmd/bd/templates/hooks/post-merge +++ b/cmd/bd/templates/hooks/post-merge @@ -1,5 +1,5 @@ #!/bin/sh -# bd-hooks-version: 0.27.0 +# bd-hooks-version: 0.27.1 # # bd (beads) post-merge hook # diff --git a/cmd/bd/templates/hooks/pre-commit b/cmd/bd/templates/hooks/pre-commit index c1a8a2c7..a580a091 100755 --- a/cmd/bd/templates/hooks/pre-commit +++ b/cmd/bd/templates/hooks/pre-commit @@ -1,5 +1,5 @@ #!/bin/sh -# bd-hooks-version: 0.27.0 +# bd-hooks-version: 0.27.1 # # bd (beads) pre-commit hook # @@ -7,6 +7,9 @@ # .beads/beads.jsonl before the commit is created, preventing the # race condition where daemon auto-flush fires after the commit. # +# When sync.branch is configured, .beads changes are committed to a separate +# branch via worktree, so auto-staging is skipped for the main branch. +# # Installation: # cp examples/git-hooks/pre-commit .git/hooks/pre-commit # chmod +x .git/hooks/pre-commit @@ -26,6 +29,16 @@ 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 +# 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 flush and auto-staging + # Changes are synced to the separate branch via 'bd sync' + exit 0 +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 diff --git a/cmd/bd/templates/hooks/pre-push b/cmd/bd/templates/hooks/pre-push index 03bf9039..5bf4a0eb 100755 --- a/cmd/bd/templates/hooks/pre-push +++ b/cmd/bd/templates/hooks/pre-push @@ -1,5 +1,5 @@ #!/bin/sh -# bd-hooks-version: 0.27.0 +# bd-hooks-version: 0.27.1 # # 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 diff --git a/cmd/bd/version.go b/cmd/bd/version.go index 5fa8a412..b5c230e4 100644 --- a/cmd/bd/version.go +++ b/cmd/bd/version.go @@ -14,7 +14,7 @@ import ( var ( // Version is the current version of bd (overridden by ldflags at build time) - Version = "0.27.0" + Version = "0.27.1" // Build can be set via ldflags at compile time Build = "dev" // Commit and branch the git revision the binary was built from (optional ldflag)