Reputation: 19
I am using pre-commit to manage local hooks for my repository. Initially, I added a local repository containing my hooks and configured the .pre-commit-config.yaml
file to reference these hooks. It worked perfectly both in my local environment and in the CI pipeline.
snippet of code from .pre-commit-config.yaml. I have installed pre_commit_hooks
as a local module, configed
- repo: local
hooks:
- id: trailing-whitespace
name: Trim trailing-whitespace
language: python
entry: python3 -m pre_commit_hooks.trailing_whitespace_fixer
additional_dependencies: [pre_commit_hooks]
However, I noticed a strange behavior:
If I delete the directory containing the hooks (the repository with the hooks files), pre-commit still runs the hooks successfully.
I tried clearing the cache using pre-commit clean
and even manually deleted the cache folder (e.g., ~/.cache/pre-commit/
), but the hooks still run without issues.
I cannot figure out how pre-commit is able to find and execute the hooks after the source directory has been deleted.
My questions:
How is pre-commit able to find and execute the hooks after the source directory is deleted?
How can I ensure pre-commit no longer runs the hooks if the source directory is deleted?
I have tried:
Cleared Pre-Commit Cache:
Ran pre-commit clean
and manually removed the cache directory (e.g., ~/.cache/pre-commit
).
Verified the cache directory was empty.
Removed Git Hooks:
.git/hooks/
for any residual scripts and deleted the pre-commit
script.Verified Configuration:
.pre-commit-config.yaml
file temporarily, and as expected, pre-commit failed to run.Inspected Pre-Commit’s Behavior:
pre-commit run --verbose
to trace execution but didn’t find useful information about where the hooks were being sourced from.Upvotes: 1
Views: 69
Reputation: 70175
pre-commit will always ensure that the configured repositories are installed. pre-commit install
just installs the .git/hooks/<whatever>
script (unless you specify --install-hooks
kind of the magic (and point) of pre-commit is as long as you've run pre-commit install
once it will always make sure that it runs exactly what is configured
if you show your output it should be pretty obvious (it will say something about installing hooks for local
...)
or perhaps you're confused what additional_dependencies: [pre_commit_hooks]
does -- this installs https://pypi.org/p/pre-commit-hooks (and definitely not your ./pre_commit_hooks
-- pre-commit never installs from the repository under test)
disclaimer: I wrote pre-commit
Upvotes: 1