8000 Elaborate on hook level confinement, add a few examples · pre-commit/pre-commit.com@886dcec · GitHub 7FFF
[go: up one dir, main page]

Skip to content

Commit 886dcec

Browse files
scopasottile
authored andcommitted
Elaborate on hook level confinement, add a few examples
Per discussion at and around pre-commit/pre-commit#2076 (comment)
1 parent 5e2783e commit 886dcec

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

sections/advanced.md

Lines changed: 9 additions & 2 deletions
+
reasonable setting for code formatter and the like hooks would be
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,16 @@ to run at the stage defined through that option. For instance,
220220
to run at the `push` stage.
221221

222222
Hooks can however be confined to a stage by setting the [`stages`](#config-stages)
223-
property in your `.pre-commit-config.yaml`. The [`stages`](#config-stages) property
224-
is an array and can contain any of `commit`, `merge-commit`, `push`, `prepare-commit-msg`,
223+
property in your `.pre-commit-config.yaml`, and the corresponding [`stages`](#hook-stages)
224+
property in the hook's `.pre-commit-hooks.yaml` definition. The `stages` properties
225+
are arrays and can contain any of `commit`, `merge-commit`, `push`, `prepare-commit-msg`,
225226
`commit-msg`, `post-checkout`, `post-commit`, `post-merge`, `post-rewrite`, and `manual`.
227+
It is useful to provide an appropriate set of stages out of the box in
228+
`.pre-commit-hooks.yaml` hook definitions to avoid unnecessary runs of hooks in
229+
stages where they do not and can not do anything useful. For example, a
230
231+
`stages: [commit, merge-commit, push, manual]`, and one for hooks that operate
232+
on commit messages could be `stages: [commit-msg, manual]`.
226233

227234
If you do not want to have hooks installed by default on the stage passed
228235
during a `pre-commit install --hook-type ...`, please set the [`default_stages`](#top_level-default_stages)

sections/new-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ file that tells pre-commit:
8080
=c= [`stages`](_#hooks-stages)
8181
=c= (optional: default (all stages)) confines the hook to the `commit`, `merge-commit`,
8282
`push`, `prepare-commit-msg`, `commit-msg`, `post-checkout`, `post-commit`,
83-
`post-merge`, `post-rewrite`, or `manual` stage. See
83+
`post-merge`, `post-rewrite`, and/or `manual` stage(s). See
8484
[Confining hooks to run at certain stages](#confining-hooks-to-run-at-certain-stages).
8585
8686
```

0 commit comments

Comments
 (0)
0