Skip to content

Instantly share code, notes, and snippets.

@logicminds
Created June 3, 2013 18:01
Show Gist options
  • Save logicminds/5700014 to your computer and use it in GitHub Desktop.
Save logicminds/5700014 to your computer and use it in GitHub Desktop.
This is my git pre commit hook that would work for linux and windows systems
#!/bin/bash
against=$1
FILES=`git diff --cached --name-only --diff-filter=ACM`
# validate json files
for file in $FILES
do
# validate json files
if [[ $file == *.json ]]; then
echo "Validating json file: $file"
python -m json.tool $file > /dev/null
# validate puppet manifests
elif [[ $file == *.pp ]]; then
echo "Validating puppet file: $file"
puppet parser validate $file
fi
# if any validation failed display error
if [[ $? != 0 ]]; then
exit 1
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment