1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-30 12:43:52 +00:00
CLI11/scripts/clang-format-pre-commit
Henry Fredrick Schreiner b519a13119 Updating clang format pre-commit helper example
[skip ci]
2018-04-11 13:43:55 +02:00

36 lines
775 B
Bash
Executable File

#!/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 "Formatting: $file"
clang-format -i -style=file -sort-includes "${1}"
if git diff-file --quiet -- "${1}" ; then
git add "${1}"
echo "Reformatting file: ${1}"
else
echo "Already formatted: ${1}"
fi;
;;
*)
;;
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