Title: Z40 = '0' * 40 hardcoding breaks `git push --delete` on SHA-256 repos · Issue #3664 · pre-commit/pre-commit · GitHub
Open Graph Title: Z40 = '0' * 40 hardcoding breaks `git push --delete` on SHA-256 repos · Issue #3664 · pre-commit/pre-commit
X Title: Z40 = '0' * 40 hardcoding breaks `git push --delete` on SHA-256 repos · Issue #3664 · pre-commit/pre-commit
Description: search you tried in the issue tracker sha256, SHA-256 push, sha-256 delete, Z40, object-format sha256, "Invalid revision range", "bad object", zero SHA, pre-push delete, deletion push The closest related hit is #3434 (closed), but that i...
Open Graph Description: search you tried in the issue tracker sha256, SHA-256 push, sha-256 delete, Z40, object-format sha256, "Invalid revision range", "bad object", zero SHA, pre-push delete, deletion push The closest r...
X Description: search you tried in the issue tracker sha256, SHA-256 push, sha-256 delete, Z40, object-format sha256, "Invalid revision range", "bad object", zero SHA, pre-push delete, deletio...
Opengraph URL: https://github.com/pre-commit/pre-commit/issues/3664
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Z40 = '0' * 40 hardcoding breaks `git push --delete` on SHA-256 repos","articleBody":"### search you tried in the issue tracker\n\n`sha256`, `SHA-256 push`, `sha-256 delete`, `Z40`, `object-format sha256`, `\"Invalid revision range\"`, `\"bad object\"`, `zero SHA`, `pre-push delete`, `deletion push`\n\nThe closest related hit is #3434 (closed), but that is about fetching sha1-format hook repos into a sha256 local repo — a different codepath.\n\n### describe your issue\n\n`pre_commit/commands/hook_impl.py` hardcodes the SHA-1 zero OID:\n\n```python\nZ40 = '0' * 40\n```\n\nIt is compared against `local_sha` / `remote_sha` to detect deletion-only pushes and new branches:\n\n```python\nif local_sha == Z40:\n continue\nelif remote_sha != Z40 and _rev_exists(remote_sha):\n ...\n```\n\nIn a repository initialized with `--object-format=sha256`, git's pre-push hook protocol emits 64-character zero OIDs rather than 40. The equality never matches, the deletion-only short-circuit never fires, and pre-commit falls through into `git diff --name-only ... \u003cold>..\u003c64-zeros>` (and then `\u003cold>...\u003c64-zeros>`). Both error out:\n\n```\nfatal: Invalid revision range 3dac4c61...6dce8d..000000...(×64)\nfatal: Invalid symmetric difference expression 3dac4c61...6dce8d...000000...(×64)\n```\n\npre-commit surfaces these as `An unexpected error has occurred: CalledProcessError` and exits non-zero, so `git push origin --delete \u003cbranch>` is refused on every sha256 repo. Branch deletion has to go through the forge's web UI or API to succeed.\n\nMinimal reproducer:\n\n```bash\ngit init --object-format=sha256 repro\ncd repro\ngit config user.email t@e.com && git config user.name T\ngit commit --allow-empty -m init\ncat > .pre-commit-config.yaml \u003c\u003c'EOF'\nrepos:\n - repo: https://github.com/pre-commit/pre-commit-hooks\n rev: v5.0.0\n hooks:\n - id: trailing-whitespace\nEOF\ngit add .pre-commit-config.yaml && git commit -m \"pc\"\npre-commit install --hook-type pre-push\n\ngit checkout -b doomed\ngit commit --allow-empty -m x\nSHA=$(git rev-parse HEAD)\nZEROS=$(printf '0%.0s' $(seq 1 64))\n\n# Feed git's pre-push stdin format directly — simulates `git push origin --delete doomed`\nprintf '(delete) %s refs/heads/doomed %s\\n' \"$ZEROS\" \"$SHA\" | .git/hooks/pre-push origin .\n# exit code 3, error above\n```\n\nSuggested fix: accept an all-zero OID of either supported length (40 or 64), or (more general) read the repo's zero OID at runtime. A one-liner that covers both currently-supported object formats:\n\n```python\ndef _is_zero_oid(oid: str) -> bool:\n return len(oid) in (40, 64) and set(oid) == {'0'}\n```\n\nCallers become `if _is_zero_oid(local_sha): continue` and `elif not _is_zero_oid(remote_sha) and _rev_exists(remote_sha):`. A strictly hash-agnostic alternative reads `git rev-parse --show-object-format` once per hook invocation and computes the zero string from it.\n\nHappy to open a PR if helpful.\n\n### pre-commit --version\n\npre-commit 4.5.1 (reproduced); `Z40 = '0' * 40` is still on line 14 of `hook_impl.py` on current `main` (f35134b) and in the 4.6.0 tag, so the bug is present on both.\n\n### .pre-commit-config.yaml\n\n```yaml\nrepos:\n - repo: https://github.com/pre-commit/pre-commit-hooks\n rev: v5.0.0\n hooks:\n - id: trailing-whitespace\n```\n\n### ~/.cache/pre-commit/pre-commit.log (if present)\n\n```\n### version information\n\npre-commit version: 4.5.1\ngit --version: git version 2.47.3\nsys.version:\n 3.12.12 (main, Jan 16 2026, 00:00:00) [GCC 14.3.1 20250617 (Red Hat 14.3.1-2)]\nsys.executable: /home/rlichten/.local/share/uv/tools/pre-commit/bin/python\nos.name: posix\nsys.platform: linux\n\n### error information\n\nAn unexpected error has occurred: CalledProcessError: command: ('/usr/bin/git', 'diff', '--name-only', '--no-ext-diff', '-z', '\u003csha>..\u003c64-zeros>')\nreturn code: 128\nstdout: (none)\nstderr:\n fatal: Invalid revision range \u003csha>..\u003c64-zeros>\n\nTraceback (most recent call last):\n File \".../pre_commit/git.py\", line 161, in get_changed_files\n _, out, _ = cmd_output(*diff_cmd, f'{old}...{new}')\n ...\npre_commit.util.CalledProcessError: command: ('/usr/bin/git', 'diff', '--name-only', '--no-ext-diff', '-z', '\u003csha>...\u003c64-zeros>')\nreturn code: 128\nstderr:\n fatal: Invalid symmetric difference expression \u003csha>...\u003c64-zeros>\n```\n","author":{"url":"https://github.com/rlichtenwalter","@type":"Person","name":"rlichtenwalter"},"datePublished":"2026-04-24T00:45:23Z","url":"https://github.com/pre-commit/pre-commit/issues/3664"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fc11124f-4159-9df6-2d1b-7fce5fcdc488 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CFAA:259026:13249FE:1967CCB:6B06625F |
| html-safe-nonce | fdc4f078799a791640f00049a2b82e0523f7362546346bb9dce05c307e2f4b9c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRkFBOjI1OTAyNjoxMzI0OUZFOjE5NjdDQ0I6NkIwNjYyNUYiLCJ2aXNpdG9yX2lkIjoiMzU0MzQ2NTk2MDc5NzUyODY3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5a08f3fc3efa720ceda0fcb0270834cbff7bbbc3597f9a3e8c04ee6e8b19a65a |
| hovercard-subject-tag | issue:4319718427 |
| github-keyboard-shortcuts | repository,issues,commits,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pre-commit/pre-commit/3664/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53c4d0f5b2910eb766c41c491cff3132c9430620390a92bd55744b54a5e3c4e2/pre-commit/pre-commit/issues/3664 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53c4d0f5b2910eb766c41c491cff3132c9430620390a92bd55744b54a5e3c4e2/pre-commit/pre-commit/issues/3664 |
| og:image:alt | search you tried in the issue tracker sha256, SHA-256 push, sha-256 delete, Z40, object-format sha256, "Invalid revision range", "bad object", zero SHA, pre-push delete, deletion push The closest r... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rlichtenwalter |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6324e6ac990fb6befbec840cc0e102a1071c339bfe8f9826bb12de2e3ba1d297 |
| turbo-cache-control | no-preview |
| go-import | github.com/pre-commit/pre-commit git https://github.com/pre-commit/pre-commit.git |
| octolytics-dimension-user_id | 6943086 |
| octolytics-dimension-user_login | pre-commit |
| octolytics-dimension-repository_id | 17689377 |
| octolytics-dimension-repository_nwo | pre-commit/pre-commit |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 17689377 |
| octolytics-dimension-repository_network_root_nwo | pre-commit/pre-commit |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7f0aa75f4141d440c6110dc31af7ea7797abb6c4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width