Skip to content

Instantly share code, notes, and snippets.

@valerykalashnikov
Last active October 4, 2018 08:13
Show Gist options
  • Save valerykalashnikov/6522704 to your computer and use it in GitHub Desktop.
Save valerykalashnikov/6522704 to your computer and use it in GitHub Desktop.
Precommit hook to prevent console.log, debugger and binding.pry
#!/bin/bash
#Precommit hook to prevent "debugger" and "console.log"
#Note: to enamble precommit on Windows machine don't forget add path to Git\bin and Git\cmd to PATH environment variable
count=0
for FILE in `git diff-index --name-status HEAD -- | cut -c3-` ; do
# Check if the file contains 'debugger' or 'console.log'
contains=`grep -e "debugger" -e "console\.log" -e "binding\.pry" $FILE`
if [ `grep -e "debugger" -e "console\.log" -e "binding\.pry" $FILE|wc -l` -ne 0 ]
then
echo -e $FILE " contains " $contains
count=$[$count+1]
fi
done
if [ $count -eq 0 ]
then exit
else exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment