Smee is a Composer package designed to make it easier to share Git hooks with a project.
Git hooks are a useful way to automatically perform actions at different points throughout the Git lifecycle. These actions could include verifying coding standards, running unit tests, enforcing commit message formats, and more.
The downside to Git hooks is that they're not distributed with the Git repository, meaning it's difficult to ensure that all developers on a project are using the same hooks.
Smee aims to change that, by introducing the .githooks
directory and providing an easy way to automatically install the hooks on composer install
.
Smee should be added to your projects via Composer:
$ composer require --dev stevegrunwell/smee
To ensure Smee is automatically run for other users, add Smee to the "post-install-cmd" Composer event:
{
"scripts": {
"post-install-cmd": [
"smee install"
]
}
}
Finally, create a .githooks
directory in the root of your project, and add the hooks you'd like to use in your project. These files should be committed to the git repository, and will automatically be copied into other developers' local repositories the next time they run composer install
.
Git supports a number of hooks, which each fire at different points throughout the lifecycle. Each Git hook exists in a separate file, named after the hook it corresponds to (e.g. .git/hooks/pre-commit
will be executed on the "pre-commit" hook).
These are some of the most common Git hooks, firing at different points as a developer attempts to commit code:
Git also supports an email-based workflow via git am
, which applies patches in sequence from a mailbox. If you're using this workflow, a few additional hooks are available.
git commit --amend
.git checkout
command.git merge
command.git push
command.