René's URL Explorer Experiment


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

direct link

Domain: github.com

IPv4 address: 140.82.113.3


Hey, it has json ld scripts:
{"@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-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:fc11124f-4159-9df6-2d1b-7fce5fcdc488
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCFAA:259026:13249FE:1967CCB:6B06625F
html-safe-noncefdc4f078799a791640f00049a2b82e0523f7362546346bb9dce05c307e2f4b9c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRkFBOjI1OTAyNjoxMzI0OUZFOjE5NjdDQ0I6NkIwNjYyNUYiLCJ2aXNpdG9yX2lkIjoiMzU0MzQ2NTk2MDc5NzUyODY3MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac5a08f3fc3efa720ceda0fcb0270834cbff7bbbc3597f9a3e8c04ee6e8b19a65a
hovercard-subject-tagissue:4319718427
github-keyboard-shortcutsrepository,issues,commits,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pre-commit/pre-commit/3664/issue_layout
twitter:imagehttps://opengraph.githubassets.com/53c4d0f5b2910eb766c41c491cff3132c9430620390a92bd55744b54a5e3c4e2/pre-commit/pre-commit/issues/3664
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/53c4d0f5b2910eb766c41c491cff3132c9430620390a92bd55744b54a5e3c4e2/pre-commit/pre-commit/issues/3664
og:image:altsearch 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerlichtenwalter
hostnamegithub.com
expected-hostnamegithub.com
None6324e6ac990fb6befbec840cc0e102a1071c339bfe8f9826bb12de2e3ba1d297
turbo-cache-controlno-preview
go-importgithub.com/pre-commit/pre-commit git https://github.com/pre-commit/pre-commit.git
octolytics-dimension-user_id6943086
octolytics-dimension-user_loginpre-commit
octolytics-dimension-repository_id17689377
octolytics-dimension-repository_nwopre-commit/pre-commit
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id17689377
octolytics-dimension-repository_network_root_nwopre-commit/pre-commit
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7f0aa75f4141d440c6110dc31af7ea7797abb6c4
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/pre-commit/pre-commit/issues/3664#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpre-commit%2Fpre-commit%2Fissues%2F3664
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpre-commit%2Fpre-commit%2Fissues%2F3664
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=pre-commit%2Fpre-commit
Reloadhttps://github.com/pre-commit/pre-commit/issues/3664
Reloadhttps://github.com/pre-commit/pre-commit/issues/3664
Reloadhttps://github.com/pre-commit/pre-commit/issues/3664
pre-commithttps://github.com/pre-commit
pre-commithttps://github.com/pre-commit/pre-commit
Codehttps://github.com/pre-commit/pre-commit
Issues17 (17)https://github.com/pre-commit/pre-commit/issues
Pull requests8 (8)https://github.com/pre-commit/pre-commit/pulls
Actionshttps://github.com/pre-commit/pre-commit/actions
Security and qualityhttps://github.com/pre-commit/pre-commit/security
Insightshttps://github.com/pre-commit/pre-commit/insights
https://github.com/pre-commit/pre-commit
New issuehttps://github.com/login?return_to=https://github.com/pre-commit/pre-commit/issues/3664
New issuehttps://github.com/login?return_to=https://github.com/pre-commit/pre-commit/issues/3664
Dmao233/pre-commit#1https://github.com/Dmao233/pre-commit/pull/1
Z40 = '0' * 40 hardcoding breaks git push --delete on SHA-256 reposhttps://github.com/pre-commit/pre-commit/issues/3664#top
Dmao233/pre-commit#1https://github.com/Dmao233/pre-commit/pull/1
https://github.com/rlichtenwalter
rlichtenwalterhttps://github.com/rlichtenwalter
on Apr 24, 2026https://github.com/pre-commit/pre-commit/issues/3664#issue-4319718427
#3434https://github.com/pre-commit/pre-commit/issues/3434
f35134bhttps://github.com/pre-commit/pre-commit/commit/f35134b05028ec938ac605ae500fdf95462655d3
https://github.com/toby-bridges
toby-bridgeshttps://github.com/toby-bridges
on May 18, 2026https://github.com/pre-commit/pre-commit/issues/3664#issuecomment-4482098967
https://github.com/asottile
asottilehttps://github.com/asottile
on May 18, 2026https://github.com/pre-commit/pre-commit/issues/3664#issuecomment-4482124494
pre-commithttps://github.com/pre-commit
toby-bridgeshttps://github.com/toby-bridges
on May 18, 2026https://github.com/pre-commit/pre-commit/issues/3664#event-25677187889
https://github.com/Gambit-Checkmate
Gambit-Checkmatehttps://github.com/Gambit-Checkmate
on Aug 22, 2026https://github.com/pre-commit/pre-commit/issues/3664#issuecomment-5380776154
Sign up for freehttps://github.com/signup?return_to=https://github.com/pre-commit/pre-commit/issues/3664
Sign in to commenthttps://github.com/login?return_to=https://github.com/pre-commit/pre-commit/issues/3664
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.