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

Commit 4338edd

Browse files
authored
Merge pull request #193 from github-for-unity/fixes/192-wrong-environment-mac
Add symlink resolver so we can figure out paths properly
2 parents f1dcc58 + 1992dc2 commit 4338edd

File tree

7 files changed

+46
-42
lines changed

7 files changed

+46
-42
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,18 @@ private Task<NPath> LookForPortableGit()
134134

135135
private async Task<NPath> LookForSystemGit()
136136
{
137-
if (environment.IsMac)
137+
NPath path = null;
138+
if (!environment.IsWindows)
138139
{
139-
var path = "/usr/local/bin/git".ToNPath();
140-
if (path.FileExists())
141-
return path;
140+
var p = new NPath("/usr/local/bin/git");
141+
if (p.FileExists())
142+
path = p;
142143
}
143-
return await new FindExecTask("git", taskManager.Token).StartAwait();
144+
145+
if (path == null)
146+
path = await new FindExecTask("git", taskManager.Token).StartAwait();
147+
148+
return path;
144149
}
145150

146151
public bool ValidateGitInstall(NPath path)

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
<Reference Include="Mono.Security">
7070
<HintPath>$(SolutionDir)lib\Mono.Security.dll</HintPath>
7171
</Reference>
72+
<Reference Include="Mono.Posix">
73+
<HintPath>$(SolutionDir)lib\Mono.Posix.dll</HintPath>
74+
</Reference>
7275
<Reference Include="Rackspace.Threading, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bb62785d398726f0, processorArchitecture=MSIL">
7376
<HintPath>$(SolutionDir)\packages\TunnelVisionLabs.Threading.2.0.0-unity\lib\net35-client\Rackspace.Threading.dll</HintPath>
7477
<Private>True</Private>

src/GitHub.Api/IO/NiceIO.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ public bool DirectoryExists(string append = "")
283283

284284
public bool DirectoryExists(NPath append)
285285
{
286+
if (append == null)
287+
return FileSystem.DirectoryExists(ToString());
286288
return FileSystem.DirectoryExists(Combine(append).ToString());
287289
}
288290

@@ -295,6 +297,8 @@ public bool FileExists(string append = "")
295297

296298
public bool FileExists(NPath append)
297299
{
300+
if (append == null)
301+
return FileSystem.FileExists(ToString());
298302
return FileSystem.FileExists(Combine(append).ToString());
299303
}
300304

@@ -749,11 +753,14 @@ public static NPath HomeDirectory
749753
}
750754
}
751755

756+
private static NPath systemTemp;
752757
public static NPath SystemTemp
753758
{
754759
get
755760
{
756-
return new NPath(FileSystem.GetTempPath());
761+
if (systemTemp == null)
762+
systemTemp = new NPath(FileSystem.GetTempPath());
763+
return systemTemp;
757764
}
758765
}
759766

@@ -1018,6 +1025,14 @@ public static NPath ToNPath(this string path)
10181025
return null;
10191026
return new NPath(path);
10201027
}
1028+
1029+
public static NPath Resolve(this NPath path)
1030+
{
1031+
if (path == null || DefaultEnvironment.OnWindows || path.IsRelative || !path.FileExists())
1032+
return path;
1033+
1034+
return new NPath(Mono.Unix.UnixPath.GetCompleteRealPath(path.ToString()));
1035+
}
10211036
}
10221037

10231038
public enum SlashMode

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/DefaultEnvironment.cs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,35 +117,14 @@ public NPath GitExecutablePath
117117
set
118118
{
119119
gitExecutablePath = value;
120-
gitInstallPath = null;
120+
if (String.IsNullOrEmpty(gitExecutablePath))
121+
GitInstallPath = null;
122+
else
123+
GitInstallPath = GitExecutablePath.Resolve().Parent.Parent;
121124
}
122125
}
123126

124-
private NPath gitInstallPath;
125-
public NPath GitInstallPath
126-
{
127-
get
128-
{
129-
if (gitInstallPath == null)
130-
{
131-
132-
if (!String.IsNullOrEmpty(GitExecutablePath))
133-
{
134-
if (IsWindows)
135-
{
136-
gitInstallPath = GitExecutablePath.Parent.Parent;
137-
}
138-
else
139-
{
140-
gitInstallPath = GitExecutablePath.Parent;
141-
}
142-
}
143-
else
144-
gitInstallPath = GitExecutablePath;
145-
}
146-
return gitInstallPath;
147-
}
148-
}
127+
public NPath GitInstallPath { get; private set; }
149128

150129
public NPath RepositoryPath { get; private set; }
151130
public IRepository Repository { get; set; }

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";

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PUblishView.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,7 @@ public override void OnGUI()
222222
return;
223223
}
224224

225-
var repositoryCloneUrl = Environment.IsWindows ? repository.CloneUrl : repository.SshUrl;
226-
227-
GitClient.RemoteAdd("origin", repositoryCloneUrl)
225+
GitClient.RemoteAdd("origin", repository.CloneUrl)
228226
.Then(GitClient.Push("origin", Repository.CurrentBranch.Value.Name))
229227
.ThenInUI(Parent.Finish)
230228
.Start();

0 commit comments

Comments
 (0)