1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-03 05:53:52 +00:00

Adding git hook example script for clang format

This commit is contained in:
Henry Fredrick Schreiner 2018-04-09 13:19:57 +02:00 committed by Henry Schreiner
parent 8f1215873c
commit 909d72bfec

30
scripts/clang-format-pre-commit Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# To use:
# ln -s scripts/clang-format.hook .git/hooks/pre-commit
# Based loosely on https://github.com/andrewseidl/githook-clang-format
format_file() {
file="${1}"
case "$file" in
*.hpp | *.cpp | .c | *.cc | *.cu | *.h )
echo "Fixing: $file"
clang-format -i -style=file "${1}"
git add "${1}"
;;
*)
;;
esac
}
case "${1}" in
--about )
echo "Runs clang-format on source files"
;;
* )
for file in `git diff-index --cached --name-only HEAD` ; do
format_file "${file}"
done
;;
esac