Skip to content

fix: support sha256 zero object ids in pre-push hooks - #3761

Closed
chen-maker999 wants to merge 1 commit into
pre-commit:mainfrom
chen-maker999:fix/3664-sha256-zero-oid
Closed

chen-maker999 wants to merge 1 commit into
pre-commit:mainfrom
chen-maker999:fix/3664-sha256-zero-oid

Conversation

@chen-maker999

Copy link
Copy Markdown

Fixes #3664.

hook_impl used a 40-character zero object ID to detect deleted refs during pre-push. Git emits 64-character zero IDs in SHA-256 repositories, so deleting a branch could fall through to an invalid revision range and reject the push.

The new helper recognizes zero IDs for both supported object formats. The regression test exercises both 40-character and 64-character deletion records.

Tests:

  • python -m pytest tests/commands/hook_impl_test.py -q -k "new_branch or deleting_branch" (4 passed)
  • pre-commit run --files pre_commit/commands/hook_impl.py tests/commands/hook_impl_test.py (formatting, imports, pyupgrade, autopep8, and flake8 passed; mypy reports existing baseline errors in unrelated files)
  • The full hook_impl_test.py run has 44 passing tests and one existing Windows-specific legacy-script failure unrelated to this change.

@asottile asottile closed this Sep 26, 2026
@pre-commit pre-commit locked as spam and limited conversation to collaborators Sep 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Z40 = '0' * 40 hardcoding breaks git push --delete on SHA-256 repos

2 participants