Skip to content

Instantly share code, notes, and snippets.

@ftiasch
Last active September 14, 2020 10:15
Show Gist options
  • Save ftiasch/e8b917d0b7e081d37d5ef99dbd57a1e9 to your computer and use it in GitHub Desktop.
Save ftiasch/e8b917d0b7e081d37d5ef99dbd57a1e9 to your computer and use it in GitHub Desktop.
clang-format check git hook
#!/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