Place pre-commit.sh
into your project's root directory, then before making changes to your repository, copy pre-commit.sh
to the repo .git/hooks
folder using:
ln -s ../../pre-commit.sh .git/hooks/pre-commit
This hook halts your commit if there are any Rubocop errors. You can abort the commit with n/N
or ignore warnings and commit anyway with any other key.
Best practice is to abort the commit and run rubocop -a
to attempt to autocorrect any errors, and manually correct any remaining complaints. Then, re-add your files and commit again. For instance:
git add .
git commit -m "Commit message"