diff options
author | Tobias C. Berner <tcberner@FreeBSD.org> | 2022-04-24 10:11:13 +0000 |
---|---|---|
committer | Tobias C. Berner <tcberner@FreeBSD.org> | 2022-04-24 10:24:28 +0000 |
commit | 4e21a051bb0aa1e6ee77a30f5803d5ad6c49d578 (patch) | |
tree | 09cb05ffc36649eb4f902eb33428461857b873d4 | |
parent | aa2539679084872cd84112e9df6bfee571570623 (diff) | |
download | ports-4e21a051bb0aa1e6ee77a30f5803d5ad6c49d578.tar.gz ports-4e21a051bb0aa1e6ee77a30f5803d5ad6c49d578.zip |
framework: create a sub-directory to support multiple pre-commit hooks
-rwxr-xr-x | .hooks/pre-commit | 18 | ||||
-rwxr-xr-x | .hooks/pre-commit.d/check_category_makefile | 17 |
2 files changed, 25 insertions, 10 deletions
diff --git a/.hooks/pre-commit b/.hooks/pre-commit index fb43d4353256..886d97d7cc1b 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -1,17 +1,15 @@ #!/bin/sh # -# Check that ports are hooked into the build +# Runs every hook in pre-commit.d/ until the first failure # -newish_makefiles=$(git diff --name-only --cached --diff-filter=ACR | grep -E '^[^/]+/[^/]+/Makefile$') -if [ $? -eq 0 ] ; then - for newish_makefile in ${newish_makefiles} ; do - category=$(echo "${newish_makefile}" | awk -F '/' '{print $1}') - port=$(echo "${newish_makefile}" | awk -F '/' '{print $2}') - grep -q -E "^[[:space:]]+SUBDIR[[:space:]]\+=[[:space:]]*${port}\$" ${category}/Makefile +hook_directory=$(realpath $(dirname $0)) + +for hook in ${hook_directory}/pre-commit.d/* ; do + if [ -x "${hook}" ] ; then + ${hook} if [ $? -ne 0 ] ; then - echo "[pre-commit] ERROR: Missing 'SUBDIR += ${port}' in ${category}/Makefile" exit 1 fi - done -fi + fi +done diff --git a/.hooks/pre-commit.d/check_category_makefile b/.hooks/pre-commit.d/check_category_makefile new file mode 100755 index 000000000000..fb43d4353256 --- /dev/null +++ b/.hooks/pre-commit.d/check_category_makefile @@ -0,0 +1,17 @@ +#!/bin/sh +# +# Check that ports are hooked into the build +# + +newish_makefiles=$(git diff --name-only --cached --diff-filter=ACR | grep -E '^[^/]+/[^/]+/Makefile$') +if [ $? -eq 0 ] ; then + for newish_makefile in ${newish_makefiles} ; do + category=$(echo "${newish_makefile}" | awk -F '/' '{print $1}') + port=$(echo "${newish_makefile}" | awk -F '/' '{print $2}') + grep -q -E "^[[:space:]]+SUBDIR[[:space:]]\+=[[:space:]]*${port}\$" ${category}/Makefile + if [ $? -ne 0 ] ; then + echo "[pre-commit] ERROR: Missing 'SUBDIR += ${port}' in ${category}/Makefile" + exit 1 + fi + done +fi |