Skip to content

Commit

Permalink
Merge branch 'master' into fixes/discard-fails
Browse files Browse the repository at this point in the history
  • Loading branch information
StanleyGoldman authored May 16, 2018
2 parents 126c6a7 + 0d9e15f commit 8a36740
Show file tree
Hide file tree
Showing 25 changed files with 155 additions and 150 deletions.
114 changes: 65 additions & 49 deletions src/GitHub.Api/Installer/GitInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public GitInstaller(IEnvironment environment, IProcessManager processManager,

public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
{
var skipSystemProbing = state != null;

state = VerifyGitSettings(state);
if (state.GitIsValid && state.GitLfsIsValid)
{
Expand All @@ -37,11 +39,14 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
return state;
}

if (environment.IsMac)
state = FindSystemGit(state);
state = SetDefaultPaths(state);
if (!skipSystemProbing)
{
if (environment.IsMac)
state = FindGit(state);
}

state = CheckForUpdates(state);
state = SetDefaultPaths(state);
state = CheckForGitUpdates(state);

if (state.GitIsValid && state.GitLfsIsValid)
{
Expand All @@ -53,6 +58,12 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
state = GetZipsIfNeeded(state);
state = GrabZipFromResourcesIfNeeded(state);
state = ExtractGit(state);

// if installing from zip failed (internet down maybe?), try to find a usable system git
if (!state.GitIsValid && state.GitInstallationPath == installDetails.GitInstallationPath)
state = FindGit(state);
if (!state.GitLfsIsValid && state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
state = FindGitLfs(state);
state.GitLastCheckTime = DateTimeOffset.Now;
return state;
}
Expand Down Expand Up @@ -82,6 +93,13 @@ public GitInstallationState VerifyGitSettings(GitInstallationState state = null)
}

public GitInstallationState FindSystemGit(GitInstallationState state)
{
state = FindGit(state);
state = FindGitLfs(state);
return state;
}

private GitInstallationState FindGit(GitInstallationState state)
{
if (!state.GitIsValid)
{
Expand All @@ -94,7 +112,11 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
if (state.GitIsValid)
state.GitInstallationPath = gitPath.Parent.Parent;
}
return state;
}

private GitInstallationState FindGitLfs(GitInstallationState state)
{
if (!state.GitLfsIsValid)
{
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken)
Expand All @@ -111,7 +133,7 @@ public GitInstallationState FindSystemGit(GitInstallationState state)

public GitInstallationState SetDefaultPaths(GitInstallationState state)
{
if (!state.GitIsValid)
if (!state.GitIsValid && environment.IsWindows)
{
state.GitInstallationPath = installDetails.GitInstallationPath;
state.GitExecutablePath = installDetails.GitExecutablePath;
Expand Down Expand Up @@ -150,8 +172,7 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
state.GitLfsIsValid = false;
return state;
}
var version =
new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
var version = new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
.Configure(processManager, state.GitLfsExecutablePath, dontSetupGit: true)
.Catch(e => true)
.RunWithReturn(true);
Expand All @@ -160,29 +181,35 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
return state;
}

private GitInstallationState CheckForUpdates(GitInstallationState state)
private GitInstallationState CheckForGitUpdates(GitInstallationState state)
{
state.GitPackage = Package.Load(environment, installDetails.GitPackageFeed);
if (state.GitPackage != null)
if (state.GitInstallationPath == installDetails.GitInstallationPath)
{
state.GitIsValid = state.GitVersion >= state.GitPackage.Version;
if (state.GitIsValid)
state.GitPackage = Package.Load(environment, installDetails.GitPackageFeed);
if (state.GitPackage != null)
{
state.IsCustomGitPath = state.GitExecutablePath != installDetails.GitExecutablePath;
}
else
{
Logger.Trace($"{installDetails.GitExecutablePath} is out of date");
state.GitIsValid = state.GitVersion >= state.GitPackage.Version;
if (state.GitIsValid)
{
state.IsCustomGitPath = state.GitExecutablePath != installDetails.GitExecutablePath;
}
else
{
Logger.Trace($"{installDetails.GitExecutablePath} is out of date");
}
}
}

state.GitLfsPackage = Package.Load(environment, installDetails.GitLfsPackageFeed);
if (state.GitLfsPackage != null)
if (state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
{
state.GitLfsIsValid = state.GitLfsVersion >= state.GitLfsPackage.Version;
if (!state.GitLfsIsValid)
state.GitLfsPackage = Package.Load(environment, installDetails.GitLfsPackageFeed);
if (state.GitLfsPackage != null)
{
Logger.Trace($"{installDetails.GitLfsExecutablePath} is out of date");
state.GitLfsIsValid = state.GitLfsVersion >= state.GitLfsPackage.Version;
if (!state.GitLfsIsValid)
{
Logger.Trace($"{installDetails.GitLfsExecutablePath} is out of date");
}
}
}
return state;
Expand Down Expand Up @@ -218,8 +245,7 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
return state;

var downloader = new Downloader();
downloader
.Catch(e =>
downloader.Catch(e =>
{
LogHelper.Trace(e, "Failed to download");
return true;
Expand All @@ -240,11 +266,14 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)

private GitInstallationState GrabZipFromResourcesIfNeeded(GitInstallationState state)
{
if (!state.GitZipExists && !state.GitIsValid)
if (!state.GitZipExists && !state.GitIsValid && state.GitInstallationPath == installDetails.GitInstallationPath)
AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
state.GitZipExists = installDetails.GitZipPath.FileExists();

if (!state.GitLfsZipExists && !state.GitLfsIsValid)
if (state.GitLfsInstallationPath != installDetails.GitLfsInstallationPath)
return state;

if (!state.GitLfsZipExists && !state.GitLfsIsValid && state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.ZipPath, environment);
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
return state;
Expand Down Expand Up @@ -292,10 +321,10 @@ private GitInstallationState ExtractGit(GitInstallationState state)
});
unzipTask.Progress(p => ((Progress)Progress)?.UpdateProgress(60 + (long)(20 * p.Percentage), 100, unzipTask.Name));
var path = unzipTask.RunWithReturn(true);
var target = state.GitLfsExecutablePath;
var target = state.GitLfsInstallationPath;
if (unzipTask.Successful)
{
var source = path.Combine(installDetails.GitLfsExecutable);
var source = path;
target.DeleteIfExists();
target.EnsureParentDirectoryExists();
source.Move(target);
Expand Down Expand Up @@ -335,8 +364,8 @@ public class GitInstallDetails
private const string packageFeed = "http://github-vs.s3.amazonaws.com/unity/git/";
#endif

private const string PackageVersion = "f02737a78695063deace08e96d5042710d3e32db";
private const string PackageName = "PortableGit";
public const string GitDirectory = "git";
public const string GitLfsDirectory = "git-lfs";

private const string gitZip = "git.zip";
private const string gitLfsZip = "git-lfs.zip";
Expand All @@ -352,46 +381,33 @@ public GitInstallDetails(NPath baseDataPath, bool onWindows)
GitZipPath = ZipPath.Combine(gitZip);
GitLfsZipPath = ZipPath.Combine(gitLfsZip);

var gitInstallPath = baseDataPath.Combine(PackageNameWithVersion);
GitInstallationPath = gitInstallPath;
GitInstallationPath = baseDataPath.Combine(GitDirectory);
GitExecutablePath = GitInstallationPath.Combine(onWindows ? "cmd" : "bin", "git" + DefaultEnvironment.ExecutableExt);

GitLfsInstallationPath = baseDataPath.Combine(GitLfsDirectory);
GitLfsExecutablePath = GitLfsInstallationPath.Combine("git-lfs" + DefaultEnvironment.ExecutableExt);

if (onWindows)
{
GitExecutable += "git.exe";
GitLfsExecutable += "git-lfs.exe";
GitExecutablePath = gitInstallPath.Combine("cmd", GitExecutable);
GitPackageFeed = packageFeed + $"windows/{GitPackageName}";
GitLfsPackageFeed = packageFeed + $"windows/{GitLfsPackageName}";
}
else
{
GitExecutable = "git";
GitLfsExecutable = "git-lfs";
GitExecutablePath = gitInstallPath.Combine("bin", GitExecutable);
GitPackageFeed = packageFeed + $"mac/{GitPackageName}";
GitLfsPackageFeed = packageFeed + $"mac/{GitLfsPackageName}";
}
GitLfsExecutablePath = GetGitLfsExecutablePath(gitInstallPath);
}

public NPath GetGitLfsExecutablePath(NPath gitInstallRoot)
{
return onWindows
? gitInstallRoot.Combine("mingw32", "libexec", "git-core", GitLfsExecutable)
: gitInstallRoot.Combine("libexec", "git-core", GitLfsExecutable);
}

public NPath ZipPath { get; }
public NPath GitZipPath { get; }
public NPath GitLfsZipPath { get; }
public NPath GitInstallationPath { get; }
public string GitExecutable { get; }
public NPath GitLfsInstallationPath { get; }
public NPath GitExecutablePath { get; }
public string GitLfsExecutable { get; }
public NPath GitLfsExecutablePath { get; }
public UriString GitPackageFeed { get; set; }
public UriString GitLfsPackageFeed { get; set; }
public string PackageNameWithVersion => PackageName + "_" + PackageVersion;
}
}
}
4 changes: 2 additions & 2 deletions src/GitHub.Api/OutputProcessors/VersionOutputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public override void LineReceived(string line)
return;

var match = GitVersionRegex.Match(line);
if (match.Groups.Count > 0)
if (match.Groups.Count > 1)
{
var version = TheVersion.Parse(match.Groups[0].Value);
var version = TheVersion.Parse(match.Groups[1].Value);
RaiseOnEntry(version);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Api/Platform/DefaultEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public static bool OnMac
set { onMac = value; }
}

public static string ExecutableExt { get { return OnWindows ? ".exe" : string.Empty; } }
public string ExecutableExtension { get { return IsWindows ? ".exe" : string.Empty; } }
protected static ILogging Logger { get; } = LogHelper.GetLogger<DefaultEnvironment>();
}
Expand Down
4 changes: 1 addition & 3 deletions src/GitHub.Api/PlatformResources/mac/git-lfs.json
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
{"md5":"e2941215f99afa99f002e96c0ae70966","url":"http://ghfvs-installer.github.com/unity/git/mac/git-lfs.zip","releaseNotes":null,"releaseNotesUrl":null,"message":null,"version":"2.4.0"}
WARNING: The runtime version supported by this application is unavailable.
Using default runtime: v4.0.30319
{"md5":"e2941215f99afa99f002e96c0ae70966","url":"http://ghfvs-installer.github.com/unity/git/mac/git-lfs.zip","releaseNotes":null,"releaseNotesUrl":null,"message":null,"version":"2.4.0"}
2 changes: 1 addition & 1 deletion src/GitHub.Api/PlatformResources/windows/git.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"md5":"ea5d5a38a6b9e9bc2b10011602c65a0d","url":"http://ghfvs-installer.github.com/unity/git/windows/git.zip","releaseNotes":null,"releaseNotesUrl":null,"message":null,"version":"2.11.1"}
{"md5":"75c42f674b9ff32ebe338ff204f907cf","url":"http://ghfvs-installer.github.com/unity/git/windows/git.zip","releaseNotes":null,"releaseNotesUrl":null,"message":null,"version":"2.17.0.windows.1"}
4 changes: 2 additions & 2 deletions src/GitHub.Api/PlatformResources/windows/git.zip
Git LFS file not shown
9 changes: 6 additions & 3 deletions src/GitHub.Api/Primitives/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ [NotSerialized] public UriString Uri
public static Package Load(IEnvironment environment, UriString packageFeed)
{
Package package = null;
var key = packageFeed.Filename.ToNPath().FileNameWithoutExtension + "_updatelastCheckTime";
var filename = packageFeed.Filename.ToNPath();
if (!filename.IsInitialized || filename.IsRoot)
return package;
var key = filename.FileNameWithoutExtension + "_updatelastCheckTime";
var now = DateTimeOffset.Now;
NPath feed = environment.UserCachePath.Combine(packageFeed.Filename);

if (!feed.FileExists() || now.Date > environment.UserSettings.Get<DateTimeOffset>(key).Date)
{
feed = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem, packageFeed, environment.UserCachePath)
.Catch(e =>
.Catch(ex =>
{
LogHelper.Trace(e, "Failed to download " + packageFeed);
LogHelper.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.Message);
return true;
})
.RunWithReturn(true);
Expand Down
13 changes: 6 additions & 7 deletions src/GitHub.Api/Primitives/TheVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace GitHub.Unity
{
public struct TheVersion : IComparable<TheVersion>
{
private const string versionRegex = @"(?<major>\d+)(\.?(?<minor>[^.]+))?(\.?(?<patch>[^.]+))?(\.?(?<build>.+))?";
private const string versionRegex = @"^(?<major>\d+)(\.?(?<minor>[^.]+))?(\.?(?<patch>[^.]+))?(\.?(?<build>.+))?";
private const int PART_COUNT = 4;
public static TheVersion Default { get; } = default(TheVersion).Initialize(null);

Expand Down Expand Up @@ -57,15 +57,14 @@ private TheVersion Initialize(string theVersion)
special = null;
parts = 0;

if (String.IsNullOrEmpty(theVersion))
return this;

intParts = new int[PART_COUNT];
stringParts = new string[PART_COUNT];

for (var i = 0; i < PART_COUNT; i++)
stringParts[i] = intParts[i].ToString();

if (String.IsNullOrEmpty(theVersion))
return this;

var match = regex.Match(theVersion);
if (!match.Success)
{
Expand Down Expand Up @@ -195,9 +194,9 @@ public bool Equals(TheVersion other)
{
if (lhs.Version == rhs.Version)
return false;
if (String.IsNullOrEmpty(lhs.Version))
if (!lhs.initialized)
return false;
if (String.IsNullOrEmpty(rhs.Version))
if (!rhs.initialized)
return true;

for (var i = 0; i < lhs.parts && i < rhs.parts; i++)
Expand Down
6 changes: 2 additions & 4 deletions src/GitHub.Api/Tasks/ProcessTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ class ProcessTask<T> : TaskBase<T>, IProcessTask<T>
{
private IOutputProcessor<T> outputProcessor;
private ProcessWrapper wrapper;
private bool finished = false;

public event Action<string> OnErrorData;
public event Action<IProcess> OnStartProcess;
Expand Down Expand Up @@ -303,7 +302,6 @@ public override T RunWithReturn(bool success)
RaiseOnStart,
() =>
{
finished = true;
try
{
if (outputProcessor != null)
Expand Down Expand Up @@ -352,7 +350,7 @@ public override string ToString()

public Process Process { get; set; }
public int ProcessId { get { return Process.Id; } }
public override bool Successful { get { return finished && ((!taskFailed && Process.ExitCode == 0) || (taskFailed && exceptionWasHandled)); } }
public override bool Successful { get { return base.Successful && Process.ExitCode == 0; } }
public StreamWriter StandardInput { get { return wrapper?.Input; } }
public virtual string ProcessName { get; protected set; }
public virtual string ProcessArguments { get; }
Expand Down Expand Up @@ -486,7 +484,7 @@ public override string ToString()

public Process Process { get; set; }
public int ProcessId { get { return Process.Id; } }
public override bool Successful { get { return Task.Status == TaskStatus.RanToCompletion && Process.ExitCode == 0; } }
public override bool Successful { get { return base.Successful && Process.ExitCode == 0; } }
public StreamWriter StandardInput { get { return wrapper?.Input; } }
public virtual string ProcessName { get; protected set; }
public virtual string ProcessArguments { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub.Api/Tasks/TaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ public override string ToString()
return $"{Task?.Id ?? -1} {Name} {GetType()}";
}

public virtual bool Successful { get { return !taskFailed || exceptionWasHandled; } }
public virtual bool Successful { get { return hasRun && !taskFailed; } }
public bool IsCompleted { get { return hasRun; } }
public string Errors { get; protected set; }
public Task Task { get; protected set; }
public bool IsCompleted { get { return hasRun; /*(Task as IAsyncResult).IsCompleted;*/ } }
public WaitHandle AsyncWaitHandle { get { return (Task as IAsyncResult).AsyncWaitHandle; } }
public object AsyncState { get { return (Task as IAsyncResult).AsyncState; } }
public bool CompletedSynchronously { get { return (Task as IAsyncResult).CompletedSynchronously; } }
Expand Down
4 changes: 3 additions & 1 deletion src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ private static void Initialize()
}

LogHelper.LogAdapter = new MultipleLogAdapter(new FileLogAdapter(logPath)
//, new UnityLogAdapter()
#if DEBUG
, new UnityLogAdapter()
#endif
);
LogHelper.Info("Initializing GitHubForUnity:'v{0}' Unity:'v{1}'", ApplicationInfo.Version, Environment.UnityVersion);

Expand Down
Loading

0 comments on commit 8a36740

Please sign in to comment.