Add pre-push hook to prevent stale JSONL exports
This commit is contained in:
@@ -28,7 +28,7 @@ fi
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# Hooks to install
|
||||
HOOKS="pre-commit post-merge"
|
||||
HOOKS="pre-commit post-merge pre-push"
|
||||
|
||||
echo "Installing bd git hooks..."
|
||||
|
||||
@@ -60,5 +60,6 @@ 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 " pre-push - Exports database to JSONL before push (prevents stale JSONL)"
|
||||
echo ""
|
||||
echo "To uninstall, remove .git/hooks/pre-commit and .git/hooks/post-merge"
|
||||
echo "To uninstall, remove the hooks from .git/hooks/"
|
||||
|
||||
51
examples/git-hooks/pre-push
Executable file
51
examples/git-hooks/pre-push
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# bd (beads) pre-push hook
|
||||
#
|
||||
# This hook ensures that the database is exported to JSONL before pushing,
|
||||
# preventing the problem where database changes are committed without
|
||||
# corresponding JSONL updates.
|
||||
#
|
||||
# Installation:
|
||||
# cp examples/git-hooks/pre-push .git/hooks/pre-push
|
||||
# chmod +x .git/hooks/pre-push
|
||||
#
|
||||
# Or use the install script:
|
||||
# examples/git-hooks/install.sh
|
||||
|
||||
# Check if bd is available
|
||||
if ! command -v bd >/dev/null 2>&1; then
|
||||
echo "Warning: bd command not found, skipping pre-push export check" >&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 database is newer than JSONL
|
||||
DB_FILE=".beads/beads.db"
|
||||
JSONL_FILE=".beads/beads.jsonl"
|
||||
|
||||
if [ -f "$DB_FILE" ] && [ -f "$JSONL_FILE" ]; then
|
||||
# Get modification times
|
||||
if [ "$DB_FILE" -nt "$JSONL_FILE" ]; then
|
||||
echo "⚠️ Database is newer than JSONL - exporting before push..." >&2
|
||||
|
||||
# Force export to ensure JSONL is up to date
|
||||
if ! BEADS_NO_DAEMON=1 bd export --output "$JSONL_FILE" >/dev/null 2>&1; then
|
||||
echo "Error: Failed to export database to JSONL" >&2
|
||||
echo "Run 'bd export' manually to diagnose" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Stage the updated JSONL
|
||||
git add "$JSONL_FILE" 2>/dev/null || true
|
||||
|
||||
echo "✓ Exported database to JSONL" >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user