feat(hooks): chain bd hook shims into repo .githooks

bd hooks install (shim 1.1.0) appended its managed sections to the tracked
.githooks/pre-commit and pre-push and added post-checkout, post-merge, and
prepare-commit-msg shims. Commit them so the repo dogfoods bd's git hook
integration, with two fixes to the host scripts so the chained sections
actually work:

- pre-commit/pre-push exited early (no staged Go files / not a tag push)
  before ever reaching the appended beads section; those exits are now
  conditional blocks.
- Both scripts run under set -euo pipefail, which aborted the hook before
  the managed section's exit-code handling (timeout -> continue without
  beads, uninitialized DB -> skip) could apply; set +e now precedes the
  managed section.
- pre-push drained the ref list from stdin; it now captures and re-feeds
  it so the chained bd hook keeps the pre-push stdin contract.

The managed sections themselves are untouched (bd owns the markers).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge 2026-07-12 19:03:43 -07:00
commit 96ec4db4e5
5 changed files with 205 additions and 29 deletions

33
.githooks/post-checkout Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env sh
# --- BEGIN BEADS INTEGRATION v1.1.0 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
_bd_timeout=${BEADS_HOOK_TIMEOUT:-300}
_bd_used_perl=0
if command -v timeout >/dev/null 2>&1; then
timeout "$_bd_timeout" bd hooks run post-checkout "$@"
_bd_exit=$?
elif command -v gtimeout >/dev/null 2>&1; then
gtimeout "$_bd_timeout" bd hooks run post-checkout "$@"
_bd_exit=$?
elif command -v perl >/dev/null 2>&1; then
_bd_used_perl=1
perl -e 'alarm shift; exec @ARGV' "$_bd_timeout" bd hooks run post-checkout "$@"
_bd_exit=$?
else
echo >&2 "beads: hook 'post-checkout' running without timeout; install coreutils or perl to enable BEADS_HOOK_TIMEOUT"
bd hooks run post-checkout "$@"
_bd_exit=$?
fi
if [ $_bd_exit -eq 124 ] || { [ $_bd_used_perl -eq 1 ] && [ $_bd_exit -eq 142 ]; }; then
echo >&2 "beads: hook 'post-checkout' timed out after ${_bd_timeout}s — continuing without beads"
_bd_exit=0
fi
if [ $_bd_exit -eq 3 ]; then
echo >&2 "beads: database not initialized — skipping hook 'post-checkout'"
_bd_exit=0
fi
if [ $_bd_exit -ne 0 ]; then exit $_bd_exit; fi
fi
# --- END BEADS INTEGRATION v1.1.0 ---

33
.githooks/post-merge Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env sh
# --- BEGIN BEADS INTEGRATION v1.1.0 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
_bd_timeout=${BEADS_HOOK_TIMEOUT:-300}
_bd_used_perl=0
if command -v timeout >/dev/null 2>&1; then
timeout "$_bd_timeout" bd hooks run post-merge "$@"
_bd_exit=$?
elif command -v gtimeout >/dev/null 2>&1; then
gtimeout "$_bd_timeout" bd hooks run post-merge "$@"
_bd_exit=$?
elif command -v perl >/dev/null 2>&1; then
_bd_used_perl=1
perl -e 'alarm shift; exec @ARGV' "$_bd_timeout" bd hooks run post-merge "$@"
_bd_exit=$?
else
echo >&2 "beads: hook 'post-merge' running without timeout; install coreutils or perl to enable BEADS_HOOK_TIMEOUT"
bd hooks run post-merge "$@"
_bd_exit=$?
fi
if [ $_bd_exit -eq 124 ] || { [ $_bd_used_perl -eq 1 ] && [ $_bd_exit -eq 142 ]; }; then
echo >&2 "beads: hook 'post-merge' timed out after ${_bd_timeout}s — continuing without beads"
_bd_exit=0
fi
if [ $_bd_exit -eq 3 ]; then
echo >&2 "beads: database not initialized — skipping hook 'post-merge'"
_bd_exit=0
fi
if [ $_bd_exit -ne 0 ]; then exit $_bd_exit; fi
fi
# --- END BEADS INTEGRATION v1.1.0 ---

View file

@ -5,22 +5,60 @@
set -euo pipefail
# Only check staged Go files (Added, Copied, Modified)
# Only check staged Go files (Added, Copied, Modified). No early exit here:
# the beads section at the bottom must run for non-Go commits too.
staged_go_files=$(git diff --cached --name-only --diff-filter=ACM -- '*.go')
[ -z "$staged_go_files" ] && exit 0
if [ -n "$staged_go_files" ]; then
# Use go run so golangci-lint is always built with the project's Go
# toolchain, avoiding version-mismatch panics from a stale global binary.
GOLANGCI_LINT="go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1"
# Use go run so golangci-lint is always built with the project's Go
# toolchain, avoiding version-mismatch panics from a stale global binary.
GOLANGCI_LINT="go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1"
# Auto-format and re-stage
echo "$staged_go_files" | xargs gofmt -w
echo "$staged_go_files" | xargs git add
# Auto-format and re-stage
echo "$staged_go_files" | xargs gofmt -w
echo "$staged_go_files" | xargs git add
# Lint changed code with auto-fix; block on remaining issues.
# CGO_ENABLED=0 avoids typecheck failures from CGO-only dependencies
# (e.g., dolthub/go-icu-regex) that require system headers not always present.
CGO_ENABLED=0 $GOLANGCI_LINT run --new-from-rev=HEAD --fix || exit 1
# Lint changed code with auto-fix; block on remaining issues.
# CGO_ENABLED=0 avoids typecheck failures from CGO-only dependencies
# (e.g., dolthub/go-icu-regex) that require system headers not always present.
CGO_ENABLED=0 $GOLANGCI_LINT run --new-from-rev=HEAD --fix || exit 1
# Re-stage any auto-fixes from the linter
echo "$staged_go_files" | xargs git add
fi
# Re-stage any auto-fixes from the linter
echo "$staged_go_files" | xargs git add
# The managed section below captures exit codes to tolerate timeouts and an
# uninitialized bd database; set -e would abort before that handling runs.
set +e
# --- BEGIN BEADS INTEGRATION v1.1.0 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
_bd_timeout=${BEADS_HOOK_TIMEOUT:-300}
_bd_used_perl=0
if command -v timeout >/dev/null 2>&1; then
timeout "$_bd_timeout" bd hooks run pre-commit "$@"
_bd_exit=$?
elif command -v gtimeout >/dev/null 2>&1; then
gtimeout "$_bd_timeout" bd hooks run pre-commit "$@"
_bd_exit=$?
elif command -v perl >/dev/null 2>&1; then
_bd_used_perl=1
perl -e 'alarm shift; exec @ARGV' "$_bd_timeout" bd hooks run pre-commit "$@"
_bd_exit=$?
else
echo >&2 "beads: hook 'pre-commit' running without timeout; install coreutils or perl to enable BEADS_HOOK_TIMEOUT"
bd hooks run pre-commit "$@"
_bd_exit=$?
fi
if [ $_bd_exit -eq 124 ] || { [ $_bd_used_perl -eq 1 ] && [ $_bd_exit -eq 142 ]; }; then
echo >&2 "beads: hook 'pre-commit' timed out after ${_bd_timeout}s — continuing without beads"
_bd_exit=0
fi
if [ $_bd_exit -eq 3 ]; then
echo >&2 "beads: database not initialized — skipping hook 'pre-commit'"
_bd_exit=0
fi
if [ $_bd_exit -ne 0 ]; then exit $_bd_exit; fi
fi
# --- END BEADS INTEGRATION v1.1.0 ---

View file

