Skip to content

Handle SHA-256 zero OIDs in pre-push#3705

Closed
marko1olo wants to merge 1 commit into
pre-commit:mainfrom
marko1olo:fix-pre-push-sha256-delete
Closed

Handle SHA-256 zero OIDs in pre-push#3705
marko1olo wants to merge 1 commit into
pre-commit:mainfrom
marko1olo:fix-pre-push-sha256-delete

Conversation

@marko1olo

Copy link
Copy Markdown

Fixes #3664.

Summary

  • Recognize both SHA-1 (40 hex) and SHA-256 (64 hex) all-zero object IDs in the pre-push hook protocol.
  • Keep deletion-only pushes as no-op pre-push runs instead of constructing a diff against a zero object ID.
  • Add regression coverage for SHA-256 branch deletion stdin while preserving the existing SHA-1 deletion behavior.

Verification

  • python -m pytest tests\commands\hook_impl_test.py -k "zero_oid or pre_push" -q passed: 9 passed.
  • python -m pytest tests\commands\hook_impl_test.py -k "not legacy" -q passed: 41 passed, 5 deselected.
  • python -m compileall -q pre_commit\commands\hook_impl.py tests\commands\hook_impl_test.py passed.
  • git diff --check passed.
  • SKIP=mypy pre-commit run --files pre_commit\commands\hook_impl.py tests\commands\hook_impl_test.py passed all non-mypy hooks.

Windows-local notes:

  • python -m pytest tests\commands\hook_impl_test.py -q reported 45 passed and 1 failed because test_run_legacy_executes_legacy_script needs bash, which is not available in this Windows environment.
  • The full mypy pre-commit hook reported existing Windows/platform-specific errors in unrelated modules (pre_commit\color.py, pre_commit\xargs.py, pre_commit\languages\docker.py) while checking these files.

@asottile asottile closed this Jun 6, 2026
@pre-commit pre-commit locked as spam and limited conversation to collaborators Jun 6, 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