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

Commit 8a36740

Browse files
Merge branch 'master' into fixes/discard-fails
2 parents 126c6a7 + 0d9e15f commit 8a36740

File tree

25 files changed

+155
-150
lines changed

25 files changed

+155
-150
lines changed

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 65 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public GitInstaller(IEnvironment environment, IProcessManager processManager,
2929

3030
public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
3131
{
32+
var skipSystemProbing = state != null;
33+
3234
state = VerifyGitSettings(state);
3335
if (state.GitIsValid && state.GitLfsIsValid)
3436
{
@@ -37,11 +39,14 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
3739
return state;
3840
}
3941

40-
if (environment.IsMac)
41-
state = FindSystemGit(state);
42-
state = SetDefaultPaths(state);
42+
if (!skipSystemProbing)
43+
{
44+
if (environment.IsMac)
45+
state = FindGit(state);
46+
}
4347

44-
state = CheckForUpdates(state);
48+
state = SetDefaultPaths(state);
49+
state = CheckForGitUpdates(state);
4550

4651
if (state.GitIsValid && state.GitLfsIsValid)
4752
{
@@ -53,6 +58,12 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
5358
state = GetZipsIfNeeded(state);
5459
state = GrabZipFromResourcesIfNeeded(state);
5560
state = ExtractGit(state);
61+
62+
// if installing from zip failed (internet down maybe?), try to find a usable system git
63+
if (!state.GitIsValid && state.GitInstallationPath == installDetails.GitInstallationPath)
64+
state = FindGit(state);
65+
if (!state.GitLfsIsValid && state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
66+
state = FindGitLfs(state);
5667
state.GitLastCheckTime = DateTimeOffset.Now;
5768
return state;
5869
}
@@ -82,6 +93,13 @@ public GitInstallationState VerifyGitSettings(GitInstallationState state = null)
8293
}
8394

8495
public GitInstallationState FindSystemGit(GitInstallationState state)
96+
{
97+
state = FindGit(state);
98+
state = FindGitLfs(state);
99+
return state;
100+
}
101+
102+
private GitInstallationState FindGit(GitInstallationState state)
85103
{
86104
if (!state.GitIsValid)
87105
{
@@ -94,7 +112,11 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
94112
if (state.GitIsValid)
95113
state.GitInstallationPath = gitPath.Parent.Parent;
96114
}
115+
return state;
116+
}
97117

118+
private GitInstallationState FindGitLfs(GitInstallationState state)
119+
{
98120
if (!state.GitLfsIsValid)
99121
{
100122
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken)
@@ -111,7 +133,7 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
111133

112134
public GitInstallationState SetDefaultPaths(GitInstallationState state)
113135
{
114-
if (!state.GitIsValid)
136+
if (!state.GitIsValid && environment.IsWindows)
115137
{
116138
state.GitInstallationPath = installDetails.GitInstallationPath;
117139
state.GitExecutablePath = installDetails.GitExecutablePath;
@@ -150,8 +172,7 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
150172
state.GitLfsIsValid = false;
151173
return state;
152174
}
153-
var version =
154-
new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
175+
var version = new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
155176
.Configure(processManager, state.GitLfsExecutablePath, dontSetupGit: true)
156177
.Catch(e => true)
157178
.RunWithReturn(true);
@@ -160,29 +181,35 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
160181
return state;
161182
}
162183

163-
private GitInstallationState CheckForUpdates(GitInstallationState state)
184+
private GitInstallationState CheckForGitUpdates(GitInstallationState state)
164185
{
165-
state.GitPackage = Package.Load(environment, installDetails.GitPackageFeed);
166-
if (state.GitPackage != null)
186+
if (state.GitInstallationPath == installDetails.GitInstallationPath)
167187
{
168-
state.GitIsValid = state.GitVersion >= state.GitPackage.Version;
169-
if (state.GitIsValid)
188+
state.GitPackage = Package.Load(environment, installDetails.GitPackageFeed);
189+
if (state.GitPackage != null)
170190
{
171-
state.IsCustomGitPath = state.GitExecutablePath != installDetails.GitExecutablePath;
172-
}
173-
else
174-
{
175-
Logger.Trace($"{installDetails.GitExecutablePath} is out of date");
191+
state.GitIsValid = state.GitVersion >= state.GitPackage.Version;
192+
if (state.GitIsValid)
193+
{
194+
state.IsCustomGitPath = state.GitExecutablePath != installDetails.GitExecutablePath;
195+
}
196+
else
197+
{
198+
Logger.Trace($"{installDetails.GitExecutablePath} is out of date");
199+
}
176200
}
177201
}
178202

179-
state.GitLfsPackage = Package.Load(environment, installDetails.GitLfsPackageFeed);
180-
if (state.GitLfsPackage != null)
203+
if (state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
181204
{
182-
state.GitLfsIsValid = state.GitLfsVersion >= state.GitLfsPackage.Version;
183-
if (!state.GitLfsIsValid)
205+
state.GitLfsPackage = Package.Load(environment, installDetails.GitLfsPackageFeed);
206+
if (state.GitLfsPackage != null)
184207
{
185-
Logger.Trace($"{installDetails.GitLfsExecutablePath} is out of date");
208+
state.GitLfsIsValid = state.GitLfsVersion >= state.GitLfsPackage.Version;
209+
if (!state.GitLfsIsValid)
210+
{
211+
Logger.Trace($"{installDetails.GitLfsExecutablePath} is out of date");
212+
}
186213
}
187214
}
188215
return state;
@@ -218,8 +245,7 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
218245
return state;
219246

220247
var downloader = new Downloader();
221-
downloader
222-
.Catch(e =>
248+
downloader.Catch(e =>
223249
{
224250
LogHelper.Trace(e, "Failed to download");
225251
return true;
@@ -240,11 +266,14 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
240266

241267
private GitInstallationState GrabZipFromResourcesIfNeeded(GitInstallationState state)
242268
{
243-
if (!state.GitZipExists && !state.GitIsValid)
269+
if (!state.GitZipExists && !state.GitIsValid && state.GitInstallationPath == installDetails.GitInstallationPath)
244270
AssemblyResources.ToFile(ResourceType.Platform, "git.zip", installDetails.ZipPath, environment);
245271
state.GitZipExists = installDetails.GitZipPath.FileExists();
246272

247-
if (!state.GitLfsZipExists && !state.GitLfsIsValid)
273+
if (state.GitLfsInstallationPath != installDetails.GitLfsInstallationPath)
274+
return state;
275+
276+
if (!state.GitLfsZipExists && !state.GitLfsIsValid && state.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
248277
AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", installDetails.ZipPath, environment);
249278
state.GitLfsZipExists = installDetails.GitLfsZipPath.FileExists();
250279
return state;
@@ -292,10 +321,10 @@ private GitInstallationState ExtractGit(GitInstallationState state)
292321
});
293322
unzipTask.Progress(p => ((Progress)Progress)?.UpdateProgress(60 + (long)(20 * p.Percentage), 100, unzipTask.Name));
294323
var path = unzipTask.RunWithReturn(true);
295-
var target = state.GitLfsExecutablePath;
324+
var target = state.GitLfsInstallationPath;
296325
if (unzipTask.Successful)
297326
{
298-
var source = path.Combine(installDetails.GitLfsExecutable);
327+
var source = path;
299328
target.DeleteIfExists();
300329
target.EnsureParentDirectoryExists();
301330
source.Move(target);
@@ -335,8 +364,8 @@ public class GitInstallDetails
335364
private const string packageFeed = "http://github-vs.s3.amazonaws.com/unity/git/";
336365
#endif
337366

338-
private const string PackageVersion = "f02737a78695063deace08e96d5042710d3e32db";
339-
private const string PackageName = "PortableGit";
367+
public const string GitDirectory = "git";
368+
public const string GitLfsDirectory = "git-lfs";
340369

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

355-
var gitInstallPath = baseDataPath.Combine(PackageNameWithVersion);
356-
GitInstallationPath = gitInstallPath;
384+
GitInstallationPath = baseDataPath.Combine(GitDirectory);
385+
GitExecutablePath = GitInstallationPath.Combine(onWindows ? "cmd" : "bin", "git" + DefaultEnvironment.ExecutableExt);
386+
387+
GitLfsInstallationPath = baseDataPath.Combine(GitLfsDirectory);
388+
GitLfsExecutablePath = GitLfsInstallationPath.Combine("git-lfs" + DefaultEnvironment.ExecutableExt);
357389

358390
if (onWindows)
359391
{
360-
GitExecutable += "git.exe";
361-
GitLfsExecutable += "git-lfs.exe";
362-
GitExecutablePath = gitInstallPath.Combine("cmd", GitExecutable);
363392
GitPackageFeed = packageFeed + $"windows/{GitPackageName}";
364393
GitLfsPackageFeed = packageFeed + $"windows/{GitLfsPackageName}";
365394
}
366395
else
367396
{
368-
GitExecutable = "git";
369-
GitLfsExecutable = "git-lfs";
370-
GitExecutablePath = gitInstallPath.Combine("bin", GitExecutable);
371397
GitPackageFeed = packageFeed + $"mac/{GitPackageName}";
372398
GitLfsPackageFeed = packageFeed + $"mac/{GitLfsPackageName}";
373399
}
374-
GitLfsExecutablePath = GetGitLfsExecutablePath(gitInstallPath);
375-
}
376-
377-
public NPath GetGitLfsExecutablePath(NPath gitInstallRoot)
378-
{
379-
return onWindows
380-
? gitInstallRoot.Combine("mingw32", "libexec", "git-core", GitLfsExecutable)
381-
: gitInstallRoot.Combine("libexec", "git-core", GitLfsExecutable);
382400
}
383401

384402
public NPath ZipPath { get; }
385403
public NPath GitZipPath { get; }
386404
public NPath GitLfsZipPath { get; }
387405
public NPath GitInstallationPath { get; }
388-
public string GitExecutable { get; }
406+
public NPath GitLfsInstallationPath { get; }
389407
public NPath GitExecutablePath { get; }
390-
public string GitLfsExecutable { get; }
391408
public NPath GitLfsExecutablePath { get; }
392409
public UriString GitPackageFeed { get; set; }
393410
public UriString GitLfsPackageFeed { get; set; }
394-
public string PackageNameWithVersion => PackageName + "_" + PackageVersion;
395411
}
396412
}
397413
}

src/GitHub.Api/OutputProcessors/VersionOutputProcessor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public override void LineReceived(string line)
1515
return;
1616

1717
var match = GitVersionRegex.Match(line);
18-
if (match.Groups.Count > 0)
18+
if (match.Groups.Count > 1)
1919
{
20-
var version = TheVersion.Parse(match.Groups[0].Value);
20+
var version = TheVersion.Parse(match.Groups[1].Value);
2121
RaiseOnEntry(version);
2222
}
2323
}

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ public static bool OnMac
232232
set { onMac = value; }
233233
}
234234

235+
public static string ExecutableExt { get { return OnWindows ? ".exe" : string.Empty; } }
235236
public string ExecutableExtension { get { return IsWindows ? ".exe" : string.Empty; } }
236237
protected static ILogging Logger { get; } = LogHelper.GetLogger<DefaultEnvironment>();
237238
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
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"}
2-
WARNING: The runtime version supported by this application is unavailable.
3-
Using default runtime: v4.0.30319
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"}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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"}
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"}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:24864bd6ed4d60a516330107932082ae17ae5b98b0819d6cb6eba4a96b7ae0e4
3-
size 83230267
2+
oid sha256:7e60087e32bfe32d897d2b20f013527be79a9596a280dc92bc793bcd744cc914
3+
size 97180593

src/GitHub.Api/Primitives/Package.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ [NotSerialized] public UriString Uri
2626
public static Package Load(IEnvironment environment, UriString packageFeed)
2727
{
2828
Package package = null;
29-
var key = packageFeed.Filename.ToNPath().FileNameWithoutExtension + "_updatelastCheckTime";
29+
var filename = packageFeed.Filename.ToNPath();
30+
if (!filename.IsInitialized || filename.IsRoot)
31+
return package;
32+
var key = filename.FileNameWithoutExtension + "_updatelastCheckTime";
3033
var now = DateTimeOffset.Now;
3134
NPath feed = environment.UserCachePath.Combine(packageFeed.Filename);
3235

3336
if (!feed.FileExists() || now.Date > environment.UserSettings.Get<DateTimeOffset>(key).Date)
3437
{
3538
feed = new DownloadTask(TaskManager.Instance.Token, environment.FileSystem, packageFeed, environment.UserCachePath)
36-
.Catch(e =>
39+
.Catch(ex =>
3740
{
38-
LogHelper.Trace(e, "Failed to download " + packageFeed);
41+
LogHelper.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.Message);
3942
return true;
4043
})
4144
.RunWithReturn(true);

src/GitHub.Api/Primitives/TheVersion.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GitHub.Unity
66
{
77
public struct TheVersion : IComparable<TheVersion>
88
{
9-
private const string versionRegex = @"(?<major>\d+)(\.?(?<minor>[^.]+))?(\.?(?<patch>[^.]+))?(\.?(?<build>.+))?";
9+
private const string versionRegex = @"^(?<major>\d+)(\.?(?<minor>[^.]+))?(\.?(?<patch>[^.]+))?(\.?(?<build>.+))?";
1010
private const int PART_COUNT = 4;
1111
public static TheVersion Default { get; } = default(TheVersion).Initialize(null);
1212

@@ -57,15 +57,14 @@ private TheVersion Initialize(string theVersion)
5757
special = null;
5858
parts = 0;
5959

60-
if (String.IsNullOrEmpty(theVersion))
61-
return this;
62-
6360
intParts = new int[PART_COUNT];
6461
stringParts = new string[PART_COUNT];
65-
6662
for (var i = 0; i < PART_COUNT; i++)
6763
stringParts[i] = intParts[i].ToString();
6864

65+
if (String.IsNullOrEmpty(theVersion))
66+
return this;
67+
6968
var match = regex.Match(theVersion);
7069
if (!match.Success)
7170
{
@@ -195,9 +194,9 @@ public bool Equals(TheVersion other)
195194
{
196195
if (lhs.Version == rhs.Version)
197196
return false;
198-
if (String.IsNullOrEmpty(lhs.Version))
197+
if (!lhs.initialized)
199198
return false;
200-
if (String.IsNullOrEmpty(rhs.Version))
199+
if (!rhs.initialized)
201200
return true;
202201

203202
for (var i = 0; i < lhs.parts && i < rhs.parts; i++)

src/GitHub.Api/Tasks/ProcessTask.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ class ProcessTask<T> : TaskBase<T>, IProcessTask<T>
213213
{
214214
private IOutputProcessor<T> outputProcessor;
215215
private ProcessWrapper wrapper;
216-
private bool finished = false;
217216

218217
public event Action<string> OnErrorData;
219218
public event Action<IProcess> OnStartProcess;
@@ -303,7 +302,6 @@ public override T RunWithReturn(bool success)
303302
RaiseOnStart,
304303
() =>
305304
{
306-
finished = true;
307305
try
308306
{
309307
if (outputProcessor != null)
@@ -352,7 +350,7 @@ public override string ToString()
352350

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

487485
public Process Process { get; set; }
488486
public int ProcessId { get { return Process.Id; } }
489-
public override bool Successful { get { return Task.Status == TaskStatus.RanToCompletion && Process.ExitCode == 0; } }
487+
public override bool Successful { get { return base.Successful && Process.ExitCode == 0; } }
490488
public StreamWriter StandardInput { get { return wrapper?.Input; } }
491489
public virtual string ProcessName { get; protected set; }
492490
public virtual string ProcessArguments { get; }

src/GitHub.Api/Tasks/TaskBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,10 @@ public override string ToString()
491491
return $"{Task?.Id ?? -1} {Name} {GetType()}";
492492
}
493493

494-
public virtual bool Successful { get { return !taskFailed || exceptionWasHandled; } }
494+
public virtual bool Successful { get { return hasRun && !taskFailed; } }
495+
public bool IsCompleted { get { return hasRun; } }
495496
public string Errors { get; protected set; }
496497
public Task Task { get; protected set; }
497-
public bool IsCompleted { get { return hasRun; /*(Task as IAsyncResult).IsCompleted;*/ } }
498498
public WaitHandle AsyncWaitHandle { get { return (Task as IAsyncResult).AsyncWaitHandle; } }
499499
public object AsyncState { get { return (Task as IAsyncResult).AsyncState; } }
500500
public bool CompletedSynchronously { get { return (Task as IAsyncResult).CompletedSynchronously; } }

0 commit comments

Comments
 (0)