Add pre-commit script

This commit is contained in:
Tatsuhiro Tsujikawa 2014-11-26 23:51:07 +09:00
parent 7c794b8d93
commit 87ce5068bb
1 changed files with 27 additions and 0 deletions

27
pre-commit Executable file
View File

@ -0,0 +1,27 @@
#!/bin/sh -e
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
CLANGFORMATDIFF=`git config --get clangformatdiff.binary`
if [ -z "$CLANGFORMATDIFF" ]; then
CLANGFORMATDIFF=clang-format-diff.py
fi
errors=`git diff-index --cached --diff-filter=ACMR -p HEAD -- | $CLANGFORMATDIFF -p1`
if [ -n "$errors" ]; then
echo "$errors"
echo "--"
echo "[ERROR] We have detected the difference between the code to commit"
echo "and clang-format style rules. Please fix this problem in either:"
echo "1) Apply patch above."
echo "2) Use clang-format to format lines."
echo "3) Reformat these lines manually."
echo "Aborting commit."
exit 1
fi