Skip to content

Instantly share code, notes, and snippets.

@svschannak
Forked from guilherme/gist:9604324
Last active June 26, 2019 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save svschannak/8d1a445a751d5ae8e18ef9b98a45be9f to your computer and use it in GitHub Desktop.
Save svschannak/8d1a445a751d5ae8e18ef9b98a45be9f to your computer and use it in GitHub Desktop.
Git pre-commit hook that detects if the developer forget to remove all the javascript console.log before commit.
#!/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
@svschannak
Copy link
Author

svschannak commented Sep 27, 2017

Insert this into your local git repo at .git/hooks/pre-commit and execute the following code, if needed:
chmod +x .git/hooks/pre-commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment