Skip to content

Instantly share code, notes, and snippets.

@binderclip
Created March 15, 2017 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binderclip/69d21bb543879ff8b59d60b8cf604263 to your computer and use it in GitHub Desktop.
Save binderclip/69d21bb543879ff8b59d60b8cf604263 to your computer and use it in GitHub Desktop.
如何设置 pre_commit 的 exclude

如何设置 pre_commit 的 exclude

首先 exclude 只能作用于 hook,所以需要在 hook 的位置去配置,而不能作用于全局的 repo,可以从下面看到:

https://github.com/pre-commit/pre-commit/blob/master/pre_commit/clientlib.py#L51

另外实验一下会发现在 repo 上配置 exclude 不会被读取(比如故意填写成 array 也不会报错)。而在 hook 上类型填错的话会报错。

另外在 run_hook 的函数中也看到了是从 hook 的配置中读取的配置。

https://github.com/pre-commit/pre-commit/blob/master/pre_commit/commands/run.py#L60

所以只好设置在 hook 里面了。

同时已经知道了填写的 exclude 应该是一个正则表达式,判断规则如下:

https://github.com/pre-commit/pre-commit/blob/master/pre_commit/git.py#L101

@binderclip
Copy link
Author

另外测试的时候可以直接 pre-commit run 而不用真的去用 commit 来触发

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment