Installs a commit-msg hook that runs mix presubmit --staged --message-file "$1", so the staged changes and the message are checked
together before the commit is created, and a prepare-commit-msg hook that
tells it when the commit amends HEAD, so the amended commit (HEAD^ to
the index) is what gets checked rather than the delta since HEAD.
mix presubmit.install # prepare-commit-msg + commit-msg hooks
mix presubmit.install --pre-commit # also a pre-commit hook (content rules, before the editor opens)
mix presubmit.install --uninstall # remove the hooks this task installedRun it from the project directory (where mix.exs is); in a subdirectory
project of a larger repository the hooks cd there before running. Hooks
live in the repository's hooks directory, which is not versioned: each
clone runs this once. A hook that was not installed by this task is never
overwritten, and installation is refused when core.hooksPath is set.
The hooks refuse a commit only when presubmit ran and a rule failed. When
presubmit cannot run (Mix stops on stale or unresolvable dependencies, the
configuration does not load), they print presubmit could not run: <the error>; commit allowed, CI still checks and let the commit through. They
also skip, with a note, while a merge is in progress, when amending a merge
commit, and when mix is not on PATH; git commit --no-verify bypasses
them entirely. Keep mix presubmit in CI as the backstop.