From 723a0095a073efdce17cb0122bba1d37c0fb9fb7 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sun, 26 Oct 2025 07:43:05 -0600 Subject: [PATCH] feat: prompt user if the pre-commit lint-fix changed anything --- .husky/pre-commit | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.husky/pre-commit b/.husky/pre-commit index 9d7ede0a..2f251261 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -9,6 +9,10 @@ echo "🔍 Running pre-commit hooks..." # Run lint-fix first echo "📝 Running lint-fix..." + +# Capture git status before lint-fix to detect changes +git_status_before=$(git status --porcelain) + npm run lint-fix || { echo echo "❌ Linting failed. Please fix the issues and try again." @@ -18,6 +22,37 @@ npm run lint-fix || { exit 1 } +# Check if lint-fix made any changes +git_status_after=$(git status --porcelain) + +if [ "$git_status_before" != "$git_status_after" ]; then + echo + echo "⚠️ lint-fix made changes to your files!" + echo "📋 Changes detected:" + git diff --name-only + echo + echo "❓ What would you like to do?" + echo " [c] Continue commit without the new changes" + echo " [a] Abort commit (recommended - review and stage the changes)" + echo + printf "Choose [c/a]: " + # The `< /dev/tty` is necessary to make read work in git's non-interactive shell + # The `|| choice="a"` is useful to set a default value to abort if read fails + read choice < /dev/tty + + case $choice in + [Cc]* ) + echo "✅ Continuing commit without lint-fix changes..." + sleep 3 + ;; + [Aa]* | * ) + echo "🛑 Commit aborted. Please review the changes made by lint-fix." + echo "💡 You can stage the changes with 'git add .' and commit again." + exit 1 + ;; + esac +fi + # Then run Build Architecture Guard #echo "🏗️ Running Build Architecture Guard..."