Pre-commit git hook to check for console.log's and php syntax errors.
#!/bin/sh exec 1>&2 exec < /dev/tty git diff --cached --name-only | while read FILE; do if [[ "$FILE" =~ ^.+(php|inc|module|install|test)$ ]]; then 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.\e[0m" >&2 exit 1 fi fi fi done || exit $? # If there's a PHP error let's hard exit # Don't even bother checking for js files because # We're not committing broken PHP with no exceptions if [ $? -eq 0 ]; then consoleregexp='^\+.*console\.log(' if test $(git diff --cached | grep $consoleregexp | wc -l) != 0 then exec git diff --cached | grep -ne $consoleregexp read -p "There are some instances of console.log in your changes. Are you sure want to continue? (y/n)" yn echo $yn | grep ^[Yy]$ if [ $? -eq 0 ] then exit 0; else exit 1; fi fi fi # You can choose 'y' if you're aware of the console.log and want it committed for some reason