Last active
April 20, 2021 23:46
-
-
Save Lauszus/31a3a43e35fabbf69ee58f9f425e69a2 to your computer and use it in GitHub Desktop.
clang-format pre-commit hook
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/sh | |
# Check if this is the initial commit | |
if git rev-parse --verify HEAD >/dev/null 2>&1; then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
# Check if it parses the clang-format style | |
git diff --staged --submodule=diff -U0 --no-color $against | clang-format-diff -p1 > .clang-format.diff | |
if [ -s .clang-format.diff ]; then | |
echo "clang-format style violation:\n" | |
cat .clang-format.diff | |
exit_code=1 | |
else | |
exit_code=0 | |
fi | |
rm .clang-format.diff | |
exit $exit_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment