I am interested in adopting the pre-commit framework. I would like to create hooks for common errors that I tend make. For example, I want to:
- stop myself committing to a branch named "main" or "master" even in projects that have not (yet) adopted pre-commit
- use the correct Git persona (personal vs work) when committing
- confirm I have made a signed commit even in projects that have not (yet) adopted pre-commit or signing conventions
- ...and more
These hooks are likely not appropriate for inclusion in project-specific repos, so they should not be stored in $PROJECT/.pre-commit-config.yaml
. Additionally, I don't want to have to copy them into every single repo I clone.
Is there a local location (in $XDG_CONFIG_HOME maybe?) for a "universal" .pre-commit-config.yaml
?
(Ideally the solution should be compatible with projects that do define their own pre-commit config.)
CodePudding user response:
not sure why "not committing to master / main" wouldn't be appropriate in the repo config though -- it's one of the more popular out of the box hooks
there is intentionally not a supported path for what you want -- the intent of pre-commit
is that the exact linting tools are versioned along with the repository so everything is kept consistent for all contributors
that said, you can add a legacy hook which calls pre-commit with your custom hooks
#!/usr/bin/env bash
exec pre-commit run --config ~/.config/pre-commit/config.yaml`
put that at .git/hooks/pre-commit.legacy
(or make it part of your init.templateDir
similar to what's written about here)
disclaimer: I wrote pre-commit