mise generate git-pre-commit
- 用法:
mise generate git-pre-commit [FLAGS] [-- MISE_ARG]… - 别名:
pre-commit - 效果: 修改状态
- 源代码:
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
参数
[-- MISE_ARG]…— 要嵌入生成的钩子中的 mise 标志,写在--之后这些参数会插入到
mise和run之间,因此钩子会携带你在命令行中传递的相同上下文。当配置文件不在仓库根目录时很有用,因为 git 会从顶层目录运行钩子:-- -C subdir会让钩子找到它。
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-push默认值:
pre-commit-h --help— 打印帮助
示例
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