mise generate git-pre-commit
- Usage:
mise generate git-pre-commit [FLAGS] [-- MISE_ARG]… - Aliases:
pre-commit - Effect: modifies state
- Source code:
src/cli/generate/git_pre_commit.rs
Generate a git hook that runs a mise task
The hook runs mise run <TASK> (default pre-commit) with the staged file names in the STAGED environment variable. It prints the hook unless you pass --write, which saves it in the repository's hooks directory and makes it executable.
For hooks that git gives a message file (commit-msg, prepare-commit-msg, applypatch-msg, sendemail-validate), the task gets that file as an argument. Other hook arguments, such as a pre-push hook's remote name and URL, are not passed on.
For a full git hook manager, see hk: https://hk.jdx.dev
Arguments
[-- MISE_ARG]…— mise flags to embed in the generated hook, given after--These are inserted between
miseandrun, so the hook carries the same context you would pass on the command line. Useful when the config is not at the repository root, since git runs hooks from the top level:-- -C subdirmakes the hook find it.
Flags
-t --task <TASK>— The task to run when the hook is triggeredDefault:
pre-commit-w --write— Write the hook to the hooks directory and make it executableThe hooks directory is
.git/hooks, orcore.hooksPathwhen it is set. An existing hook of the same name is moved to<HOOK>.old.--hook <HOOK>— Which git hook to write, such as pre-pushDefault:
pre-commit-h --help— Print help
Examples
Install the hook; each commit then runs mise run pre-commit
mise generate git-pre-commit --write --task=pre-commitUse the config in subdir, since git runs hooks from the repository root
mise generate git-pre-commit --write -- -C subdir