Created
July 24, 2018 15:15
-
-
Save niklas-ourmachinery/072792a5bcb553a55ae5cd324c805f17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This file should be installed in .git/hooks/pre-commit | |
EXITCODE=0 | |
format_file() { | |
clang-format -style=file ${1} | diff ${1} - > /dev/null | |
if [ $? -ne 0 ] | |
then | |
echo "clang-format mismatch in ${1}" | |
clang-format -i -style=file ${1} | |
EXITCODE=1 | |
fi | |
} | |
case "${1}" in | |
--about ) | |
echo "Runs clang-format on source files" | |
;; | |
* ) | |
for file in `git diff-index --cached --diff-filter=ACMRTUXB --name-only HEAD | egrep "(\.c$|\.h$|\.cpp$|\.inl$|\.m$|\.mm$)"` ; do | |
format_file "${file}" | |
done | |
;; | |
esac | |
exit $EXITCODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment