97 lines
2.3 KiB
Bash
Executable File
97 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Install git hooks for the project
|
|
|
|
set -e
|
|
|
|
HOOKS_DIR=".git/hooks"
|
|
SCRIPTS_DIR="scripts"
|
|
|
|
echo "Installing git hooks..."
|
|
echo ""
|
|
|
|
# Create hooks directory if it doesn't exist
|
|
mkdir -p "$HOOKS_DIR"
|
|
|
|
# Pre-commit hook
|
|
cat > "$HOOKS_DIR/pre-commit" << 'EOF'
|
|
#!/usr/bin/env bash
|
|
# Git pre-commit hook - runs linting before commit
|
|
|
|
echo "🔍 Running pre-commit linting..."
|
|
echo ""
|
|
|
|
# Use nix flake linting for consistency
|
|
if ! nix run .#lint; then
|
|
echo ""
|
|
echo "❌ Linting failed. Fix errors or use --no-verify to skip."
|
|
echo " Auto-fix: nix run .#lint-fix"
|
|
exit 1
|
|
fi
|
|
|
|
echo ""
|
|
echo "✅ Pre-commit checks passed!"
|
|
EOF
|
|
|
|
chmod +x "$HOOKS_DIR/pre-commit"
|
|
echo "✓ Installed pre-commit hook"
|
|
|
|
# Pre-push hook (DISABLED by default - enable when tests are ready)
|
|
cat > "$HOOKS_DIR/pre-push.disabled" << 'EOF'
|
|
#!/usr/bin/env bash
|
|
# Git pre-push hook - runs tests before push
|
|
#
|
|
# TO ENABLE: Rename this file to 'pre-push' (remove .disabled)
|
|
# TO DISABLE: Rename back to 'pre-push.disabled'
|
|
# OR use: git push --no-verify
|
|
|
|
echo "🧪 Running tests before push..."
|
|
echo ""
|
|
|
|
# Backend tests (if pytest is available)
|
|
if [ -d "backend" ] && command -v pytest &> /dev/null; then
|
|
cd backend
|
|
# Run tests without coverage requirement for pre-push
|
|
if ! pytest -xvs --tb=short --no-cov; then
|
|
echo ""
|
|
echo "❌ Backend tests failed. Fix tests or use --no-verify to skip."
|
|
exit 1
|
|
fi
|
|
cd ..
|
|
fi
|
|
|
|
# Frontend tests (if npm test is available)
|
|
if [ -d "frontend/node_modules" ]; then
|
|
cd frontend
|
|
if ! npm test -- --run; then
|
|
echo ""
|
|
echo "❌ Frontend tests failed. Fix tests or use --no-verify to skip."
|
|
exit 1
|
|
fi
|
|
cd ..
|
|
fi
|
|
|
|
echo ""
|
|
echo "✅ All tests passed!"
|
|
EOF
|
|
|
|
chmod +x "$HOOKS_DIR/pre-push.disabled"
|
|
echo "✓ Created pre-push hook template (disabled by default)"
|
|
echo " To enable: mv .git/hooks/pre-push.disabled .git/hooks/pre-push"
|
|
|
|
echo ""
|
|
echo "========================================="
|
|
echo "✅ Git hooks installed successfully!"
|
|
echo "========================================="
|
|
echo ""
|
|
echo "Hooks installed:"
|
|
echo " • pre-commit - Runs linting before commit"
|
|
echo " • pre-push - Runs tests before push (optional)"
|
|
echo ""
|
|
echo "To skip hooks when committing:"
|
|
echo " git commit --no-verify"
|
|
echo ""
|
|
echo "To uninstall:"
|
|
echo " rm .git/hooks/pre-commit .git/hooks/pre-push"
|
|
echo ""
|
|
|