@@ -26,7 +26,7 @@ You can copy/paste the following snippet into your `.pre-commit-config.yaml` fil
2626 # that Pre-Commit passes into the hook.
2727 # For repo-based hooks, '--' is not needed.
2828 #
29- # NOTE: You can pass environment variables to hooks using args with the
29+ # NOTE: You can pass environment variables to hooks using args with the
3030 # following format:
3131 #
3232 # --hook:env:NAME=VALUE
@@ -228,6 +228,115 @@ You can pass multiple `--hook:env:` arguments.
228228
229229The arguments can appear anywhere in the `args:` list.
230230
231+ #### Passing Ignore Patterns To Hooks
232+
233+ You can pass arguments to hooks to specify files / directories to ignore.
234+
235+ ##### Ignoring Directories
236+
237+ To specify a directory to ignore, use:
238+
239+ * `--hook:ignore-dir=PATTERN`
240+
241+ **Pattern Syntax**
242+
243+ Here's a table with examples of how the directory ignore patterns work:
244+
245+ | <sub>(see legend below)</sub> | `/foo` | `/foo/bar` | `/foo/*/bar` | `bar` | `bing/bar` | `bing/*/bar` | `foo/*/bang/*/bar` |
246+ |:------------------------------|:------:|:----------:|:------------:|:-----:|:----------:|:------------:|:------------------:|
247+ | `file` | | | | | | | |
248+ | `foo/file` | ✔ | | | | | | |
249+ | `foo/bar/file` | ✔ | ✔ | | ✔ | | | |
250+ | `foo/bing/bar/file` | ✔ | | ✔ | ✔ | ✔ | | |
251+ | `foo/bing/bang/bar/file` | ✔ | | ✔ | ✔ | | ✔ | |
252+ | `foo/bing/bang/baz/bar/file` | ✔ | | ✔ | ✔ | | ✔ | ✔ |
253+ | `bar/file` | | | | ✔ | | | |
254+ | `bing/bar/file` | | | | ✔ | ✔ | | |
255+ | `bing/bang/bar/file` | | | | ✔ | | ✔ | |
256+
257+ <sub>rows = filenames. columns = ignore patterns. ✔ = directory ignored (matched).</sub>
258+
259+ NOTES:
260+ * Only the directory portion of the filename is considered for matching
261+ * File `foo/bar/file` would attempt to match patterns against the directory `foo/bar`
262+ * Patterns with leading slash (`/`) indicate that the pattern is _anchored_ and must match the **beginning** of the directory path
263+ * Pattern `/bar` would match filenames `bar/file` and `bar/bang/file`, but **not** `foo/bar/file`
264+ * Patterns without leading slash (`/`) indicate that the pattern is _floating_ and can match **anywhere** in the directory path
265+ * Pattern `bar` would match **all** filenames `bar/file`, `bar/bang/file` and `foo/bar/file`
266+ * Trailing slashes (`foo/`) are not supported and are ignored
267+ * Explicit Leading and trailing wildcards (`*/foo`, `foo/*`, `*/foo/*`) are not supported
268+ * Recursive directory patterns (`**`) are not supported
269+
270+ ##### Ignoring Files
271+
272+ To specify files to ignore, use:
273+
274+ * `--hook:ignore-file=PATTERN`
275+
276+ **Pattern Syntax**
277+
278+ Here's a table with examples of how the file ignore patterns work:
279+
280+ | <sub>(see legend below)</sub> | `file1.txt` | `file?.txt` | `file2.*` | `*.md` | `bar/*.md` | `/bar/*.txt` |
281+ |:------------------------------|:-----------:|:-----------:|:---------:|:------:|:----------:|:------------:|
282+ | `file1.txt` | ✔ | ✔ | | | | |
283+ | `file2.txt` | | ✔ | ✔ | | | |
284+ | `file3.md` | | | | ✔ | | |
285+ | `foo/file1.txt` | ✔ | ✔ | | | | |
286+ | `bar/file1.txt` | ✔ | ✔ | | | | ✔ |
287+ | `bar/file2.md` | | | ✔ | ✔ | ✔ | |
288+ | `foo/bar/file4.txt` | | ✔ | | | | |
289+ | `foo/bar/file5.md` | | | | ✔ | ✔ | |
290+
291+ <sub>rows = filenames. columns = ignore patterns. ✔ = file ignored (matched).</sub>
292+
293+ NOTES:
294+ * Patterns with no slashes (`/`) are only matched against the filename portion of the file path
295+ * Pattern `file.txt` would match filenames `file.txt`, `foo/file.txt`, and `bar/file.txt`
296+ * Patterns with leading slash (`/`) indicate that the pattern is _anchored_ and must match the **full** file path
297+ * Pattern `/bar/file` would match filename `bar/file`, but **not** `foo/bar/file`
298+ * Patterns without leading slash (`/`) indicate that the pattern is _trailing_ and just needs to match the **end** of the file path
299+ * Pattern `bar/file` would match filenames `bar/file` and `foo/bar/file`
300+ * Explicit Leading (`*/foo/file`) are not supported
301+ * Recursive directory patterns (`**`) are not supported
302+
303+
304+ ##### Ignore By Pattern
305+
306+ If the directory and file-based convenience options are not enough, you can specify a more complicated (bash-specific) pattern.
307+
308+ To specify these types of patterns to ignore, use:
309+
310+ * `--hook:ignore-pattern=PATTERN`
311+
312+ **Pattern Syntax**
313+
314+ Here's a table with examples of how the general ignore patterns work:
315+
316+ | <sub>(see legend below)</sub> | `file` | `foo/bar/*` | `foo/*/bar/*` | `*/file` | `*/bar/file` | `*/bar/*` | `*/bing/*/bar/*` | `*/b?ng/*/file` |
317+ |:------------------------------|:------:|:-----------:|:-------------:|:--------:|:------------:|:---------:|:----------------:|:---------------:|
318+ | `file` | ✔ | | | | | | | |
319+ | `foo/file` | | | | ✔ | | | | |
320+ | `foo/bar/file` | | ✔ | | ✔ | ✔ | ✔ | | |
321+ | `foo/bing/bar/file` | | | ✔ | ✔ | ✔ | ✔ | | ✔ |
322+ | `foo/bang/bar/file` | | | ✔ | ✔ | ✔ | ✔ | | ✔ |
323+ | `foo/bing/bang/bar/file` | | | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
324+ | `foo/bing/bang/baz/bar/file` | | | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
325+ | `bar/file` | | | | ✔ | | | | |
326+ | `bing/bar/file` | | | | ✔ | ✔ | ✔ | | |
327+ | `bing/bang/bar/file` | | | | ✔ | ✔ | ✔ | | ✔ |
328+ | `.file` | | | | | | | | |
329+ | `.bar/file` | | | | ✔ | | | | |
330+ | `foo/.bang/bar/file` | | | ✔ | ✔ | ✔ | ✔ | | |
331+
332+ <sub>rows = filenames. columns = ignore patterns. ✔ = file ignored (matched).</sub>
333+
334+ NOTES:
335+ * Patterns are matched against the **full** (relative) file path
336+ * Patterns are Bash-specific (although _possibly_ POSIX compliant) and are **not** regular expressions (regex)
337+ * See the Official Bash documentation for [Pattern Matching](https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching)
338+ * Patterns based on `extglob` setting/syntax are **not** supported
339+
231340#### Always Run
232341By default, hooks ONLY run when matching file types (usually `*.go`) are staged.
233342
0 commit comments