sajad torkamani

Suppose you’re working on a Rails app and you want to run your RSpec tests before a Git commit is allowed. Here’s a possible approach.

Create executable pre-commit hook file

touch .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

Add hooks to file

exec ./bin/rubocop
exec ./bin/rspec spec/

Verify hook is running

Make a small change (e.g., add a new line to your README.md) and then commit as usual:

git commit

Your hooks (e.g., ./bin/rspec spec/) should run. If any of them returns with a non-zero status code, the commit will be rejected.

Tagged: Git

Leave a comment

Your email address will not be published. Required fields are marked *