From 58f63c9a0246a5b1bc96906bac5d06c75237c2ca Mon Sep 17 00:00:00 2001
From: Adrian Lehmann <info@adrianlehmann.net>
Date: Tue, 6 Feb 2024 10:55:26 -0600
Subject: [PATCH] Fix hooks stashing issue

---
 .hooks/pre-commit | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/.hooks/pre-commit b/.hooks/pre-commit
index 7c7e212..d9d3661 100755
--- a/.hooks/pre-commit
+++ b/.hooks/pre-commit
@@ -4,9 +4,18 @@ BASEDIR=$(dirname "$0")
 
 # Stash changes that are not staged to check if the commited state if valid
 # Make sure to pop later!
-git stash --keep-index -u > /dev/null 2>/dev/null
+git stash --keep-index -u 2>/dev/null
 
-"$BASEDIR/Z_X_rules_validator.py" || (echo "Error - disallowing commit: Z_X validator failed"; git stash pop > /dev/null 2>/dev/null; exit 1)
-"$BASEDIR/Search_validator.py" || (echo "Error - disallowing commit: Search validator failed"; git stash pop > /dev/null 2>/dev/null; exit 1)
-"$BASEDIR/Name_validator.py" || (echo "Error - disallowing commit: Naming validator failed"; git stash pop > /dev/null 2>/dev/null; exit 1)
-git stash pop > /dev/null 2>/dev/null || exit 0
\ No newline at end of file
+unstash() {
+  git stash pop > /dev/null 2>/dev/null
+  exit $1
+}
+
+
+"$BASEDIR/Z_X_rules_validator.py" || { echo "Error - disallowing commit: Z_X validator failed"; unstash 1; }
+
+"$BASEDIR/Search_validator.py" || { echo "Error - disallowing commit: Search validator failed"; unstash 1; }
+
+"$BASEDIR/Name_validator.py" || { echo "Error - disallowing commit: Naming validator failed"; unstash 1; }
+
+unstash 0