Created
November 28, 2016 17:10
-
-
Save karadza3a/b2347a20da2041fadf11d56b0b29cf9e to your computer and use it in GitHub Desktop.
Add this to .git/hooks/pre-commit and make sure it's executable.
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/bash | |
# brew install clang-format | |
STYLE=$(git config --get hooks.clangformat.style) | |
if [ -n "${STYLE}" ] ; then | |
STYLEARG="-style=${STYLE}" | |
else | |
STYLEARG="-style=file" | |
fi | |
format_file() { | |
file="${1}" | |
if [[ $file =~ .*\.[mh]$ ]];then | |
clang-format -i ${STYLEARG} $file | |
git add ${1} | |
fi | |
} | |
case "${1}" in | |
--about ) | |
echo "Runs clang-format on source files" | |
;; | |
* ) | |
for file in `git diff-index --cached --name-only HEAD` ; do | |
format_file "${file}" | |
done | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment