Git Hooks

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

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 standards specified unless it’s done by force.

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

$ #!/bin/sh
$ set -e
$ coala

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

See also

Module Tutorial for Users
Documentation on how to run coala which introduces the CLI arguments.
Module coafile Specification
Documentation on how to configure coala using the coafile specification.

Note

If you allow coala to auto apply patches, it’s recommended to add *.orig to your .gitignore. coala creates these files while applying patches 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), you can make it executable by running

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

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