-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
#!/bin/bash | ||
|
||
# derived from here | ||
# https://github.com/andrewseidl/githook-clang-format/blob/master/clang-format.hook | ||
# Uses the _clang-format file for rules | ||
# Uses the _clang-format_ignore file to skip dirs | ||
# Check if there are any staged changes | ||
if ! git diff --cached --name-only | grep -q '\.cpp\|\.c\|\.h\|\.hpp'; then | ||
exit 0 | ||
fi | ||
|
||
format_file() { | ||
file="${1}" | ||
# Run clang-format on staged changes | ||
git clang-format --style=file | ||
|
||
if [ -f $file ]; then | ||
clang-format -style=file -i ${file} | ||
git add ${file} | ||
fi | ||
} | ||
|
||
for file in `git diff-index --cached --name-only HEAD | grep -iE '\*.(cpp|h|m|mm)$' ` ; do | ||
format_file "${file}" | ||
done | ||
# Check if clang-format made any changes | ||
if ! git diff --cached --name-only | grep -q '\.cpp\|\.c\|\.h\|\.hpp'; then | ||
echo "No changes made by clang-format." | ||
exit 0 | ||
fi | ||
|
||
# Add the formatted changes | ||
echo "Code formatted with clang-format." | ||
git add . |