Created
July 12, 2017 09:50
-
-
Save Lycisca/ae510f97d496acefd58d93fe8cf337ce 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
Instructions
Download the file to git hooks folder and set execution permission.
When you try to commit a file with any word that match the regexp
consoleregexp
this program warning you and ask for continue or abort the commit.Example