Improve pre-push hook: suggest bd sync with auto-sync option

The pre-push hook now provides better guidance when beads JSONL has
uncommitted changes:

- Interactive terminals: Prompts to auto-run 'bd sync' (y/N)
- Non-interactive/CI: Shows 'bd sync' command to run
- Fallback: Manual git commands if bd not available

This addresses the UX issue where users weren't sure they should
run 'bd sync' instead of manual git commands.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-11-23 16:10:02 -08:00
parent 9a9d04fb9c
commit 106499c4fc
4 changed files with 158 additions and 21 deletions

View File

@@ -48,14 +48,57 @@ if [ -n "$FILES" ]; then
echo "❌ Error: Beads JSONL 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 before pushing:" >&2
echo "" >&2
# shellcheck disable=SC2086
echo " git add $FILES" >&2
echo ' git commit -m "Update bd JSONL"' >&2
echo " git push" >&2
echo "" >&2
exit 1
# Check if bd is available and offer auto-sync
if command -v bd >/dev/null 2>&1; then
# Check if we're in an interactive terminal
if [ -t 0 ]; then
echo "Would you like to run 'bd sync' now to commit and push these changes? [y/N]" >&2
read -r response
case "$response" in
[yY][eE][sS]|[yY])
echo "" >&2
echo "Running: bd sync" >&2
if bd sync; then
echo "" >&2
echo "✓ Sync complete. Continuing with push..." >&2
exit 0
else
echo "" >&2
echo "❌ Sync failed. Push aborted." >&2
exit 1
fi
;;
*)
echo "" >&2
echo "Push aborted. Run 'bd sync' manually when ready:" >&2
echo "" >&2
echo " bd sync" >&2
echo " git push" >&2
echo "" >&2
exit 1
;;
esac
else
# Non-interactive: just show the message
echo "Run 'bd sync' to commit these changes:" >&2
echo "" >&2
echo " bd sync" >&2
echo "" >&2
exit 1
fi
else
# bd not available, fall back to manual git commands
echo "Please commit the updated JSONL before pushing:" >&2
echo "" >&2
# shellcheck disable=SC2086
echo " git add $FILES" >&2
echo ' git commit -m "Update bd JSONL"' >&2
echo " git push" >&2
echo "" >&2
exit 1
fi
fi
fi