diff options
author | Tobias C. Berner <tcberner@FreeBSD.org> | 2022-04-24 10:54:43 +0000 |
---|---|---|
committer | Tobias C. Berner <tcberner@FreeBSD.org> | 2022-04-25 17:34:55 +0000 |
commit | 27bebbf28a72ab5286623603611c5c0e39b6a4c8 (patch) | |
tree | d9c3e69f3e817d873fa3901bf75cbe05ce166c98 /.hooks | |
parent | 52f351a02a3b27fc65d8537202e508802d5f5ce6 (diff) | |
download | ports-27bebbf28a72ab5286623603611c5c0e39b6a4c8.tar.gz ports-27bebbf28a72ab5286623603611c5c0e39b6a4c8.zip |
framework: add hook to check indentation of conditionals of Mk/ files
This adds a further pre-commit hook to enforce indentations in Mk/*
Usage:
> vim Mk/Uses/tcl.mk
[add/remove some whitespaces between a `.` and an `if`]
> git add Mk/Uses/tcl.mk
> git commit -m "Mk/Uses/tcl.mk: test hook"
[pre-commit] tcl.mk is not properly indented -- please use /tmp/check_indentations-tcl.mk.LShfR7TD48/tcl.mk which was created using Tools/scripts/indent_make_if.pl
Reminder: to make use of the hooks provided by the ports tree use the
following from [1]
Add the prepare-commit-msg hook to the repository.
To make use of it, the easiest way is to run:
git config --add core.hooksPath .hooks
[1] bbc2474ef7a65eb8561c8ecf7af80c2bfed1f248
Reviewed by: portmgr (rene)
Differential Revision: https://reviews.freebsd.org/D35041
Diffstat (limited to '.hooks')
-rwxr-xr-x | .hooks/pre-commit.d/check_mk_indentations | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/.hooks/pre-commit.d/check_mk_indentations b/.hooks/pre-commit.d/check_mk_indentations new file mode 100755 index 000000000000..00fdb16f24cf --- /dev/null +++ b/.hooks/pre-commit.d/check_mk_indentations @@ -0,0 +1,31 @@ +#!/bin/sh +# +# Check that Mk/ files are properly indented +# + +check_indentation() { + local mkfile="$1" + local name=$(echo "${mkfile}" | awk -F / '{print $NF}') + local tempdir=$(mktemp -d -t check_indentations-${name}) + if [ $? -ne 0 ] ; then + echo "[pre-commit] failed to create tempdir" + exit 2 + fi + cp ${mkfile} ${tempdir} && Tools/scripts/indent_make_if.pl ${tempdir}/${name} + if [ $? -ne 0 ] ; then + echo "[pre-commit] failed to run Tools/scripts/indent_make_if.pl" + exit 2 + fi + cmp -s ${tempdir}/* + if [ $? -ne 0 ] ; then + echo "[pre-commit] ${name} is not properly indented -- please use ${tempdir}/${name} which was created using Tools/scripts/indent_make_if.pl" + exit 1 + fi +} + +modified_mks=$(git diff --name-only --cached --diff-filter=ACRM | grep -E '^Mk/.*\.mk$') +if [ $? -eq 0 ] ; then + for modified_mk in ${modified_mks} ; do + check_indentation "${modified_mk}" + done +fi |