Skip to content

Instantly share code, notes, and snippets.

@bbrothers
Last active October 29, 2015 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbrothers/127c5454d9138dc9a930 to your computer and use it in GitHub Desktop.
Save bbrothers/127c5454d9138dc9a930 to your computer and use it in GitHub Desktop.
#!/bin/bash
git diff --cached --name-only | while read FILE; do
if [[ "$FILE" =~ ^.+(php|inc|module|install|test)$ ]]; then
# Courtesy of swytsh from the comments below.
if [[ -f $FILE ]]; then
php -l "$FILE" 1> /dev/null
if [ $? -ne 0 ]; then
echo -e "\e[1;31m\tAborting commit due to files with syntax errors" >&2
exit 1
fi
fi
fi
done || exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment