fix(windows): prevent _update_cwd() from overwriting self.cwd with Git Bash POSIX path#16628
Closed
hypen-o wants to merge 1 commit into
Closed
fix(windows): prevent _update_cwd() from overwriting self.cwd with Git Bash POSIX path#16628hypen-o wants to merge 1 commit into
hypen-o wants to merge 1 commit into
Conversation
…t Bash POSIX path LocalEnvironment._update_cwd() reads the cwd from a temp file written by Git Bash's pwd -P command. Git Bash always outputs POSIX-style paths (e.g. /d/djh/hermes), which are invalid for subprocess.Popen(cwd=...) on Windows, causing WinError 267 on all subsequent terminal commands. Guard _update_cwd() on Windows so the cwd file read cannot overwrite the already-correct self.cwd. The marker stripping (_extract_cwd_from_output) still runs to keep output clean, but self.cwd is restored afterward. The _IS_WINDOWS variable was already defined at module level and used throughout the file in _find_bash(), _kill_process(), and _run_bash(). Ref: NousResearch#14644
Contributor
|
Thanks for the contribution @hypen-o! The Windows / Git Bash POSIX-path issue is real and worth fixing, but the diff is 417/-408 across one file — that's CRLF line-ending noise from saving the file with Windows line endings. Could you resubmit with LF line endings? Set |
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.
Fixes the WinError 267 "The directory name is invalid" error on Windows/Git Bash
terminal.backend: local.Root Cause
LocalEnvironment._update_cwd()(local.py:390) reads the cwd from a temp file written by Git Bash'spwd -Pcommand. Git Bash always outputs POSIX-style paths (e.g./c/Users/user/project), which are invalid forsubprocess.Popen(cwd=...)on Windows.The failure sequence:
TERMINAL_CWDoros.getcwd()setsself.cwdto a valid Windows path (e.g.D:\project)_update_cwd()reads_cwd_file(which contains the POSIX path from Git Bash'spwd -P)self.cwdwith/c/Users/user/project(POSIX format)subprocess.Popen(cwd=self.cwd)-> WinError 267 (The directory name is invalid)This affects all Windows users with
terminal.backend: localusing native Git Bash without WSL2. The initial cwd from TERMINAL_CWD is correct but gets immediately overwritten by the POSIX path from_update_cwd().Fix
Guard
_update_cwd()on Windows so the cwd file read (which always contains POSIX paths from Git Bash) cannot overwrite the already-correctself.cwd. The marker stripping (_extract_cwd_from_output()) still runs to keep output clean, butself.cwdis restored to its saved value afterward.The
_IS_WINDOWSvariable is already defined at module level and used throughout the file in_find_bash(),_kill_process(), and_run_bash().No non-Windows code paths are touched.
Relationship to existing work
Commit
4c136288("fix(local): respect configured cwd in init_session()") addedcwd=self.cwdtosubprocess.Popen(), which correctly fixes theinit_session()startup directory. This PR complements it by also protecting against_update_cwd()overwritingself.cwdon subsequent commands after the first one succeeds.PR fix(windows): native Git Bash terminal — exit 126 with empty output #14644 addresses the broader "exit 126 with empty output" issue on Windows (select.select, get_temp_dir, path conversion). This PR takes a simpler, complementary approach focused solely on the POSIX path overwrite in
_update_cwd().Tested
On Windows 11 + Git for Windows 2.42.0:
echo hello->{output: "hello", exit_code: 0}pwd->{output: "/c/Users/user/project", exit_code: 0}(POSIX visible to user, but self.cwd stays valid for subsequent Popen)cd /tmp && pwd-> cwd persists correctlyTERMINAL_CWD=D:\projectin .env preserved across all commandsRef: #14644