echo "π Running pre-commit validations..."
# Check for sensitive files first (exclude .env.example which is a template)
echo "π Checking for sensitive files..."
if git diff --cached --name-only | grep -E "\.(key|pem|p12|pfx)$|\.env$|\.env\.(local|development|test|production)$" > /dev/null; then
echo "β Attempting to commit sensitive files. Please remove them from the commit."
git diff --cached --name-only | grep -E "\.(key|pem|p12|pfx)$|\.env$|\.env\.(local|development|test|production)$"
exit 1
fi
# NEW: Check for untracked source files that might be imported (REQ-2)
echo "π Checking for untracked source files..."
UNTRACKED_SRC=$(find src -name "*.ts" -type f 2>/dev/null | while read -r file; do
if ! git ls-files --error-unmatch "$file" >/dev/null 2>&1; then
echo "$file"
fi
done)
if [ -n "$UNTRACKED_SRC" ]; then
echo "β Found untracked source files that may cause CI failures:"
echo "$UNTRACKED_SRC"
echo ""
echo "π‘ These files exist locally but are not tracked by git."
echo " CI will fail because it only sees tracked files."
echo " Add these files: git add <files>"
exit 1
fi
# NEW: Validate gitignore patterns don't ignore source code (REQ-2)
echo "π Validating .gitignore patterns..."
IGNORED_SRC=$(git check-ignore src/**/*.ts 2>/dev/null || true)
if [ -n "$IGNORED_SRC" ]; then
echo "β Source files are being ignored by .gitignore:"
echo "$IGNORED_SRC"
echo ""
echo "π‘ This WILL cause CI failures. Fix .gitignore patterns."
echo " Use leading '/' to anchor patterns to repository root."
echo " Example: '/memory/' only matches root-level memory directory"
exit 1
fi
# Run CI validation (same as CI: audit, format:check, lint:strict, typecheck, test:coverage)
echo "ποΈ Running CI validation..."
timeout 800s npm run validate:ci
if [ $? -ne 0 ]; then
echo "β CI validation failed. Please fix the issues above."
echo "π‘ CI validation includes: security audit, format check, strict lint (zero warnings), typecheck, tests with coverage."
exit 1
fi
echo "β
Pre-commit validations passed!"