From 832124bc5b33996e585480933e57d93b0bd8dbe3 Mon Sep 17 00:00:00 2001
From: Lex Neva <lexelby@users.noreply.github.com>
Date: Sat, 14 Sep 2024 18:56:00 -0400
Subject: [PATCH] only style-check staged changes (#3186)

---
 bin/git-pre-commit-hook | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/bin/git-pre-commit-hook b/bin/git-pre-commit-hook
index 81ace2cd2..4d81c5a71 100755
--- a/bin/git-pre-commit-hook
+++ b/bin/git-pre-commit-hook
@@ -7,11 +7,18 @@
 # DO NOT SYMLINK
 # DO NOT SYMLINK (why? security risk)
 
+check_errors() {
+    errors="$("$@")"
+
+    if [ "$?" != "0" ]; then
+        echo "$errors"
+        exit 1
+    fi
+}
+
 cd $(dirname "$0")/../..
 
-errors=$(git diff --cached | bin/style-check --diff 2>&1)
+check_errors git stash --keep-index
+check_errors git diff --cached | bin/style-check 2>&1
+check_errors git stash pop
 
-if [ "$?" != "0" ]; then
-    echo "$errors"
-    exit 1
-fi