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

Commit edc6441

Browse files
committed
Add symlink resolver so we can figure out paths properly
Fixes #192 On non-windows, git and other files might be symlinks, so when we're using them as a base for determining parent directories, we may need to resolve the symlink first. The rules for automatically doing symlink resolution are tricky, so for now just do it manually.
1 parent f1dcc58 commit edc6441

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
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.Resolve();
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: 12 additions & 0 deletions
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

@@ -1018,6 +1022,14 @@ public static NPath ToNPath(this string path)
10181022
return null;
10191023
return new NPath(path);
10201024
}
1025+
1026+
public static NPath Resolve(this NPath path)
1027+
{
1028+
if (path == null || DefaultEnvironment.OnWindows || path.IsRelative || !path.FileExists())
1029+
return path;
1030+
1031+
return new NPath(Mono.Unix.UnixPath.GetCompleteRealPath(path.ToString()));
1032+
}
10211033
}
10221034

10231035
public enum SlashMode

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.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; }

0 commit comments

Comments
 (0)