Create a gist now

Instantly share code, notes, and snippets.

@edasque /pre-commit
Last active Feb 19, 2016

What would you like to do?
pre-commit Git hook to JSONlint - place it in .git/hooks
git diff-index -z --cached HEAD --name-only --diff-filter=ACMRTUXB |
xargs -0 -t -L1 /usr/local/bin/jsonlint -c;
if [ "$?" != "0" ]; then
echo "\nOne or more JSON file didn't pass jsonlint'ing.";
echo "Fix them before committing. If it is not possible to fix them all commit with the option --no-verify.";
exit 1;
edasque commented Feb 19, 2016

This works on a mac. xargs is a little bit different on linux where it probably should be changed to xargs --null --no-run-if-empty /usr/local/bin/jsonlint -c;.
This assumes jsonlint 1.6.x is installed in /usr/local/bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment