#!/bin/bash # Quick Pre-Push Hook Script # Minimal checks for quick fixes and small changes # Use this for: styling, text changes, minor bug fixes set -e # Exit on any error echo "⚡ Running QUICK Pre-Push Checks..." echo "===================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Function to print colored output print_status() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Check if we're in a git repository if ! git rev-parse --git-dir > /dev/null 2>&1; then print_error "Not in a git repository!" exit 1 fi # Get current branch CURRENT_BRANCH=$(git branch --show-current) print_status "Current branch: $CURRENT_BRANCH" # Check if there are uncommitted changes if ! git diff-index --quiet HEAD --; then print_error "You have uncommitted changes. Please commit or stash them first." exit 1 fi # 1. Quick ESLint check (only on changed files) print_status "Running ESLint on changed files..." CHANGED_FILES=$(git diff --name-only --cached | grep -E '\.(ts|tsx|js|jsx)$' || true) if [ -n "$CHANGED_FILES" ]; then if ! npx eslint $CHANGED_FILES; then print_error "ESLint failed on changed files! Please fix the errors." exit 1 fi print_success "ESLint passed on changed files" else print_status "No TypeScript/JavaScript files changed, skipping ESLint" fi # 2. Quick Type Check (only on changed files) print_status "Running TypeScript type check on changed files..." if [ -n "$CHANGED_FILES" ]; then if ! npx tsc --noEmit --skipLibCheck; then print_error "TypeScript type check failed!" exit 1 fi print_success "TypeScript type check passed" else print_status "No TypeScript files changed, skipping type check" fi # 3. Check for obvious syntax errors (very fast) print_status "Checking for syntax errors..." if ! node -c package.json 2>/dev/null; then print_error "Package.json syntax error!" exit 1 fi echo "" echo "===================================" print_success "Quick pre-push checks passed! ⚡" print_status "Ready to push to $CURRENT_BRANCH" print_warning "Note: Full tests and build will run in CI/CD" echo "===================================" # Show what will be pushed echo "" print_status "Files to be pushed:" git diff --name-only origin/$CURRENT_BRANCH..HEAD 2>/dev/null || git diff --name-only HEAD~1..HEAD echo "" print_status "Proceeding with quick push..."