Skip to content

Instantly share code, notes, and snippets.

@kont-noor
Last active August 29, 2015 14:17
Show Gist options
  • Save kont-noor/370d9b9678407d41fa51 to your computer and use it in GitHub Desktop.
Save kont-noor/370d9b9678407d41fa51 to your computer and use it in GitHub Desktop.
git pre-commit hook
#!/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
#!/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