fix(terminal): normalize Windows cwd for Git Bash bootstrap - #42105
Closed
kingshukkundu wants to merge 2 commits into
Closed
kingshukkundu wants to merge 2 commits into
kingshukkundu wants to merge 2 commits into
Conversation
… bash On Windows, Python's os.getcwd() returns native paths (C:\Users\x) but Git Bash requires MSYS-style POSIX paths (/c/Users/x). The existing _msys_to_windows_path handled the reverse direction only, causing every bash command to fail on the initial 'builtin cd' with: /bin/bash: line 2: cd: C:\Users\<user>: No such file or directory Add _windows_to_msys_path() as the inverse converter and override _normalize_cwd_for_cd() in LocalEnvironment to apply it before passing CWD into bash scripts. Mirrors the existing pattern where base.py provides a no-op hook that subclasses override for platform-specific behaviour.
tonydwb
approved these changes
Jun 9, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Looks Good
- Fixes Git Bash bootstrap on Windows: paths with spaces (e.g.
C:\Users\Some Name\project) are now properly converted to MSYS-style POSIX paths (/c/Users/Some Name/project) before being passed tobuiltin cd. - Handles both regular Windows paths and UNC paths (
\\server\share\folder). _normalize_cwd_for_cdoverride inLocalEnvironmentfor Windows-specific path translation.- No security concerns, no debug artifacts.
Reviewed by Hermes Agent
Collaborator
|
Superseded by PR #56384, which fixes this at the root: it reorders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a Windows terminal bootstrap bug where Hermes stores native cwd values like
C:\Users\Kingshukand injects them directly into Git Bashcdcommands. Git Bash expects MSYS-style paths like/c/Users/Kingshuk, so session bootstrap and wrapped commands can fail before the terminal is usable.This keeps
self.cwdin native OS format for Python-side filesystem handling and converts only at the bash boundary.LocalEnvironmentnormalizes Windows and UNC paths forcd, andBaseEnvironment.init_session()now routes bootstrap cwd handling through the same quoting and normalization helper used for wrapped commands.This complements #23866, which focuses on MSYS-to-Windows normalization for paths coming back from bash. This PR fixes the opposite direction: native Windows cwd values going into bash.
Related Issue
N/A
Type of Change
Changes Made
BaseEnvironment.init_session()cwd handling through_quote_cwd_for_cd_normalize_cwd_for_cd()intools/environments/base.py_windows_to_msys_path()andLocalEnvironment._normalize_cwd_for_cd()intools/environments/local.pytests/tools/test_windows_native_support.pyHow to Test
C:\Users\Kingshuk.pwd.cd: C:\Users\Kingshuk: No such file or directory.Checklist
Code
pytest tests/ -qand all tests passDocumentation & Housekeeping
LocalEnvironmentand preserves existing behavior elsewhereScreenshots / Logs
C:\Users\Some Name\project->'/c/Users/Some Name/project'\\server\share\folder->//server/share/folderpytestwas not available in the system Python used for this local checkout