Skip to content

Commit a3effcb

Browse files
authored
Merge pull request #1054 from pre-commit/4_5_0
document `pre-commit hazmat`
2 parents 60e4016 + f35f043 commit a3effcb

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

sections/advanced.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,99 @@ The currently available `meta` hooks:
352352
debugging.
353353
```
354354

355+
## `pre-commit hazmat`
356+
357+
"hazardous materials"
358+
359+
pre-commit provides a few `entry` prefix "helpers" for unusual situations.
360+
361+
in case it's not clear, using these is _usually_ a bad idea.
362+
363+
_note_: hazmat helpers do not work on languages which adjust `entry` (`docker`
364+
/ `docker_image` / `fail` / `julia` / `pygrep` / `r` / `unsupported_script`).
365+
366+
### `pre-commit hazmat cd`
367+
368+
_new in 4.5.0_
369+
370+
for "monorepo" usage one can use this to target a subdirectory.
371+
372+
this entry prefix will cd to the target subdir and adjust filename arguments
373+
374+
example usage:
375+
376+
```yaml
377+
# recommended:
378+
# minimum_pre_commit_version: 4.5.0
379+
repos:
380+
- repo: ...
381+
rev: ...
382+
hooks:
383+
- id: example
384+
alias: example-repo1
385+
name: example (repo1)
386+
files: ^repo1/
387+
# important! ends with `--`
388+
# important! copy `args: [...]` to entry and blank out `args: []`
389+
entry: pre-commit hazmat cd repo1 example-bin --arg1 --
390+
args: []
391+
392+
- id: example
393+
alias: example-repo2
394+
name: example (repo2)
395+
files: ^repo2/
396+
entry: pre-commit hazmat cd repo2 example-bin --arg1 --
397+
args: []
398+
399+
# ... etc.
400+
```
401+
402+
### `pre-commit hazmat ignore-exit-code`
403+
404+
_new in 4.5.0_
405+
406+
it's a bad idea to introduce warning noise but this gives you a way to do it.
407+
408+
example:
409+
410+
```yaml
411+
# recommended:
412+
# minimum_pre_commit_version: 4.5.0
413+
repos:
414+
- repo: ...
415+
rev: ...
416+
hooks:
417+
- id: example
418+
# important! copy `args: [...]` to entry and blank out `args: []`
419+
entry: pre-commit hazmat ignore-exit-code example-bin --arg1 --
420+
args: []
421+
# otherwise the output will always be hidden
422+
verbose: true
423+
```
424+
425+
### `pre-commit hazmat n1`
426+
427+
_new in 4.5.0_
428+
429+
some hooks only take one filename argument. this runs them one at a time
430+
(which is super slow!)
431+
432+
example:
433+
434+
```yaml
435+
# recommended:
436+
# minimum_pre_commit_version: 4.5.0
437+
repos:
438+
- repo: ...
439+
rev: ...
440+
hooks:
441+
- id: example
442+
# important! ends with `--`
443+
# important! copy `args: [...]` to entry and blank out `args: []`
444+
entry: pre-commit hazmat n1 example-bin --arg1 --
445+
args: []
446+
```
447+
355448
## automatically enabling pre-commit on repositories
356449
357450
`pre-commit init-templatedir` can be used to set up a skeleton for `git`'s

0 commit comments

Comments
 (0)