GeezerVison is showing github.com — `pre-push` hooks are intentionally not run on ref deletion · Issue #3050 · pre-commit/pre-commit
pre-push hooks are intentionally not run on ref deletion #3050
Descriptionsearch you tried in the issue tracker
pre-push
describe your issue
I am attempting to write a pre-push hook which prevents tag deletion.
By way of print statements, I observe the following behavior.
When I install the pre-push hook via pre-commit:
- I push a tag with
git push origin tmptag, the hook is invoked.
- I delete a tag with
git push origin :tmptag, the hook is not invoked
In contrast, if I forgo pre-commit and manually put a pre-push file in my .git/hooks/ folder
- I push a tag with
git push origin tmptag, the hook is invoked.
- I delete a tag with
git push origin :tmptag, the hook is invoked
Am I misunderstanding how the pre-push hook of pre-commit is supposed to work? Or is there some logic within pre-commit to skip the execution of pre-push hooks under certain circumstances?
pre-commit --version
3.3.3
.pre-commit-config.yaml
- repo: local
hooks:
- id: prevent-tag-deletion
name: prevent tag deletion
entry: python
language: system
args: ['pre_push.py']
stages: [pre-push]
verbose: true
~/.cache/pre-commit/pre-commit.log (if present)
No response Activitywhophil commented on Nov 3, 2023 Snooping around, the behavior seems related to these lines
|
if local_sha == Z40: |
|
continue |
which return a namespace of None if local_sha == "0" * 40 - this is the case when a ref is deleted. Curious, what is the reason why pre-push hooks are skipped in this case? asottile commented on Nov 3, 2023 pre-commit is for linting new change sets and so deletions are ignored. you can use a legacy hook if you want but your use case is intentionally not managed by the framework whophil commented on Nov 3, 2023 Thanks @asottile! For my specific case, it is a "small" hack to just make the pre-push hook run in the case of a ref deletion.
Is there a chance you'd entertain a change related to this capability? asottile commented on Nov 3, 2023 no. this would be a breaking change whophil commented on Nov 3, 2023 It indeed would be breaking as written. Perhaps "pre-push on ref deletion" could be enabled via some sort of configuration flag, which is disabled by default? (This is my last suggestion before conceding, as surely I do not understand the full scope of such a change). asottile commented on Nov 3, 2023 yeah I'm not going to add a configuration option for something I would never use, and something the tool intentionally is designed to not support. you're free to maintain a fork though to add whatever functionality you might want changed the title [-]When is a `pre-push` hook executed or skipped?[/-] [+]`pre-push` hooks are intentionally not run on ref deletion[/+] on Nov 3, 2023whophil commented on Nov 3, 2023 Maintaining/packaging a fork is not worth it for me, so I will pursue other options. Thanks for the discussion.
Changed issue name to aid future searchers.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|