Whisky is the simplest, framework agnostic, CLI tool for managing and enforcing a php project's git hooks across an entire team.
Git hooks are a fantastic tool to ensure that code hitting version control satisfies your org's code quality standards. However, .git/hooks
is not included in your git tree. This makes it impractical to have all contributors to a repository use the same checks with the same settings.
Whisky's only dependency is php^8.1
.
You can install the package via composer:
composer require --dev projektgopher/whisky
./vendor/bin/whisky install
Note It is recommended to only require Whisky on a project level, as it does not currently work as expected when installed globally.
The install
command will create a whisky.json
file in your project root:
{
"disabled": [],
"hooks": {
"pre-commit": [
"./vendor/bin/pint --dirty"
],
"pre-push": [
"php artisan test"
]
}
}
For a complete list of supported git hooks, see the Git Documentation.
Adding or removing any hooks (not individual commands) to your whisky.json
file should be followed by ./vendor/bin/whisky update
to ensure that these changes are reflected in your .git/hooks
directory.
Warning all hooks are evaluated as-is in the terminal. Keep this in mind when committing anything involving changes to your
whisky.json
.
Sometimes you need to commit or push changes without running your git hooks,
like when handing off work to another computer. This can usually be done
using git's native --no-verify
flag.
git commit -m "wip" --no-verify
However, some git actions don't support this flag, like git merge --continue
.
In this case, running the following command will have the exact same effect.
./vendor/bin/whisky skip-once
Note by adding
alias whisky=./vendor/bin/whisky
to yourbash.rc
file, you can shorten the length of this command.
Adding a hook's name to the disabled
array in your whisky.json
will disable the hook from running.
This can be useful when building out a workflow that isn't ready for the rest of the team yet.
For anything more complicated than simple terminal commands it's recommended to create a
scripts
directory in your project root. This comes with the added benefit of allowing
you to run scripts written in any language.
// whisky.json
// ...
"pre-push": [
"composer lint",
"rustc ./scripts/complicated_thing.rs"
]
// ...
Note When doing this, make sure any scripts referenced are executable:
chmod +x ./scripts/*
composer test
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
A big "Thank You" to EXACTsports for supporting the development of this package.
The MIT License (MIT). Please see License File for more information.