@ -12,27 +12,66 @@
set -euo pipefail
# git feeds "<local ref> <local sha> <remote ref> <remote sha>" lines on stdin.
# Capture it so the chained beads hook at the bottom still sees the ref list.
push_refs="$(cat)"
pushing_version_tag=0
while read -r local_ref _local_sha _remote_ref _remote_sha; do
case "$local_ref" in
refs/tags/v[0-9]*) pushing_version_tag=1 ;;
esac
done
done <<< "$push_refs"
[ "$pushing_version_tag" -eq 0 ] && exit 0
repo_root="$(git rev-parse --show-toplevel)"
if [ ! -x "$repo_root/scripts/check-versions.sh" ]; then
# Older checkout without the consistency check; do not block.
exit 0
if [ "$pushing_version_tag" -eq 1 ]; then
repo_root="$(git rev-parse --show-toplevel)"
# Skip on older checkouts without the consistency check; do not block.
if [ -x "$repo_root/scripts/check-versions.sh" ]; then
echo "Release tag push detected — verifying version + docs consistency..."
if ! (cd "$repo_root" && ./scripts/check-versions.sh); then
echo ""
echo "❌ Refusing to push release tag: version/docs are inconsistent." >&2
echo " Fix with: scripts/update-versions.sh <version>" >&2
echo " (or scripts/snapshot-release-docs.sh <version> for the docs side)." >&2
echo " Override with --no-verify only if you know what you are doing." >&2
exit 1
fi
fi
fi
echo "Release tag push detected — verifying version + docs consistency..."
if ! (cd "$repo_root" && ./scripts/check-versions.sh); then
echo ""
echo "❌ Refusing to push release tag: version/docs are inconsistent." >&2
echo " Fix with: scripts/update-versions.sh <version>" >&2
echo " (or scripts/snapshot-release-docs.sh <version> for the docs side)." >&2
echo " Override with --no-verify only if you know what you are doing." >&2
exit 1
# The managed section below captures exit codes to tolerate timeouts and an
# uninitialized bd database; set -e would abort before that handling runs.
set +e
exec < <(printf '%s\n' "$push_refs")
# --- BEGIN BEADS INTEGRATION v1.1.0 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
_bd_timeout=${BEADS_HOOK_TIMEOUT:-300}
_bd_used_perl=0
if command -v timeout >/dev/null 2>&1; then
timeout "$_bd_timeout" bd hooks run pre-push "$@"
_bd_exit=$?
elif command -v gtimeout >/dev/null 2>&1; then
gtimeout "$_bd_timeout" bd hooks run pre-push "$@"
_bd_exit=$?
elif command -v perl >/dev/null 2>&1; then
_bd_used_perl=1
perl -e 'alarm shift; exec @ARGV' "$_bd_timeout" bd hooks run pre-push "$@"
_bd_exit=$?
else
echo >&2 "beads: hook 'pre-push' running without timeout; install coreutils or perl to enable BEADS_HOOK_TIMEOUT"
bd hooks run pre-push "$@"
_bd_exit=$?
fi
if [ $_bd_exit -eq 124 ] || { [ $_bd_used_perl -eq 1 ] && [ $_bd_exit -eq 142 ]; }; then
echo >&2 "beads: hook 'pre-push' timed out after ${_bd_timeout}s — continuing without beads"
_bd_exit=0
fi
if [ $_bd_exit -eq 3 ]; then
echo >&2 "beads: database not initialized — skipping hook 'pre-push'"
_bd_exit=0
fi
if [ $_bd_exit -ne 0 ]; then exit $_bd_exit; fi
fi
# --- END BEADS INTEGRATION v1.1.0 ---

33
.githooks/prepare-commit-msg Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env sh
# --- BEGIN BEADS INTEGRATION v1.1.0 ---
# This section is managed by beads. Do not remove these markers.
if command -v bd >/dev/null 2>&1; then
export BD_GIT_HOOK=1
_bd_timeout=${BEADS_HOOK_TIMEOUT:-300}
_bd_used_perl=0
if command -v timeout >/dev/null 2>&1; then
timeout "$_bd_timeout" bd hooks run prepare-commit-msg "$@"
_bd_exit=$?
elif command -v gtimeout >/dev/null 2>&1; then
gtimeout "$_bd_timeout" bd hooks run prepare-commit-msg "$@"
_bd_exit=$?
elif command -v perl >/dev/null 2>&1; then
_bd_used_perl=1
perl -e 'alarm shift; exec @ARGV' "$_bd_timeout" bd hooks run prepare-commit-msg "$@"
_bd_exit=$?
else
echo >&2 "beads: hook 'prepare-commit-msg' running without timeout; install coreutils or perl to enable BEADS_HOOK_TIMEOUT"
bd hooks run prepare-commit-msg "$@"
_bd_exit=$?
fi
if [ $_bd_exit -eq 124 ] || { [ $_bd_used_perl -eq 1 ] && [ $_bd_exit -eq 142 ]; }; then
echo >&2 "beads: hook 'prepare-commit-msg' timed out after ${_bd_timeout}s — continuing without beads"
_bd_exit=0
fi
if [ $_bd_exit -eq 3 ]; then
echo >&2 "beads: database not initialized — skipping hook 'prepare-commit-msg'"
_bd_exit=0
fi
if [ $_bd_exit -ne 0 ]; then exit $_bd_exit; fi
fi
# --- END BEADS INTEGRATION v1.1.0 ---