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!"