Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 3bf1eaf

Browse files
committed
Fix the command line environment on mac
1 parent 8310c7e commit 3bf1eaf

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,13 @@ public void RunCommandLineWindow(NPath workingDirectory)
7474
}
7575
else if (environment.IsMac)
7676
{
77+
// we need to create a temp bash script to set up the environment properly, because
78+
// osx terminal app doesn't inherit the PATH env var and there's no way to pass it in
79+
var envVarFile = environment.FileSystem.GetRandomFileName();
80+
environment.FileSystem.WriteAllLines(envVarFile, new string[] { "cd $GHU_WORKINGDIR", "PATH=$GHU_FULLPATH:$PATH /bin/bash" });
81+
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
7782
startInfo.FileName = "open";
78-
startInfo.Arguments = $"-a Terminal {workingDirectory}";
83+
startInfo.Arguments = $"-a Terminal {envVarFile}";
7984
}
8085
else
8186
{

src/GitHub.Api/Platform/ProcessEnvironment.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory)
5454

5555
var gitPathRoot = Environment.GitInstallPath;
5656
var gitLfsPath = Environment.GitInstallPath;
57+
var gitExecutableDir = Environment.GitExecutablePath.Parent; // original path to git (might be different from install path if it's a symlink)
5758

5859
// Paths to developer tools such as msbuild.exe
5960
//var developerPaths = StringExtensions.JoinForAppending(";", developerEnvironment.GetPaths());
@@ -78,19 +79,17 @@ public void Configure(ProcessStartInfo psi, NPath workingDirectory)
7879
if (Environment.IsWindows)
7980
{
8081
var userPath = @"C:\windows\system32;C:\windows";
81-
path = String.Format(CultureInfo.InvariantCulture, @"{0}\cmd;{0}\usr\bin;{1};{2};{0}\usr\share\git-tfs;{3};{4}{5}",
82-
gitPathRoot, execPath, binPath,
83-
gitLfsPath, userPath, developerPaths);
82+
path = $"{gitPathRoot}\\cmd;{gitPathRoot}\\usr\\bin;{execPath};{binPath};{gitLfsPath};{userPath}{developerPaths}";
8483
}
8584
else
8685
{
87-
var userPath = Environment.Path;
88-
path = String.Format(CultureInfo.InvariantCulture, @"{0}:{1}:{2}:{3}{4}",
89-
binPath, execPath, gitLfsPath, userPath, developerPaths);
86+
path = $"{gitExecutableDir}:{binPath}:{execPath}:{gitLfsPath}:{Environment.Path}:{developerPaths}";
9087
}
9188
psi.EnvironmentVariables["GIT_EXEC_PATH"] = execPath.ToString();
9289

9390
psi.EnvironmentVariables["PATH"] = path;
91+
psi.EnvironmentVariables["GHU_FULLPATH"] = path;
92+
psi.EnvironmentVariables["GHU_WORKINGDIR"] = workingDirectory;
9493

9594
psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh";
9695
psi.EnvironmentVariables["TERM"] = "msys";

0 commit comments

Comments
 (0)