Files
beads/examples/git-hooks/install.sh
Steve Yegge 0344e1f08b Fix bd-51: Add git hooks to eliminate auto-flush race condition
- Added --flush-only flag to bd sync command
- Created pre-commit hook to flush pending changes before commit
- Created post-merge hook to import changes after pull/merge
- Added install script for easy setup
- Updated AGENTS.md with git hooks workflow
- Resolves race condition where daemon auto-flush fires after commit

Amp-Thread-ID: https://ampcode.com/threads/T-00b80d3a-4194-4c75-a60e-25a318cf9f91
Co-authored-by: Amp <amp@ampcode.com>
2025-10-24 22:17:06 -07:00

65 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
#
# Install bd git hooks
#
# This script copies the bd git hooks to your .git/hooks directory
# and makes them executable.
#
# Usage:
# ./examples/git-hooks/install.sh
set -e
# Check if we're in a git repository
if [ ! -d .git ]; then
echo "Error: Not in a git repository root" >&2
echo "Run this script from the root of your git repository" >&2
exit 1
fi
# Check if we're in a bd workspace
if [ ! -d .beads ]; then
echo "Error: Not in a bd workspace" >&2
echo "Run 'bd init' first" >&2
exit 1
fi
# Find the script directory (handles being called from anywhere)
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Hooks to install
HOOKS="pre-commit post-merge"
echo "Installing bd git hooks..."
for hook in $HOOKS; do
src="$SCRIPT_DIR/$hook"
dst=".git/hooks/$hook"
if [ ! -f "$src" ]; then
echo "Warning: Hook $hook not found at $src" >&2
continue
fi
# Backup existing hook if present
if [ -f "$dst" ]; then
backup="$dst.backup-$(date +%Y%m%d-%H%M%S)"
echo " Backing up existing $hook to $backup"
mv "$dst" "$backup"
fi
# Copy and make executable
cp "$src" "$dst"
chmod +x "$dst"
echo " Installed $hook"
done
echo ""
echo "✓ Git hooks installed successfully"
echo ""
echo "Hooks installed:"
echo " pre-commit - Flushes pending bd changes to JSONL before commit"
echo " post-merge - Imports updated JSONL after git pull/merge"
echo ""
echo "To uninstall, remove .git/hooks/pre-commit and .git/hooks/post-merge"