1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#!/bin/sh
# clang-format pre-commit hook
#
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions.
#
# This script does not handle file names that contain spaces.
cfiles=$(git diff --name-only HEAD --diff-filter=d | grep '\.\(cc\|hh\|c\|h\)$')
numerrors=0
for f in $cfiles; do
diffoutput=$(clang-format $f | diff $f -)
if [ -n "$diffoutput" ]; then
[ $numerrors -eq 0 ] && echo >&2 "Unformatted files:";
echo >&2 "$f";
((numerrors++))
fi
done
exit $numerrors
|