2026-06-16 07:28:45 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
# install-hooks.sh — Install automaton git hooks into the current project.
|
|
|
|
|
#
|
|
|
|
|
# Usage: bash ~/.automaton/scripts/install-hooks.sh [project-path]
|
|
|
|
|
#
|
2026-06-26 16:51:39 -04:00
|
|
|
# Called automatically by onboard-project.sh. Can also be run manually
|
|
|
|
|
# after framework updates to refresh hooks.
|
|
|
|
|
#
|
2026-06-16 07:28:45 -04:00
|
|
|
# Installs pre-commit and pre-push hooks. The pre-commit hook blocks
|
|
|
|
|
# commits when no task is in implement/doc_review. The pre-push hook
|
|
|
|
|
# blocks pushes in the same condition, catching --no-verify bypasses.
|
2026-06-26 16:51:39 -04:00
|
|
|
#
|
|
|
|
|
# Next step: python3 ~/.automaton/scripts/status.py --create-task --project .
|
2026-06-16 07:28:45 -04:00
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
PROJECT_DIR="${1:-$(pwd)}"
|
|
|
|
|
GIT_DIR="$PROJECT_DIR/.git"
|
|
|
|
|
HOOKS_DIR="$GIT_DIR/hooks"
|
|
|
|
|
FRAMEWORK_DIR="$HOME/.automaton"
|
|
|
|
|
|
|
|
|
|
if [ ! -d "$GIT_DIR" ]; then
|
|
|
|
|
echo "ERROR: $PROJECT_DIR is not a git repository (no .git directory)"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
mkdir -p "$HOOKS_DIR"
|
|
|
|
|
|
|
|
|
|
HOOKS=(
|
|
|
|
|
"pre-commit"
|
|
|
|
|
"pre-push"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
installed=0
|
|
|
|
|
for hook in "${HOOKS[@]}"; do
|
|
|
|
|
SOURCE="$FRAMEWORK_DIR/scripts/git-hooks/$hook"
|
|
|
|
|
TARGET="$HOOKS_DIR/$hook"
|
|
|
|
|
if [ ! -f "$SOURCE" ]; then
|
|
|
|
|
echo "WARNING: Source hook not found: $SOURCE"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
cp "$SOURCE" "$TARGET"
|
|
|
|
|
chmod +x "$TARGET"
|
|
|
|
|
echo "Installed: $TARGET"
|
|
|
|
|
installed=$((installed + 1))
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "$installed hook(s) installed in $PROJECT_DIR"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "Pre-commit: Blocks commits without an active task in implement/doc_review"
|
|
|
|
|
echo "Pre-push: Blocks pushes without an active task (catches --no-verify bypasses)"
|
|
|
|
|
echo ""
|
|
|
|
|
echo "To reinstall after automaton update, re-run this script."
|