#!/usr/bin/env bash # safe-commit.sh – Commit with pre-commit hooks guaranteed to run # Usage: ./scripts/safe-commit.sh "commit message" # # This script ensures lint checks always execute, even when committing # from non-interactive contexts (CI, AI agents, etc.). set -euo pipefail if [ -z "${1:-}" ]; then echo "❌ Usage: ./scripts/safe-commit.sh \"commit message\"" exit 1 fi MSG="$1" REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$REPO_ROOT" # Ensure hooks directory exists and is configured if [ -d ".husky" ]; then git config core.hooksPath .husky fi # Run lint-staged manually as a safety net (in case hook is skipped) if command -v npx &>/dev/null && [ -f "node_modules/.bin/lint-staged" ]; then echo "🔍 Running pre-commit lint checks..." npx lint-staged || { echo "" echo "❌ Lint checks failed. Commit aborted." echo " Fix the errors above and try again." exit 1 } echo "✅ All lint checks passed." fi # Commit with hooks enabled (no --no-verify) git commit -m "$MSG"