Skip to content
Snippets Groups Projects
Commit edc64412 authored by Andreia Gaita's avatar Andreia Gaita
Browse files

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.
parent f1dcc58c
No related branches found
No related tags found
No related merge requests found
......@@ -134,13 +134,18 @@ namespace GitHub.Unity
private async Task<NPath> LookForSystemGit()
{
if (environment.IsMac)
NPath path = null;
if (!environment.IsWindows)
{
var path = "/usr/local/bin/git".ToNPath();
if (path.FileExists())
return path;
var p = new NPath("/usr/local/bin/git");
if (p.FileExists())
path = p;
}
return await new FindExecTask("git", taskManager.Token).StartAwait();
if (path == null)
path = await new FindExecTask("git", taskManager.Token).StartAwait();
return path.Resolve();
}
public bool ValidateGitInstall(NPath path)
......
......@@ -69,6 +69,9 @@
<Reference Include="Mono.Security">
<HintPath>$(SolutionDir)lib\Mono.Security.dll</HintPath>
</Reference>
<Reference Include="Mono.Posix">
<HintPath>$(SolutionDir)lib\Mono.Posix.dll</HintPath>
</Reference>
<Reference Include="Rackspace.Threading, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bb62785d398726f0, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\TunnelVisionLabs.Threading.2.0.0-unity\lib\net35-client\Rackspace.Threading.dll</HintPath>
<Private>True</Private>
......
......@@ -283,6 +283,8 @@ GitHub.Unity
public bool DirectoryExists(NPath append)
{
if (append == null)
return FileSystem.DirectoryExists(ToString());
return FileSystem.DirectoryExists(Combine(append).ToString());
}
......@@ -295,6 +297,8 @@ GitHub.Unity
public bool FileExists(NPath append)
{
if (append == null)
return FileSystem.FileExists(ToString());
return FileSystem.FileExists(Combine(append).ToString());
}
......@@ -1018,6 +1022,14 @@ GitHub.Unity
return null;
return new NPath(path);
}
public static NPath Resolve(this NPath path)
{
if (path == null || DefaultEnvironment.OnWindows || path.IsRelative || !path.FileExists())
return path;
return new NPath(Mono.Unix.UnixPath.GetCompleteRealPath(path.ToString()));
}
}
public enum SlashMode
......
......@@ -117,35 +117,14 @@ namespace GitHub.Unity
set
{
gitExecutablePath = value;
gitInstallPath = null;
if (String.IsNullOrEmpty(gitExecutablePath))
GitInstallPath = null;
else
GitInstallPath = GitExecutablePath.Parent.Parent;
}
}
private NPath gitInstallPath;
public NPath GitInstallPath
{
get
{
if (gitInstallPath == null)
{
if (!String.IsNullOrEmpty(GitExecutablePath))
{
if (IsWindows)
{
gitInstallPath = GitExecutablePath.Parent.Parent;
}
else
{
gitInstallPath = GitExecutablePath.Parent;
}
}
else
gitInstallPath = GitExecutablePath;
}
return gitInstallPath;
}
}
public NPath GitInstallPath { get; private set; }
public NPath RepositoryPath { get; private set; }
public IRepository Repository { get; set; }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment