-
-
Save davetorbeck/4d19c84b578463d229365d7999c1c576 to your computer and use it in GitHub Desktop.
Git pre-commit hook to detect some words like binding.pry, debugger...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Redirect output to stderr. | |
exec 1>&2 | |
# enable user input | |
exec < /dev/tty | |
consoleregexp='console.log|debugger|binding.pry' | |
# CHECK | |
if test $(git diff --cached | grep -E $consoleregexp | wc -l) != 0 | |
then | |
files_changed=$(git diff --cached --name-only --) | |
for file in $files_changed | |
do | |
if test $(grep -E $consoleregexp $file | wc -l) != 0 | |
then | |
echo 'File:' $file':'$(grep -E -n $consoleregexp $file | cut -f1 -d:) | |
grep -E -ne $consoleregexp $file | |
echo | |
fi | |
done | |
echo "There are some occurrences of $consoleregexp at your modification." | |
read -p "Are you sure want to continue? (y/n)" yn | |
echo $yn | grep ^[Yy]$ | |
if [ $? -eq 0 ] | |
then | |
exit 0; # Continue | |
else | |
exit 1; # Not continue | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment