Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
Forked from guilherme/gist:9604324
Last active August 29, 2015 14:12
Show Gist options
  • Save cansadadeserfeliz/3c87d8d04345d413a02f to your computer and use it in GitHub Desktop.
Save cansadadeserfeliz/3c87d8d04345d413a02f to your computer and use it in GitHub Desktop.
pre-commit hook for git
#!/bin/bash
# Redirect output to stderr.
exec 1>&2
# enable user input
exec < /dev/tty
consoleregexp='console.log'
printregexp='print '
# CHECK
if [[ $(git diff --cached | grep $consoleregexp | wc -l) != 0 ]] || [[ $(git diff --cached | grep $printregexp | wc -l) != 0 ]]
then
exec git diff --cached | grep -ne $consoleregexp
read -p "There are some occurrences of console.log or print 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment