fix(windows): refresh terminal environment from registry on launch - #2605
Open
weiningwei wants to merge 2 commits into
Open
fix(windows): refresh terminal environment from registry on launch#2605weiningwei wants to merge 2 commits into
weiningwei wants to merge 2 commits into
Conversation
Signed-off-by: weiningwei <weiningwei09@gmail.com>
Signed-off-by: weiningwei <weiningwei09@gmail.com>
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.
Problem
When SourceGit is running and the user installs new CLI tools (Node.js, Python, Rust, etc.) or modifies system/user environment variables, clicking "Open in Terminal" opens a terminal with the stale environment snapshot from when SourceGit was started. The new PATH entries are missing, so commands from newly installed tools are not found.
This affects all Windows terminal types: cmd, pwsh, git-bash, and Windows Terminal.
Root Cause
Process.Startwith defaultUseShellExecute = falseusesCreateProcess, which inherits the parent process's Environment Block — the snapshot from SourceGit's startup time.UseShellExecute = truealso does not solve this, asShellExecuteExwith NULLlpEnvironmentalso inherits the parent environment.Solution
Add
RefreshEnvFromRegistrymethod that re-reads the latest environment from the Windows registry each time "Open in Terminal" is clicked, and sets a customProcessStartInfo.Environmentfor the child process.Algorithm
HKLM\...\Environment)HKCU\Environment) — overrides Machine, PATH is appended not replaced