Last active
August 29, 2015 14:17
-
-
Save kont-noor/370d9b9678407d41fa51 to your computer and use it in GitHub Desktop.
git pre-commit hook
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 | |
#.git/hooks/pre-commit | |
patterns=("TODO" "binding.pry" "selenium") | |
status=0 | |
for pattern in ${patterns[*]} | |
do | |
matches=`git-diff-index -p -M --cached HEAD -- | grep '^+' | grep -i "$pattern"` | |
matches_count=`git-diff-index -p -M --cached HEAD -- | grep '^+' | grep -i "$pattern" | wc -l` | |
if [ "$matches_count" -gt 0 ]; then | |
echo "Blocking commit because string $pattern detected in patch" | |
echo $matches | |
echo "Total matches found: $matches_count" | |
status=1 | |
fi | |
done | |
exit $status |
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 | |
#.git/hooks/pre-push | |
branch=`git branch | grep '^*'` | |
correct_branch=`git branch | grep '^* \d' | wc -l` | |
if [ "$correct_branch" -eq 0 ]; then | |
echo "Blocking push because branch name doesn't start from number" | |
echo "Branch name is $branch" | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment