Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-push hooks are intentionally not run on ref deletion #3050

Closed
whophil opened this issue Nov 3, 2023 · 7 comments
Closed

pre-push hooks are intentionally not run on ref deletion #3050

whophil opened this issue Nov 3, 2023 · 7 comments

Comments

@whophil
Copy link

whophil commented Nov 3, 2023

search 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

@whophil
Copy link
Author

whophil commented 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
Copy link
Member

asottile commented 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

@asottile asottile closed this as completed Nov 3, 2023
@whophil
Copy link
Author

whophil commented 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
Copy link
Member

asottile commented Nov 3, 2023

no. this would be a breaking change

@whophil
Copy link
Author

whophil commented 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
Copy link
Member

asottile commented 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

@whophil whophil changed the title When is a pre-push hook executed or skipped? pre-push hooks are intentionally not run on ref deletion Nov 3, 2023
@whophil
Copy link
Author

whophil commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants