Skip to content

Instantly share code, notes, and snippets.

@mehulkar
Last active August 29, 2015 14:08
Show Gist options
  • Save mehulkar/6964b68b3e2302e81f9b to your computer and use it in GitHub Desktop.
Save mehulkar/6964b68b3e2302e81f9b to your computer and use it in GitHub Desktop.
git precommit hook for rspec
#!/usr/bin/env bash
# Add this file to .git/hooks/pre-commit
# and make it executable.
# 1. greps the repo for "focus: true"
# 2. counts number of results
# 3. Strips the whitespace from the resulting number string
num=$(git grep "focus: true" | wc -l | xargs)
# 4. assumes that spec_helper has the string for
# turning on that configuration, so the hook will abort
# commit only if there are more than 1 mentions of "focus: true"
if [[ "$num" -gt 1 ]]; then
echo "git commit error: Remove all 'focus: true' directives from spec suite"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment