Pre-Commit
Fleeting- External reference: https://pre-commit.com/index.html
pre-commit
automatically enabling pre-commit on repositories
pre-commit init-templatedir can be used to set up a skeleton for git’s init.templateDir option. This means that any newly cloned repository will automatically have the hooks set up without the need to run pre-commit install.
To configure, first set git’s init.templateDir – in this example I’m using ~/.git-template as my template directory.
$ git config –global init.templateDir ~/.git-template $ pre-commit init-templatedir ~/.git-template
pre-commit installed at home/asottile.git-template/hooks/pre-commit
To check only files which have changed, which may be faster, use something like pre-commit run –from-ref origin/HEAD –to-ref HEAD
Managing CI Caches
pre-commit by default places its repository store in ~/.cache/pre-commit – this can be configured in two ways:
- PRE_COMMIT_HOME: if set, pre-commit will use that location instead.
- XDG_CACHE_HOME: if set, pre-commit will use $XDG_CACHE_HOME/pre-commit following the XDG Base Directory Specification.
circleci […] uses immutable caches: steps:
- run: command: | cp .pre-commit-config.yaml pre-commit-cache-key.txt python –version –version >> pre-commit-cache-key.txt
- restore_cache: keys:
- v1-pc-cache-{{ checksum “pre-commit-cache-key.txt” }}