Last active
February 21, 2016 14:14
-
-
Save bitIO/fb0bcef37014083826ca to your computer and use it in GitHub Desktop.
Git local hooks
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/bash | |
# Don't allow console.log() statements to be committed. | |
# Add to .git/hooks/pre-commit | |
YELLOW='\033[1;33m' | |
RED='\033[0;31m' | |
RESET='\033[0m' | |
# Don't allow console.log() statements to be committed. | |
count=`git diff --staged -z HEAD | grep console\.log | grep ^+ | wc -l` | |
if [ "$count" -ge 1 ] | |
then | |
echo -e "${RED}Your commit contains console.log statements${YELLOW}" | |
git diff -z HEAD | grep console\.log | grep ^+ | |
echo -e "${RESET}\n" | |
read -p "Do you want to commit them anyway? [y|n] " -n 1 -r < /dev/tty | |
echo | |
if echo $REPLY | grep -E '^[Yy]$' > /dev/null | |
then | |
exit 0 # commit will execute | |
fi | |
exit 1 # commit will not execute | |
fi |
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/bash | |
protected_branch='master' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
echo "protected_branch is $protected_branch" | |
echo "current_branch is $current_branch" | |
if [ $protected_branch == $current_branch ] | |
then | |
read -p "You're about to push master, is that what you intended? [y|n] " -n 1 -r < /dev/tty | |
echo | |
if echo $REPLY | grep -E '^[Yy]$' > /dev/null | |
then | |
exit 0 # push will execute | |
fi | |
exit 1 # push will not execute | |
else | |
echo "push can happen" | |
exit 0 # push will execute | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment