Skip to content

fix: handle SHA-256 zero OIDs in pre-push hook#3691

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

fix: handle SHA-256 zero OIDs in pre-push hook#3691
karlhillx wants to merge 1 commit into
pre-commit:mainfrom
karlhillx:fix/sha256-zero-oid

Conversation

@karlhillx
Copy link
Copy Markdown

Fix SHA-256 zero OID handling in pre-push hook

In repositories initialized with --object-format=sha256, git's pre-push hook protocol emits 64-character zero OIDs instead of the SHA-1 40-character variety. The previous hardcoded check

Z40 = '0' * 40
if local_sha == Z40:

never matched in SHA-256 repos, causing git push --delete to fail with:

fatal: Invalid symmetric difference expression <sha>...<64-zeros>

Add _is_zero_oid() as a hash-format-agnostic helper that accepts zero OIDs of either supported length (40 or 64), replacing the hardcoded Z40 constant in _pre_push_ns.

Also adds test_run_ns_pre_push_deleting_branch_sha256 as a regression test for the SHA-256 deletion push case.

Fixes #3664

@asottile
Copy link
Copy Markdown
Member

sorry we didn't accept ai contributions

@asottile asottile closed this May 16, 2026
@karlhillx karlhillx deleted the fix/sha256-zero-oid branch May 16, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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