Git Hooks

This document is a guide on how to add coala as a git hook. Using a git hookcoala can be executed automatically, ensuring your code follows your qualityrequirements.

Pre-Commit Hooks

The pre-commit hook can be used to run coala before every commit action.Hence, this does not allow any code not following the quality standardsspecified unless it’s done by force.

To enable this, just create the file .git/hooks/pre-commit under yourrepository and add the lines:

  1. #!/bin/sh
  2. set -e
  3. coala

You can also specify arguments like -S autoapply=false which tellscoala to not apply any patch by itself. Or you can run specific sections withcoala <section_name>.

See also

Note

If you allow coala to auto apply patches, it’s recommended to add*.orig to your .gitignore. coala creates these files while applyingpatches and they could be erroneously added to your commit.

This file needs to be executable. If it is not (or if you aren’t sure), youcan make it executable by running

  1. $ chmod +x .git/hooks/pre-commit

and you’re done! It will run every time before you commit, and preventyou from committing if the code has any errors.