Skip to content

Commit c12409f

Browse files
authored
Ensure we create a WindowsProcessManager on Windows (#1146)
We are creating a `WindowsProcessManager` implementation on macOS and a non-Windows/WSL aware, plain `ProcessManager` on Windows - this is the reverse of what we should do. Fix this.
2 parents f7c9fd0 + d1b64cc commit c12409f

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/shared/Core/CommandContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public CommandContext()
104104
FileSystem = new WindowsFileSystem();
105105
SessionManager = new WindowsSessionManager();
106106
Environment = new WindowsEnvironment(FileSystem);
107-
ProcessManager = new ProcessManager(Trace2);
107+
ProcessManager = new WindowsProcessManager(Trace2);
108108
Terminal = new WindowsTerminal(Trace);
109109
string gitPath = GetGitPath(Environment, FileSystem, Trace);
110110
Git = new GitProcess(
@@ -120,7 +120,7 @@ public CommandContext()
120120
FileSystem = new MacOSFileSystem();
121121
SessionManager = new MacOSSessionManager();
122122
Environment = new MacOSEnvironment(FileSystem);
123-
ProcessManager = new WindowsProcessManager(Trace2);
123+
ProcessManager = new ProcessManager(Trace2);
124124
Terminal = new MacOSTerminal(Trace);
125125
string gitPath = GetGitPath(Environment, FileSystem, Trace);
126126
Git = new GitProcess(

src/shared/Core/Interop/Windows/WindowsProcessManager.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
using System.Diagnostics;
2-
31
namespace GitCredentialManager.Interop.Windows;
42

53
public class WindowsProcessManager : ProcessManager
64
{
7-
private readonly ITrace2 _trace2;
8-
95
public WindowsProcessManager(ITrace2 trace2) : base(trace2)
106
{
11-
_trace2 = trace2;
7+
PlatformUtils.EnsureWindows();
128
}
139

1410
public override ChildProcess CreateProcess(string path, string args, bool useShellExecute, string workingDirectory)
@@ -17,7 +13,7 @@ public override ChildProcess CreateProcess(string path, string args, bool useShe
1713
if (!useShellExecute && WslUtils.IsWslPath(path))
1814
{
1915
string wslPath = WslUtils.ConvertToDistroPath(path, out string distro);
20-
return WslUtils.CreateWslProcess(distro, $"{wslPath} {args}", _trace2, workingDirectory);
16+
return WslUtils.CreateWslProcess(distro, $"{wslPath} {args}", Trace2, workingDirectory);
2117
}
2218

2319
return base.CreateProcess(path, args, useShellExecute, workingDirectory);

src/shared/Core/ProcessManager.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ public interface IProcessManager
2727

2828
public class ProcessManager : IProcessManager
2929
{
30-
private readonly ITrace2 _trace2;
30+
protected readonly ITrace2 Trace2;
3131

3232
public ProcessManager(ITrace2 trace2)
3333
{
34-
_trace2 = trace2;
34+
EnsureArgument.NotNull(trace2, nameof(trace2));
35+
36+
Trace2 = trace2;
3537
}
3638

3739
public virtual ChildProcess CreateProcess(string path, string args, bool useShellExecute, string workingDirectory)
@@ -51,6 +53,6 @@ public virtual ChildProcess CreateProcess(string path, string args, bool useShel
5153

5254
public virtual ChildProcess CreateProcess(ProcessStartInfo psi)
5355
{
54-
return new ChildProcess(_trace2, psi);
56+
return new ChildProcess(Trace2, psi);
5557
}
5658
}

0 commit comments

Comments
 (0)