GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

New issue
Copy link
New issue
Copy link
Closed
Closed
pre-push hooks are intentionally not run on ref deletion#3050
Copy link

Description

@whophil
whophil
opened on Nov 3, 2023
Issue body actions

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

Activity

  1. whophil commented on Nov 3, 2023

    @whophil
    whophil
    on Nov 3, 2023
    Author
    More actions

    Snooping around, the behavior seems related to these lines

    pre-commit/pre_commit/commands/hook_impl.py

    Lines 127 to 128 in 14169eb

    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?

  2. asottile commented on Nov 3, 2023

    @asottile
    asottile
    on Nov 3, 2023
    Member
    More actions

    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

  3. asottile
    closed this as completedon Nov 3, 2023
  4. whophil commented on Nov 3, 2023

    @whophil
    whophil
    on Nov 3, 2023
    Author
    More actions

    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?

  5. asottile commented on Nov 3, 2023

    @asottile
    asottile
    on Nov 3, 2023
    Member
    More actions

    no. this would be a breaking change

  6. whophil commented on Nov 3, 2023

    @whophil
    whophil
    on Nov 3, 2023
    Author
    More actions

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

  7. asottile commented on Nov 3, 2023

    @asottile
    asottile
    on Nov 3, 2023
    Member
    More actions

    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

    Reacted by Phil Chiu
  8. whophil
    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, 2023
  9. whophil commented on Nov 3, 2023

    @whophil
    whophil
    on Nov 3, 2023
    Author
    More actions

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.