Files
beads/cmd/bd/templates/hooks/post-merge
Steve Yegge aed166fe85 fix: improve issue ID prefix extraction for word-like suffixes
Refine ExtractIssuePrefix to better distinguish hash IDs from English
words in multi-part issue IDs. Hash suffixes now require digits or be
exactly 3 chars, preventing "test", "gate", "part" from being treated
as hashes. This fixes prefix extraction for IDs like "vc-baseline-test".

Also updates git hooks to use -q flag and adds AGENTS.md documentation.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-16 13:19:22 -08:00

57 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# bd-hooks-version: 0.30.1
#
# 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 --no-git-history' to import changes
#
# Installation:
# cp examples/git-hooks/post-merge .git/hooks/post-merge
# chmod +x .git/hooks/post-merge
#
# 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
exit 0
fi
# Check if we're in a bd workspace
if [ ! -d .beads ]; then
# Not a bd workspace, nothing to do
exit 0
fi
# Check if any JSONL file exists in .beads/
if ! ls .beads/*.jsonl >/dev/null 2>&1; then
exit 0
fi
# 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 --no-git-history 2>&1); then
echo "Warning: Failed to sync bd changes after merge" >&2
echo "$output" >&2
echo "" >&2
echo "Run 'bd doctor --fix' to diagnose and repair" >&2
# Don't fail the merge, just warn
fi
# Run quick health check (silent on success, hints if issues found)
# This catches version mismatches, outdated hooks, etc.
bd doctor --check-health 2>/dev/null || true
exit 0