mirror of
https://git.freebsd.org/ports.git
synced 2025-04-28 09:36:41 -04:00
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] bbc2474ef7
Reviewed by: portmgr (rene)
Differential Revision: https://reviews.freebsd.org/D35041
This commit is contained in:
parent
52f351a02a
commit
27bebbf28a
1 changed files with 31 additions and 0 deletions
31
.hooks/pre-commit.d/check_mk_indentations
Executable file
31
.hooks/pre-commit.d/check_mk_indentations
Executable file
|
@ -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
|
Loading…
Add table
Reference in a new issue