coding style: experimental use of a clang-format git pre-commit hook to use code convention

parent f1ec8325
/Users/gpelloux/Dropbox/belledonne/clang-format
\ No newline at end of file
#!/bin/bash
# This hook purpose is to keep coding style consistent between all developers
# It is automatically installed in .git/hooks folder by cmake on first run.
# From https://github.com/tatsuhiro-t/nghttp2/blob/master/pre-commit
# Maybe this is a totally wrong way of detecting clang-format-diff availability..
clang_format_diff=$(find /usr/bin/ -name 'clang-format-diff*' -type f | head -n1)
clang_format_diff_options="-style=file"
if [ -z "$clang_format_diff" ]; then
echo "$0: Please install clang-format-diff (coding style checker)."
exit 1
fi
errors=$(git diff-index --cached --diff-filter=ACMR -p HEAD -- | $clang_format_diff $clang_format_diff_options -p1)
if [ -n "$errors" ]; then
tmpfile=$(mktemp)
echo "$errors" > $tmpfile
echo "$errors"
echo
echo "*****************"
echo "$0: Invalid coding style detected. Please correct it using one of the following:"
echo "1) Apply patch located at $tmpfile using:"
echo " cd $(git rev-parse --show-toplevel) && patch -p0 < $tmpfile"
echo "2) Use clang-format to format lines using:"
echo " ${clang_format_diff/-diff/} $clang_format_diff_options -i <some_file.cpp>)"
echo "3) Reformat these lines manually."
echo "*** Aborting commit.***"
exit 1
fi
......@@ -37,13 +37,18 @@ if test -d /share/aclocal ; then
ACLOCAL_ARGS="$ACLOCAL_ARGS -I /share/aclocal"
fi
set -x
rm -rf config.cache autom4te.cache
$libtoolize --copy --force
$ACLOCAL -I m4 $ACLOCAL_ARGS
autoheader
$AUTOMAKE --force-missing --add-missing --copy
$AUTOMAKE --force-missing --add-missing --copy
autoconf
#install git pre-commit hooks if possible
if [ -d .git/hooks ] && [ ! -f .git/hooks/pre-commit ]; then
cp .git-pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
fi
cd $THEDIR
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment