fix(pre-push): treat SHA-256 all-zero OIDs as null object#3724
Closed
Solaris-star wants to merge 1 commit into
Closed
fix(pre-push): treat SHA-256 all-zero OIDs as null object#3724Solaris-star wants to merge 1 commit into
Solaris-star wants to merge 1 commit into
Conversation
Z40 only matched SHA-1 zero OIDs. On object-format=sha256 repos, git emits 64-char zero OIDs for deletions/new branches, so pre-push fell through into invalid rev-list ranges and blocked git push --delete. Treat any all-zero hex string as the null OID. Fixes pre-commit#3664 Signed-off-by: Solaris-star <820622658@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
pre_commit/commands/hook_impl.pyhardcodes:and compares
local_sha/remote_shaagainst it to detect deletion-only pushes and new branches.On repositories initialized with
--object-format=sha256, git's pre-push protocol emits 64-character zero OIDs. The equality never matches, deletion short-circuit never fires, and pre-commit ends up runninggit rev-list/diffagainst invalid ranges, exiting non-zero — sogit push origin --delete <branch>is refused.Fix
_is_zero_oid(sha)that accepts any non-empty all-zero hex string (SHA-1 or SHA-256)._pre_push_ns.Z40for existing tests; addZ64+ regression tests for SHA-256 deletion stdin.Tests
Linked Issue
Closes #3664