Title: run_commit_hook picks the WSL launcher stub on Windows: bare bash.exe resolves from System32 before PATH · Issue #2198 · gitpython-developers/GitPython · GitHub
Open Graph Title: run_commit_hook picks the WSL launcher stub on Windows: bare bash.exe resolves from System32 before PATH · Issue #2198 · gitpython-developers/GitPython
X Title: run_commit_hook picks the WSL launcher stub on Windows: bare bash.exe resolves from System32 before PATH · Issue #2198 · gitpython-developers/GitPython
Description: Summary On Windows, run_commit_hook spawns extensionless hooks as a bare "bash.exe" and leaves the executable lookup to Windows. CreateProcess resolves a bare name in this order: application dir -> parent cwd -> System32 -> Windows dir -...
Open Graph Description: Summary On Windows, run_commit_hook spawns extensionless hooks as a bare "bash.exe" and leaves the executable lookup to Windows. CreateProcess resolves a bare name in this order: application dir ->...
X Description: Summary On Windows, run_commit_hook spawns extensionless hooks as a bare "bash.exe" and leaves the executable lookup to Windows. CreateProcess resolves a bare name in this order: applicat...
Opengraph URL: https://github.com/gitpython-developers/GitPython/issues/2198
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"run_commit_hook picks the WSL launcher stub on Windows: bare bash.exe resolves from System32 before PATH","articleBody":"### Summary\n\nOn Windows, `run_commit_hook` spawns extensionless hooks as a **bare** `\"bash.exe\"` and leaves the executable lookup to Windows. `CreateProcess` resolves a bare name in this order:\n\n```\napplication dir -> parent cwd -> System32 -> Windows dir -> PATH\n```\n\nso `C:\\Windows\\System32\\bash.exe` — the **WSL launcher stub**, present on any machine where the \"Windows Subsystem for Linux\" optional feature has been enabled — is found at **step 3, before PATH is ever consulted**.\n\nIf no WSL distro is installed, that stub prints and exits 1:\n\n```\nWindows Subsystem for Linux has no installed distributions.\nYou can resolve this by installing a distribution with the instructions below:\n\nUse 'wsl.exe --list --online' to list available distributions\nand 'wsl.exe --install \u003cDistro>' to install.\n```\n\nGitPython surfaces this as `HookExecutionError`, so **every** `repo.index.commit()` fails on such a machine and the hook body never runs — regardless of what the hook contains.\n\n### Version\n\n- GitPython 3.1.46 (reproduced), and current `main` still builds `cmd = [\"bash.exe\", ...]`\n- Windows 11, Git for Windows 2.x, WSL optional feature enabled with **no** distro installed\n\n### Reproduction\n\n```python\nfrom pathlib import Path\nimport git\n\nrepo = git.Repo.init(\"scratch\")\nhook = Path(\"scratch/.git/hooks/pre-commit\")\nhook.write_text(\"#!/bin/sh\\necho HOOK RAN\\nexit 0\\n\", newline=\"\\n\")\nhook.chmod(0o755)\n\nPath(\"scratch/f.txt\").write_text(\"x\\n\")\nrepo.index.add([\"f.txt\"])\nrepo.index.commit(\"test\") # HookExecutionError on a machine with the WSL stub\n```\n\n`git commit` from Git Bash on the same repo runs the hook fine, which makes this look like a hook or repo problem rather than a library one.\n\n### Why the usual workarounds don't apply\n\n| Workaround | Why it cannot help |\n|---|---|\n| Put `C:\\Program Files\\Git\\bin` on PATH | PATH is consulted only *after* System32 |\n| Give the hook an absolute-path shebang | `run_commit_hook` never reads the shebang |\n| Reorder PATH ahead of System32 | Irrelevant — System32 is searched before PATH regardless of PATH contents |\n\nThe only thing that changes the outcome is naming the interpreter by absolute path.\n\n### Note on the current comment in the source\n\nThe relative-path calculation carries this comment:\n\n> Different drives have no relative path on Windows. Git Bash accepts an absolute path in this form, although a relative path is preferable because it also works with the Windows Subsystem for Linux wrapper.\n\nThat reads as though WSL bash is an acceptable target. When WSL is a stub with no distro it is not merely acceptable-but-different, it is guaranteed to fail — and because of the `CreateProcess` search order it is the one that gets selected by default, ahead of Git's own bash.\n\n### Suggested fix\n\nResolve Git for Windows' `bash.exe` by absolute path and use it explicitly, rejecting any candidate under `%SystemRoot%`. Candidate order that works well in practice:\n\n1. the `bin/` directory beside the `git.exe` already on PATH (`shutil.which(\"git\")` → `../bin/bash.exe`)\n2. `GIT_INSTALL_ROOT`\n3. standard install locations (`C:\\Program Files\\Git`, `C:\\Program Files (x86)\\Git`)\n\nFalling back to today's bare `\"bash.exe\"` when none is found would keep behavior unchanged for anyone currently relying on WSL bash.\n\nI am working around it downstream by patching the single `safer_popen` call site in `git/index/fun.py` to rewrite a bare `bash.exe` / `sh.exe` argv[0] to Git's absolute bash. Happy to open a PR against `run_commit_hook` if the approach above looks acceptable.\n\n### Possibly related\n\n- #1999 (closed, not planned) — a different failure in the same Windows hook path\n- #971 / #1129 — the `WinError 193` reports that motivated b719e18, the commit that introduced the `bash.exe` spawn\n","author":{"url":"https://github.com/piyushmakhija28","@type":"Person","name":"piyushmakhija28"},"datePublished":"2026-07-30T09:54:36Z","url":"https://github.com/gitpython-developers/GitPython/issues/2198"}
| 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:cef1e2ee-877b-67f6-7bcb-bce0cbb5855e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC5A:1EC9BC:C83D39:10049B6:6B0100BA |
| html-safe-nonce | 35a9d672ad1cb19c61caa8cf9234412e2c0c83ba2f5235a87b88e50bf3850266 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzVBOjFFQzlCQzpDODNEMzk6MTAwNDlCNjo2QjAxMDBCQSIsInZpc2l0b3JfaWQiOiIzODYxMDQ4NzQwNDUwMjA1ODgyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cef8ffabf4e691a3738bd8970f084d96f91931d0aa4a3f1ad4a3f50dcddb5b5e |
| hovercard-subject-tag | issue:5018487192 |
| github-keyboard-shortcuts | repository,issues,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/gitpython-developers/GitPython/2198/issue_layout |
| twitter:image | https://opengraph.githubassets.com/73e93809b0b682d6ae04f2c4ebf84e6af7c7134c8e03721331fefe27c204821d/gitpython-developers/GitPython/issues/2198 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/73e93809b0b682d6ae04f2c4ebf84e6af7c7134c8e03721331fefe27c204821d/gitpython-developers/GitPython/issues/2198 |
| og:image:alt | Summary On Windows, run_commit_hook spawns extensionless hooks as a bare "bash.exe" and leaves the executable lookup to Windows. CreateProcess resolves a bare name in this order: application dir ->... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | piyushmakhija28 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| 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 | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width