From 6b9df069b1a4dbbff03e0f18b1641534529fc933 Mon Sep 17 00:00:00 2001 From: Holger Schmermbeck Date: Sun, 2 Nov 2025 20:27:43 +0100 Subject: [PATCH] fix: improve pre-push error message for PR size violations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enhanced error message with clear visual separation and actionable guidance: Before (unclear): PR too large (644 > 600 lines). Please split into smaller slices. [followed by Git's generic 'error: failed to push' message] After (crystal clear): ═══════════════════════════════════════════════════════════════ ❌ PRE-PUSH CHECK FAILED: PR TOO LARGE ═══════════════════════════════════════════════════════════════ Your changes: 644 lines (636 insertions, 8 deletions) Maximum allowed: 600 lines per PR Action required: Split changes into smaller, focused PRs 💡 Available options: 1. Split PR: Recommended approach 2. Override check: touch .preflight-allow-large-pr 3. Bypass hook: git push --no-verify (not recommended) ═══════════════════════════════════════════════════════════════ Push aborted. Fix the issue above and try again. ═══════════════════════════════════════════════════════════════ Changes: - Added visual separators (borders) for attention - Show exact breakdown (insertions + deletions) - Numbered options for clarity - Clear "Push aborted" message before Git's error - Inserted blank lines for better readability Fixes #80 --- scripts/preflight.sh | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/scripts/preflight.sh b/scripts/preflight.sh index 01b7e28..824bfeb 100755 --- a/scripts/preflight.sh +++ b/scripts/preflight.sh @@ -270,18 +270,38 @@ else echo "Preflight OK · Changed lines: 0 (after exclusions)" exit 0 else - # Use --numstat for locale-independent parsing (sum insertions + deletions) - CHANGED=$(echo "$DIFF_OUTPUT" | awk '{ins+=$1; del+=$2} END {print ins+del+0}') - [ -z "$CHANGED" ] && CHANGED=0 + # Use --numstat for locale-independent parsing + INSERTIONS=$(echo "$DIFF_OUTPUT" | awk '{ins+=$1} END {print ins+0}') + DELETIONS=$(echo "$DIFF_OUTPUT" | awk '{del+=$2} END {print del+0}') + CHANGED=$((INSERTIONS + DELETIONS)) if [ "$CHANGED" -gt 600 ]; then # Check for override file (similar to GitHub label for exceptional cases) if [ -f "$ROOT_DIR/.preflight-allow-large-pr" ]; then echo "⚠️ Large PR override active ($CHANGED > 600 lines). Remove .preflight-allow-large-pr when done." >&2 else - echo "PR too large ($CHANGED > 600 lines). Please split into smaller slices." >&2 - echo "Tip: Lock files and license files are already excluded. See .preflight-exclude for details." >&2 - echo "For exceptional cases, create .preflight-allow-large-pr to override this check." >&2 + echo "" >&2 + echo "═══════════════════════════════════════════════════════════════" >&2 + echo "❌ PRE-PUSH CHECK FAILED: PR TOO LARGE" >&2 + echo "═══════════════════════════════════════════════════════════════" >&2 + echo "" >&2 + echo "Your changes: $CHANGED lines ($INSERTIONS insertions, $DELETIONS deletions)" >&2 + echo "Maximum allowed: 600 lines per PR" >&2 + echo "" >&2 + echo "Action required: Split changes into smaller, focused PRs" >&2 + echo "" >&2 + echo "💡 Available options:" >&2 + echo " 1. Split PR: Recommended approach" >&2 + echo " 2. Override check: touch .preflight-allow-large-pr" >&2 + echo " 3. Bypass hook: git push --no-verify (not recommended)" >&2 + echo "" >&2 + echo "Note: Lock files and license files are already excluded" >&2 + echo " See .preflight-exclude for custom exclusion patterns" >&2 + echo "" >&2 + echo "═══════════════════════════════════════════════════════════════" >&2 + echo "Push aborted. Fix the issue above and try again." >&2 + echo "═══════════════════════════════════════════════════════════════" >&2 + echo "" >&2 exit 2 fi else