Videos
there is intentionally no such "include" mechanism for pre-commit configurations.
each repository tends to have some customization needed (on top of a theoretical "base" configuration) and as such an include mechanism would tend to reduce flexibility instead of increasing convenience.
pre-commit already provides reusable repositories which is where the bulk of the complexity lies
there are hacky workarounds some have come up with in the issue tracker (such as utilizing a hook which itself calls pre-commit --config ... in a nested manner) but these are not encouraged
disclaimer: I wrote pre-commit
If I correctly understand your question, you need to create a .pre-commit-config.yaml file in each repository where you want to use this pre-commit configuration.
The file should look like this:
repos:
- repo: https://github.com/gruntwork-io/pre-commit
rev: v0.1.17
hooks:
- id: terraform-fmt
reposhould point to your repository containing the pre-commit hooks;revspecifies the version. You can use a Git tag, or a specific Git commit hash;hooks:idthis is anid(like name) of specific hook within your repository;
You can find all available parameters in the documentation
And here’s an example repository: https://github.com/gruntwork-io/pre-commit
And of course in each repo you need to do the following:
- Install pre-commit. E.g.
brew install pre-commit. - Run
pre-commit installin the repo.
Alternatively, instead of using pre-commit, you might find it more suitable to use a Git template along with Git hooks, such as prepare-commit-msg.
In that case you can check my repo with examples, which could serve as a good starting point.
The only downside is that you'll need to set the environment variable GIT_TEMPLATE_DIR which point to git-template, and run git int command every time after you updated git-template repo.