Skip to content

Commit e135430

Browse files
committed
git: fix crash when reading stderr from non-redirected processes
ProcessManager.CreateProcess sets RedirectStandardError=false for all processes to avoid TRACE2 deadlocks. However, GetRemotes and CreateGitException unconditionally read StandardError, which throws InvalidOperationException when stderr is not redirected. Fix GetRemotes by explicitly redirecting stderr before starting the process, since it needs to check for 'not a git repository' errors. Guard CreateGitException defensively, as it is called from various contexts where stderr may or may not be redirected. Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
1 parent 4d6cf6e commit e135430

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/shared/Core/Git.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ public IEnumerable<GitRemote> GetRemotes()
174174
{
175175
using (var git = CreateProcess("remote -v show"))
176176
{
177+
// Redirect stderr so we can check for 'not a git repository' errors
178+
git.StartInfo.RedirectStandardError = true;
177179
git.Start(Trace2ProcessClass.Git);
178180
// To avoid deadlocks, always read the output stream first and then wait
179181
// TODO: don't read in all the data at once; stream it
@@ -274,7 +276,9 @@ public async Task<IDictionary<string, string>> InvokeHelperAsync(string args, ID
274276

275277
public static GitException CreateGitException(ChildProcess git, string message, ITrace2 trace2 = null)
276278
{
277-
var gitMessage = git.StandardError.ReadToEnd();
279+
var gitMessage = git.StartInfo.RedirectStandardError
280+
? git.StandardError.ReadToEnd()
281+
: null;
278282

279283
if (trace2 != null)
280284
throw new Trace2GitException(trace2, message, git.ExitCode, gitMessage);

0 commit comments

Comments
 (0)