Created
March 6, 2013 16:57
-
-
Save jeekl/5100895 to your computer and use it in GitHub Desktop.
update.jsonlint.sh: git update hook for checking syntax of json objects.
update.ruby-syntax.sh: git update hook for checking ruby syntax.
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
#!/usr/bin/env bash | |
# Runs all .json or .js files through pythons json lint tool before updating, | |
# to make sure that you don't push broken json objects. | |
refname=$1 | |
old=$2 | |
new=$3 | |
for file in $(git ls-tree --name-only -r $new \ | |
| grep -P '\.((js)|(json))$'); do | |
git cat-file blob $new:$file | python -mjson.tool &> /dev/null | |
if [ $? -ne 0 ] ; then | |
echo -e "\e[31mLint check of JSON object failed. Your push was not accepted.\e[0m" | |
echo -e "\e[31min $file:\e[0m" | |
output=$(git cat-file blob $new:$file | python -mjson.tool 2>&1) | |
echo -e "\e[31m $output \e[0m" | |
exit 1 | |
fi | |
done |
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
#!/usr/bin/env bash | |
# Runs all .rb files through ruby -c for simple syntax checking | |
refname=$1 | |
old=$2 | |
new=$3 | |
for file in $(git ls-tree --name-only -r $new | grep -P '\.(rb)$') ; do | |
git cat-file blob $new:$file | ruby -c &>/dev/null | |
if [ $? -ne 0 ] ; then | |
echo -e "\e[31mRuby syntax check of failed. Your push was not accepted.\e[0m" | |
echo -e "\e[31min $file, on line : \e[0m" | |
git cat-file blob $new:$file | ruby -c 1>/dev/null | |
exit 1 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment