Git hooks made easy
Husky is an elixir version of the husky npm module.
Husky can prevent bad git commit, git push and more 🐶 ❤️ woof!
The Husky Hex package can be installed
by adding husky to your list of dependencies in mix.exs:
defp deps do
[
{:husky, "~> 1.0", only: :dev, runtime: false}
]
end- On compile, husky will install git hook scripts (
mix husky.installto install manually) - Configure git hook commands in either your
config/dev.exsor a.husky.jsonfile- Note:
config/dev.exswill take precedence over.husky.jsonif there are key conflicts
- Note:
use Mix.Config
config :husky,
pre_commit: "mix format && mix credo --strict",
pre_push: "mix format --check-formatted && mix credo --strict && mix test"View example file config.example.exs
.husky.json
{
"husky": {
"hooks": {
"pre_commit": "mix format && mix credo --strict",
"pre_push": "mix format --check-formatted && mix credo --strict && mix test"
}
}
}View example file .husky.example.json
With the above setup:
git commitwill executemix formatandmix credo --strictand only commit if credo succeeds.git pushwill executemix format,mix credo, andmix test, and only push if all three commands succeed.git commit --no-verifystill commit even ifmix credo --strictfails
export HUSKY_SKIP_INSTALL=trueHUSKY_SKIP_HOOKS=true git rebase -i develop- Remove git hook scripts
mix husky.delete
Documentation can found at https://hexdocs.pm/husky.
See the development README.md