Skip to content

Commit

Permalink
Adding git hook example script for clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Apr 9, 2018
1 parent 801e0ad commit 571cae9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions scripts/clang-format-pre-commit
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 571cae9

Please sign in to comment.