Title: `npm install git+file://` during hook install inside a submodule overwrites the submodule's index · Issue #3773 · pre-commit/pre-commit · GitHub
Open Graph Title: `npm install git+file://` during hook install inside a submodule overwrites the submodule's index · Issue #3773 · pre-commit/pre-commit
X Title: `npm install git+file://` during hook install inside a submodule overwrites the submodule's index · Issue #3773 · pre-commit/pre-commit
Description: search you tried in the issue tracker GIT_INDEX_FILE, GIT_DIR, no_git_env, submodule, "unable to read", "invalid object", git+file, npm git describe your issue Since 4.6.1, when a language: node hook environment is installed by git commi...
Open Graph Description: search you tried in the issue tracker GIT_INDEX_FILE, GIT_DIR, no_git_env, submodule, "unable to read", "invalid object", git+file, npm git describe your issue Since 4.6.1, when a language: node ho...
X Description: search you tried in the issue tracker GIT_INDEX_FILE, GIT_DIR, no_git_env, submodule, "unable to read", "invalid object", git+file, npm git describe your issue Since 4.6.1, when...
Opengraph URL: https://github.com/pre-commit/pre-commit/issues/3773
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`npm install git+file://` during hook install inside a submodule overwrites the submodule's index","articleBody":"### search you tried in the issue tracker\n\nGIT_INDEX_FILE, GIT_DIR, no_git_env, submodule, \"unable to read\", \"invalid object\", git+file, npm git\n\n### describe your issue\n\nSince 4.6.1, when a `language: node` hook environment is installed by `git commit` run inside a git submodule, the submodule's index is replaced with the index of the hook repository. The commit fails and whatever was staged is lost. 4.6.0 is not affected: the reproduction below passes on 4.6.0 and on ff8541f, and fails on b1cc920 (#3719), 4.6.1 and 4.6.2.\n\nInside a submodule, git runs the pre-commit hook with absolute `GIT_DIR` and `GIT_INDEX_FILE` (`\u003csuper>/.git/modules/\u003cname>` and `\u003csuper>/.git/modules/\u003cname>/index`). #3719 changed the install to `npm install ... git+file://\u003cstore clone>`, and npm clones and checks out that URL with git. That `git` inherits `GIT_INDEX_FILE`, so the checkout writes the hook repository's index to the submodule's index file. `store.py` already runs the initial clone of the hook repository with `no_git_env()`. The npm install does not.\n\nConfirm the issue on 4.6.2 using this Dockerfile:\n\n```dockerfile\nFROM python:3.13\n\nARG PRE_COMMIT=pre-commit==4.6.2\n\nRUN pip install \"${PRE_COMMIT}\"\nRUN git config --global user.name repro \\\n && git config --global user.email repro@example.com \\\n && git config --global protocol.file.allow always\n\nWORKDIR /repro\n\nCOPY \u003c\u003c'EOF' repro.sh\nset -eu\npre-commit --version\n\ngit init -q sub\ncd sub\n\ncat > .pre-commit-config.yaml \u003c\u003c'YAML'\nrepos:\n - repo: https://github.com/rbubley/mirrors-prettier\n rev: v3.6.2\n hooks:\n - id: prettier\nYAML\n\ngit add .pre-commit-config.yaml\ngit commit -q -m init\ncd ..\n\ngit init -q super\ncd super\n\ngit submodule -q add ../sub sub\ngit commit -q -m 'add submodule'\n\ncd sub\npre-commit install\n\necho '# hello' > README.md\ngit add README.md\ngit commit -m 'trigger install from inside a submodule' || true\n\necho '--- submodule index (expected: .pre-commit-config.yaml, README.md)'\ngit ls-files -s\ncat ~/.cache/pre-commit/pre-commit.log 2>/dev/null || true\nEOF\n\nCMD [\"bash\", \"repro.sh\"]\n```\n\n```bash\ndocker build -t pre-commit-submodule-repro .\ndocker run --rm pre-commit-submodule-repro\n```\n\noutput of `docker run` (the `pre-commit.log` it prints at the end is in the log field below):\n\n```\npre-commit 4.6.2\npre-commit installed at /repro/super/.git/modules/sub/hooks/pre-commit\n[INFO] Initializing environment for https://github.com/rbubley/mirrors-prettier.\n[INFO] Initializing environment for https://github.com/rbubley/mirrors-prettier:prettier@3.6.2.\n[INFO] Installing environment for https://github.com/rbubley/mirrors-prettier.\n[INFO] Once installed this environment will be reused.\n[INFO] This may take a few minutes...\nAn unexpected error has occurred: CalledProcessError: command: ('/usr/lib/git-core/git', 'diff', '--staged', '--name-only', '--no-ext-diff', '-z', '--diff-filter=ACMRTUXB')\nreturn code: 128\nstdout: (none)\nstderr:\n fatal: unable to read 7192ee1c223039c8ac42c8871ec7f6f8faeedebd\nCheck the log at /root/.cache/pre-commit/pre-commit.log\n--- submodule index (expected: .pre-commit-config.yaml, README.md)\n100644 7192ee1c223039c8ac42c8871ec7f6f8faeedebd 0\t.github/workflows/main.yml\n100644 72e8ffc0db8aad71a934dd11e5968bd5109e54b4 0\t.npmignore\n100644 a7d109de0c111bd5b225d20183593b283ad80516 0\t.pre-commit-hooks.yaml\n100644 b72762837ea636398fece3c5651f664c2ee82ffb 0\t.version\n100644 d86d9ea06347dbd79c04079484155ea94fa2c3ed 0\tLICENSE\n100644 92a483e6ca5ae20de5bae985aa1215eb658c6498 0\tREADME.md\n100644 d4083c5b452e10dc41112eae1813d9d1631024b5 0\tpackage.json\n```\n\nThe submodule's index now holds the files of `mirrors-prettier`. `git read-tree HEAD` in the submodule recovers it.\n\nConfirm 4.6.0 is not affected:\n\n```bash\ndocker build --build-arg PRE_COMMIT=pre-commit==4.6.0 -t pre-commit-submodule-repro:4.6.0 .\ndocker run --rm pre-commit-submodule-repro:4.6.0\n```\n\nWorkaround: run `pre-commit install-hooks` from a shell before committing.\n\nThe closest related issues I found is #1379 which has the same `fatal: unable to read \u003csha>` after a fresh install; the cause was never found for this one.\n\n### pre-commit --version\n\npre-commit 4.6.2\n\n### .pre-commit-config.yaml\n\n```yaml\nrepos:\n - repo: https://github.com/rbubley/mirrors-prettier\n rev: v3.6.2\n hooks:\n - id: prettier\n```\n\n### ~/.cache/pre-commit/pre-commit.log (if present)\n\n### version information\n\n```\npre-commit version: 4.6.2\ngit --version: git version 2.47.3\nsys.version:\n 3.13.16 (main, Oct 6 2026, 04:43:07) [GCC 14.2.0]\nsys.executable: /usr/local/bin/python3.13\nos.name: posix\nsys.platform: linux\n```\n\n### error information\n\n```\nAn unexpected error has occurred: CalledProcessError: command: ('/usr/lib/git-core/git', 'diff', '--staged', '--name-only', '--no-ext-diff', '-z', '--diff-filter=ACMRTUXB')\nreturn code: 128\nstdout: (none)\nstderr:\n fatal: unable to read 7192ee1c223039c8ac42c8871ec7f6f8faeedebd\n```\n\n```\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/error_handler.py\", line 73, in error_handler\n yield\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/main.py\", line 401, in main\n return hook_impl(\n store,\n ...\u003c5 lines>...\n args=args.rest[1:],\n )\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/commands/hook_impl.py\", line 275, in hook_impl\n return retv | run(config, store, ns)\n ~~~^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/commands/run.py\", line 445, in run\n return _run_hooks(config, hooks, skips, args)\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/commands/run.py\", line 291, in _run_hooks\n _all_filenames(args), config['files'], config['exclude'],\n ~~~~~~~~~~~~~~^^^^^^\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/commands/run.py\", line 271, in _all_filenames\n return git.get_staged_files()\n ~~~~~~~~~~~~~~~~~~~~^^\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/git.py\", line 137, in get_staged_files\n cmd_output(\n ~~~~~~~~~~^\n 'git', 'diff', '--staged', '--name-only', '--no-ext-diff', '-z',\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n ...\u003c2 lines>...\n cwd=cwd,\n ^^^^^^^^\n )[1],\n ^\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/util.py\", line 117, in cmd_output\n returncode, stdout_b, stderr_b = cmd_output_b(*cmd, **kwargs)\n ~~~~~~~~~~~~^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.13/site-packages/pre_commit/util.py\", line 111, in cmd_output_b\n raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)\npre_commit.util.CalledProcessError: command: ('/usr/lib/git-core/git', 'diff', '--staged', '--name-only', '--no-ext-diff', '-z', '--diff-filter=ACMRTUXB')\nreturn code: 128\nstdout: (none)\nstderr:\n fatal: unable to read 7192ee1c223039c8ac42c8871ec7f6f8faeedebd\n```\n","author":{"url":"https://github.com/cbirkhold","@type":"Person","name":"cbirkhold"},"datePublished":"2026-10-09T06:31:00Z","url":"https://github.com/pre-commit/pre-commit/issues/3773"}
| 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:45b9dc29-b75b-d615-4439-971fcd3ab93c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CD48:CE438:1016349:1585B87:6B01F06F |
| html-safe-nonce | 73efdab473cca52a035e47c190a044a76e9a8a93e6f4e48ac2fb5d8b1b6a5d82 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDQ4OkNFNDM4OjEwMTYzNDk6MTU4NUI4Nzo2QjAxRjA2RiIsInZpc2l0b3JfaWQiOiI4MDYwODcwNzY4NDAzMjc5OTgzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 0e00f5c2a23ee4733ba2f9070a3658eab78abed99df3b75381cd7f35686c31fa |
| hovercard-subject-tag | issue:5773890135 |
| 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/3773/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7d0a1f707071a5d5508a6f6d2386cdc7e0f3a8253119eb24ac6365fa4e942f16/pre-commit/pre-commit/issues/3773 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7d0a1f707071a5d5508a6f6d2386cdc7e0f3a8253119eb24ac6365fa4e942f16/pre-commit/pre-commit/issues/3773 |
| og:image:alt | search you tried in the issue tracker GIT_INDEX_FILE, GIT_DIR, no_git_env, submodule, "unable to read", "invalid object", git+file, npm git describe your issue Since 4.6.1, when a language: node ho... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cbirkhold |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width