From 87f907d948bab9b333193d4737e61b3db37878c0 Mon Sep 17 00:00:00 2001 From: DarkFeather Date: Wed, 26 Oct 2022 19:38:18 -0500 Subject: [PATCH] Updating & documenting hooks --- Hooks/scripts.d/local-hooks | 8 ++++++++ Hooks/scripts.d/pytest | 4 +++- Hooks/scripts.d/whitespace | 12 +++++++----- README.md | 6 ++++++ 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100755 Hooks/scripts.d/local-hooks diff --git a/Hooks/scripts.d/local-hooks b/Hooks/scripts.d/local-hooks new file mode 100755 index 0000000..4a94399 --- /dev/null +++ b/Hooks/scripts.d/local-hooks @@ -0,0 +1,8 @@ +# This script ensures that repos can commit personal hooks in the ./precommit-hooks folder. + +for script in `find precommit-hooks -type f`; do + if ! bash "$script"; then + echo "Local script $script failed checks." + exit 1 + fi +done diff --git a/Hooks/scripts.d/pytest b/Hooks/scripts.d/pytest index 43acb14..c72fb16 100755 --- a/Hooks/scripts.d/pytest +++ b/Hooks/scripts.d/pytest @@ -8,4 +8,6 @@ elif [ -f requirements.txt ]; then python3 -m venv venv venv/bin/python3 -m pip install -r requirements.txt fi -python3 -m pytest +if [ -d tests/ ]; then + python3 -m pytest +fi diff --git a/Hooks/scripts.d/whitespace b/Hooks/scripts.d/whitespace index 4d34854..b9a4927 100755 --- a/Hooks/scripts.d/whitespace +++ b/Hooks/scripts.d/whitespace @@ -2,6 +2,11 @@ # Sourced from https://github.com/git/git/blob/master/templates/hooks--pre-commit.sample +if git ls-files | xargs egrep -irl '\s\+$' ; then + echo The above lines have trailing whitespace. Run "sed -i 's/\s\+$//'" on the affected files. + exit 1 +fi + if git rev-parse --verify HEAD >/dev/null 2>&1 then against=HEAD @@ -13,9 +18,6 @@ fi # Redirect output to stderr. exec 1>&2 + # If there are whitespace errors, print the offending file names and fail. -git diff-index --check --cached $against -- -if [ $? -ne 0 ]; then - echo The above lines have trailing whitespace. Run "sed -i 's/\s\+$//'" on the affected files. - exit 1 -fi +exec git diff-index --check --cached $against -- diff --git a/README.md b/README.md index 76d90ca..1c0ebab 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,9 @@ The following executables are available: * `uniglot-clone` ensures that when repos are cloned, they are attached to the standard Uniglot hooks. * `home-git` is support for [User Support Repositories](https://aninix.net/AniNIX/Wiki/src/branch/main/Articles/User_Support_Repositories.md). + +# Hooks + +The Hooks folder includes a standard pre-commit and pre-receive that will be enforced across repos. These pre-commit and pre-receive will enforce the contents of `Hooks/scripts.d`. This allows us to enforce standards of quality across the ecosystem. + +Notably, each repo that subscribes to this enforcement can also commit their own standards in addition to global standards. Python tests should go in a folder called `tests/` and scripts in a folder called `precommit-hooks/`. These will be run in addition to the global hooks.