Created
May 21, 2019 05:39
-
-
Save acoomans/5a6d6c31dcd47a93560388586e99f003 to your computer and use it in GitHub Desktop.
Git pre-commit 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/sh -x | |
# Run git config --global core.hooksPath /path/to/hooks | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
against=$(git hash-object -t tree /dev/null) | |
fi | |
changed_files=$(git diff-index --cached $against | \ | |
grep -E '[MA] .*\.(c|cpp)$' | cut -f 2) | |
if [ -n "$changed_files" ]; then | |
clang-format -i -style=LLVM $changed_files | |
exit $? | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment