1

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.)

lofidevops
  • 15,528
  • 14
  • 79
  • 119

1 Answers1

1

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

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • thank you! I've elaborated on my use cases for clarity, but I understand now that this is outside the scope of precommit – lofidevops Jul 20 '22 at 16:11