Last active
September 14, 2020 10:15
-
-
Save ftiasch/e8b917d0b7e081d37d5ef99dbd57a1e9 to your computer and use it in GitHub Desktop.
clang-format check git hook
This file contains hidden or 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/bash | |
tmpfile=$(mktemp) | |
for f in `git diff --cached --name-only --diff-filter=ACMR | egrep '\.(cc|cu|cuh|h)$'`; do | |
git show :"$f" > $tmpfile | |
if ! diff -q "$tmpfile" <(clang-format "$tmpfile") 2>&1 >/dev/null; then | |
echo "$f" is not clang-formatted. | |
rm -rf $tmpfile | |
exit 1 | |
fi | |
done | |
# python | |
for f in `git diff --cached --name-only --diff-filter=ACMR | egrep '\.(py)$'`; do | |
git show :"$f" > $tmpfile | |
if ! diff -q "$tmpfile" <(autopep8 "$tmpfile") 2>&1 >/dev/null; then | |
echo "$f" is not autopep8. | |
rm -rf $tmpfile | |
exit 1 | |
fi | |
done | |
rm -rf $tmpfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment