Forked from svschannak/gist:8d1a445a751d5ae8e18ef9b98a45be9f
Last active
June 26, 2019 08:55
Star
You must be signed in to star a gist
Git pre-commit hook that detects if the developer forget to remove all the javascript console.log before commit.
This file contains 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(' | |
# CHECK | |
if test $(git diff --cached | grep $consoleregexp | wc -l) != 0 | |
then | |
exec git diff --cached | grep -ne $consoleregexp | |
read -p "There are some occurrences of console.log at your modification. Are you sure want to continue? (y/n)" yn | |
echo $yn | grep ^[Yy]$ | |
if [ $? -eq 0 ] | |
then | |
exit 0; #THE USER WANTS TO CONTINUE | |
else | |
exit 1; # THE USER DONT WANT TO CONTINUE SO ROLLBACK | |
fi | |
fi |
This file contains 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
curl https://gist.githubusercontent.com/richarddewit/650b35fd1c22995d69e2a1bfe22b876f/raw/a1b555e2a1679cf684963d90e465802d6d0da851/_pre-commit-check-console-log.sh > .git/hooks/pre-commit | |
chmod +x .git/hooks/pre-commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment