Skip to content

Commit

Permalink
Merge pull request #44 from inQWIRE/fix/pre-commit-stash-issue
Browse files Browse the repository at this point in the history
Fix usability issues with hooks
  • Loading branch information
caldwellb committed Feb 7, 2024
2 parents 1672944 + b2a3603 commit 772846c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
9 changes: 8 additions & 1 deletion .hooks/Name_validator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/usr/bin/env python3

import re
import os
import sys
import sys


MIN_PYTHON = (3, 10)
if sys.version_info < MIN_PYTHON:
print(f"Your python version is {sys.version_info.major}.{sys.version_info.minor}. {MIN_PYTHON[0]}.{MIN_PYTHON[1]} is required")
exit(3)


args = sys.argv[1:]

Expand Down
7 changes: 7 additions & 0 deletions .hooks/Nocheck_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
import os
import sys


MIN_PYTHON = (3, 10)
if sys.version_info < MIN_PYTHON:
print(f"Your python version is {sys.version_info.major}.{sys.version_info.minor}. {MIN_PYTHON[0]}.{MIN_PYTHON[1]} is required")
exit(3)


b_color_yellow = '\033[93m'
b_color_reset = '\033[0m'

Expand Down
5 changes: 5 additions & 0 deletions .hooks/Search_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import os
import sys

MIN_PYTHON = (3, 10)
if sys.version_info < MIN_PYTHON:
print(f"Your python version is {sys.version_info.major}.{sys.version_info.minor}. {MIN_PYTHON[0]}.{MIN_PYTHON[1]} is required")
exit(3)

args = sys.argv[1:]

usage = "./Name_validator.py [--interactive]"
Expand Down
8 changes: 8 additions & 0 deletions .hooks/Z_X_rules_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

import re
import os
import sys


MIN_PYTHON = (3, 10)
if sys.version_info < MIN_PYTHON:
print(f"Your python version is {sys.version_info.major}.{sys.version_info.minor}. {MIN_PYTHON[0]}.{MIN_PYTHON[1]} is required")
exit(3)


b_color_yellow = '\033[93m'
b_color_reset = '\033[0m'
Expand Down
19 changes: 14 additions & 5 deletions .hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit 772846c

Please sign in to comment.