Skip to content

Instantly share code, notes, and snippets.

@rhodee
Last active August 29, 2015 13:57
Show Gist options
  • Save rhodee/9520692 to your computer and use it in GitHub Desktop.
Save rhodee/9520692 to your computer and use it in GitHub Desktop.
Ideas for a pre-commit hook. Welcome.
#!/usr/bin/env ruby
# Drop in .git/hooks
# Make executable and get back to werk.
# Stash files not to be committed
system('git stash -q --keep-index')
# check for rake
rake_available = system('bundle list | grep rake > /dev/null')
minitest_available = system('bundle list | grep minitest > /dev/null')
rspec_available = system('bundle list | grep rspec > /dev/null')
if rake_available && minitest_available
# Run test
puts 'Running Tests...'
system('bundle exec rake test')
end
if rspec_available
# Run test
puts 'Running Tests...'
system('bundle exec rspec spec')
end
# Unstash changes to the working tree that we had stashed
system('git stash pop -q')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment