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/sh | |
# | |
# 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. | |
set -e | |
git diff --cached | while IFS= read -r line | |
do | |
read -r -a WORDS <<< "$line" | |
diff=${line:0:1} | |
case ${WORDS[0]} in | |
diff) | |
file=${WORDS[2]:2} | |
;; | |
new | index | deleted | similarity | rename | --- | +++) | |
;; | |
@@) | |
state=0 | |
;; | |
*) | |
case ${diff} in | |
-) | |
case ${state} in | |
0 | 1) | |
state=1 | |
;; | |
2) | |
state=4 | |
;; | |
*) | |
echo >& too many changes in ${file} | |
exit 1 | |
;; | |
esac | |
;; | |
+) | |
case ${state} in | |
0 | 2) | |
state=2 | |
;; | |
1 | 3) | |
state=3 | |
;; | |
*) | |
echo >&2 too many changes in ${file} | |
exit 1 | |
;; | |
esac | |
;; | |
' ') | |
# unchanged line | |
state=0 | |
;; | |
*) | |
echo >&2 "parse error on '${line}' in ${file}" | |
exit 2 | |
;; | |
esac | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment