The original pre-push hook tried to export DB → JSONL during the push, then run 'git add', but this doesn't work because: 1. The commit is already created when pre-push runs 2. git add in pre-push stages files for a FUTURE commit 3. The current push sends the old commit with stale JSONL 4. Result: dirty git status after push Fix: - Pre-push now CHECKS for uncommitted JSONL changes - If found, it FAILS the push with clear instructions - User must commit JSONL before pushing - This prevents stale JSONL from reaching remote The pre-commit hook already properly flushes changes, so this catch-all prevents changes made BETWEEN commit and push. Amp-Thread-ID: https://ampcode.com/threads/T-39a89553-c301-4d4f-b39f-6df9c403d22b Co-authored-by: Amp <amp@ampcode.com>
57 lines
1.7 KiB
Bash
Executable File
57 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# bd-hooks-version: 0.22.0
|
|
#
|
|
# bd (beads) pre-push hook
|
|
#
|
|
# This hook checks if the database has uncommitted changes and prevents
|
|
# pushing stale JSONL by failing with a clear error message.
|
|
#
|
|
# The pre-commit hook should have already exported changes, but if new
|
|
# changes were made between commit and push, this hook catches that.
|
|
#
|
|
# 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
|
|
# If bd is not available, we can't check - allow push
|
|
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
|
|
|
|
# Find the JSONL file (could be issues.jsonl or beads.jsonl)
|
|
JSONL_FILE=""
|
|
if [ -f .beads/beads.jsonl ]; then
|
|
JSONL_FILE=".beads/beads.jsonl"
|
|
elif [ -f .beads/issues.jsonl ]; then
|
|
JSONL_FILE=".beads/issues.jsonl"
|
|
fi
|
|
|
|
# Check if JSONL file has uncommitted changes
|
|
if [ -n "$JSONL_FILE" ] && [ -f "$JSONL_FILE" ]; then
|
|
# Check git status for the JSONL file
|
|
if ! git diff --quiet "$JSONL_FILE" 2>/dev/null || ! git diff --cached --quiet "$JSONL_FILE" 2>/dev/null; then
|
|
echo "❌ Error: $JSONL_FILE has uncommitted changes" >&2
|
|
echo "" >&2
|
|
echo "You made changes to bd issues between your last commit and this push." >&2
|
|
echo "Please commit the updated JSONL file before pushing:" >&2
|
|
echo "" >&2
|
|
echo " git add $JSONL_FILE" >&2
|
|
echo " git commit -m \"Update beads JSONL\"" >&2
|
|
echo " git push" >&2
|
|
echo "" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
exit 0
|