Created
June 22, 2016 18:53
-
-
Save aelindeman/afa0ab33082fd3fd38a5a4677c08d651 to your computer and use it in GitHub Desktop.
lint files before allowing git push recieve
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 | |
oldrev=$1 | |
newrev=$2 | |
refname=$3 | |
while read oldrev newrev refname; do | |
files=`git diff --name-only ${oldrev} ${newrev}` | |
objects=`git ls-tree --full-name -r ${newrev}` | |
for file in ${files}; do | |
object=`echo -e "${objects}" | egrep "\s+${file}\$" | awk '{ print $3 }'` | |
if [ -z ${object} ]; then | |
continue | |
fi | |
lint=0 | |
case "${file}" in | |
*.php) | |
lint=`git cat-file blob ${object} | php -l -- > /dev/null; echo -n $?` | |
;; | |
*.json) | |
lint=`git cat-file blob ${object} | python -m simplejson.tool > /dev/null; echo -n $?` | |
;; | |
*) | |
continue | |
;; | |
esac | |
if [ ${lint} ]; then | |
echo -e "\033[0;93mlint failed for ${file}\033[0m" | |
exit 1 | |
else | |
echo "\033[0;37mlint passed for ${file}\033[0m" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment