You've already forked opencryptoki
mirror of
https://github.com/opencryptoki/opencryptoki.git
synced 2026-10-24 05:39:17 +03:00
The pre-commit hook will help developers have their code changes checked for indentation problems. Documentation mentions how the hook can be set up. Signed-off-by: Eduardo Barretto <ebarretto@linux.vnet.ibm.com>
59 lines
1.7 KiB
Bash
59 lines
1.7 KiB
Bash
#!/bin/sh
|
|
#
|
|
# Check that the code follows the coding style
|
|
#
|
|
# If the code does not follow the coding style a warning will be printed.
|
|
#
|
|
|
|
version=`gnuindent --version 2> /dev/null`
|
|
if [ "x$version" = "x" ]; then
|
|
version=`indent --version 2> /dev/null`
|
|
if [ "x$version" = "x" ] || [[ "$version" != *GNU* ]]; then
|
|
echo "Git pre-commit hook:"
|
|
echo "Did not find GNU indent, please install it before continuing."
|
|
exit 1
|
|
fi
|
|
INDENT=indent
|
|
else
|
|
INDENT=gnuindent
|
|
fi
|
|
|
|
echo "*******************"
|
|
|
|
for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR`; do
|
|
ext=$(expr "$file" : ".*\(\..*\)")
|
|
case $ext in
|
|
.c|.h)
|
|
echo "Checking code style"
|
|
# ckfile is the temporary checkout and we indent it
|
|
ckfile=`git checkout-index --temp ${file} | cut -f 1`
|
|
newfile=`mktemp /tmp/${ckfile}.XXXXXX` || exit 1
|
|
$INDENT $ckfile -o $newfile 2>> /dev/null
|
|
$INDENT $newfile 2>> /dev/null
|
|
diff -u -p "${ckfile}" "${newfile}"
|
|
r=$?
|
|
rm "${ckfile}"
|
|
rm "${newfile}"
|
|
rm "${newfile}~"
|
|
if [ $r != 0 ]; then
|
|
echo "Warning: Code style error in $file"
|
|
read -n1 -p "Do you want to CONTINUE committing? [Y/n]" opt < /dev/tty
|
|
case $opt in
|
|
n|N)
|
|
echo
|
|
exit 1
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
echo "*******************"
|
|
fi
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Not checking code style for this type of file"
|
|
echo "*******************"
|
|
;;
|
|
esac
|
|
done
|