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

Commit dea4762

Browse files
committed
Fix installer tests reflecting the different paths git and git lfs are in now
Also, the installer tests use a smaller git zip, which can't be the same that's served from the web server package feed, because the versions don't match. This means the tests need to manually unzip git and not download it from the package feed.
1 parent e9e6996 commit dea4762

File tree

10 files changed

+79
-80
lines changed

10 files changed

+79
-80
lines changed

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
4242
if (!skipSystemProbing)
4343
{
4444
if (environment.IsMac)
45-
state = FindSystemGit(state);
45+
state = FindGit(state);
4646
state = SetDefaultPaths(state);
4747
}
4848

@@ -58,6 +58,12 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
5858
state = GetZipsIfNeeded(state);
5959
state = GrabZipFromResourcesIfNeeded(state);
6060
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);
6167
state.GitLastCheckTime = DateTimeOffset.Now;
6268
return state;
6369
}
@@ -88,18 +94,13 @@ public GitInstallationState VerifyGitSettings(GitInstallationState state = null)
8894

8995
public GitInstallationState FindSystemGit(GitInstallationState state)
9096
{
91-
if (!state.GitIsValid)
92-
{
93-
var gitPath = new FindExecTask("git", cancellationToken)
94-
.Configure(processManager, dontSetupGit: true)
95-
.Catch(e => true)
96-
.RunWithReturn(true);
97-
state.GitExecutablePath = gitPath;
98-
state = ValidateGitVersion(state);
99-
if (state.GitIsValid)
100-
state.GitInstallationPath = gitPath.Parent.Parent;
101-
}
97+
state = FindGit(state);
98+
state = FindGitLfs(state);
99+
return state;
100+
}
102101

102+
private GitInstallationState FindGitLfs(GitInstallationState state)
103+
{
103104
if (!state.GitLfsIsValid)
104105
{
105106
var gitLfsPath = new FindExecTask("git-lfs", cancellationToken)
@@ -114,6 +115,22 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
114115
return state;
115116
}
116117

118+
private GitInstallationState FindGit(GitInstallationState state)
119+
{
120+
if (!state.GitIsValid)
121+
{
122+
var gitPath = new FindExecTask("git", cancellationToken)
123+
.Configure(processManager, dontSetupGit: true)
124+
.Catch(e => true)
125+
.RunWithReturn(true);
126+
state.GitExecutablePath = gitPath;
127+
state = ValidateGitVersion(state);
128+
if (state.GitIsValid)
129+
state.GitInstallationPath = gitPath.Parent.Parent;
130+
}
131+
return state;
132+
}
133+
117134
public GitInstallationState SetDefaultPaths(GitInstallationState state)
118135
{
119136
if (!state.GitIsValid && environment.IsWindows)
@@ -155,8 +172,7 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
155172
state.GitLfsIsValid = false;
156173
return state;
157174
}
158-
var version =
159-
new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
175+
var version = new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
160176
.Configure(processManager, state.GitLfsExecutablePath, dontSetupGit: true)
161177
.Catch(e => true)
162178
.RunWithReturn(true);

src/GitHub.Api/Primitives/Package.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ [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

src/tests/IntegrationTests/Installer/GitInstallerTests.cs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -169,72 +169,71 @@ public override void OnSetup()
169169
[Test]
170170
public void GitLfsIsInstalledIfMissing()
171171
{
172-
var gitInstallationPath = TestBasePath.Combine("GitInstall").CreateDirectory();
173-
174-
var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath, DefaultEnvironment.OnWindows)
175-
{
176-
GitPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitPackageName}",
177-
GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}",
178-
};
172+
var tempZipExtractPath = TestBasePath.Combine("Temp", "git_zip_extract_zip_paths");
173+
var gitInstallationPath = TestBasePath.Combine("GitInstall").Combine(GitInstaller.GitInstallDetails.GitDirectory);
174+
var gitLfsInstallationPath = TestBasePath.Combine("GitInstall").Combine(GitInstaller.GitInstallDetails.GitLfsDirectory);
179175

180-
var package = Package.Load(Environment, installDetails.GitPackageFeed);
176+
var gitZipUri = new UriString($"http://localhost:{server.Port}/unity/git/windows/git-slim.zip");
181177
var downloader = new Downloader();
182-
downloader.Catch(e => true);
183-
downloader.QueueDownload(package.Uri, installDetails.ZipPath);
178+
downloader.QueueDownload(gitZipUri, tempZipExtractPath);
184179
downloader.RunWithReturn(true);
185180

186-
var tempZipExtractPath = TestBasePath.Combine("Temp", "git_zip_extract_zip_paths");
187-
188181
var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();
189-
ZipHelper.Instance.Extract(installDetails.GitZipPath, gitExtractPath, TaskManager.Token, null);
182+
ZipHelper.Instance.Extract(tempZipExtractPath.Combine(gitZipUri.Filename), gitExtractPath, TaskManager.Token, null);
190183
var source = gitExtractPath;
191-
var target = installDetails.GitInstallationPath;
184+
var target = gitInstallationPath;
192185
target.DeleteIfExists();
193186
target.EnsureParentDirectoryExists();
194187
source.Move(target);
195188

189+
var installDetails = new GitInstaller.GitInstallDetails(gitInstallationPath.Parent, DefaultEnvironment.OnWindows)
190+
{
191+
GitPackageFeed = "http://nope",
192+
GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}",
193+
};
194+
196195
var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, installDetails: installDetails);
197196

198197
var result = gitInstaller.SetupGitIfNeeded();
199198
result.Should().NotBeNull();
200199

201-
Assert.AreEqual(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitDirectory), result.GitInstallationPath);
202-
result.GitExecutablePath.Should().Be(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitDirectory, "cmd", "git" + Environment.ExecutableExtension));
203-
result.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitLfsDirectory, "git-lfs" + Environment.ExecutableExtension));
200+
Assert.AreEqual(gitInstallationPath, result.GitInstallationPath);
201+
result.GitExecutablePath.Should().Be(gitInstallationPath.Combine("cmd", "git" + Environment.ExecutableExtension));
202+
result.GitLfsExecutablePath.Should().Be(gitLfsInstallationPath.Combine("git-lfs" + Environment.ExecutableExtension));
204203
}
205204

206205
[Test]
207206
public void GitLfsIsInstalledIfMissingWithCustomGitPath()
208207
{
209-
var defaultGitInstall = TestBasePath.Combine("DefaultInstall").CreateDirectory();
210-
var customGitInstall = TestBasePath.Combine("CustomGitInstall").CreateDirectory();
211-
212-
var installDetails = new GitInstaller.GitInstallDetails(defaultGitInstall, DefaultEnvironment.OnWindows)
213-
{
214-
GitPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitPackageName}",
215-
GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}",
216-
};
208+
var tempZipExtractPath = TestBasePath.Combine("Temp", "git_zip_extract_zip_paths");
209+
var customGitInstall = TestBasePath.Combine("CustomGitInstall").Combine(GitInstaller.GitInstallDetails.GitDirectory);
217210

218-
var package = Package.Load(Environment, installDetails.GitPackageFeed);
211+
var gitZipUri = new UriString($"http://localhost:{server.Port}/unity/git/windows/git-slim.zip");
219212
var downloader = new Downloader();
220-
downloader.Catch(e => true);
221-
downloader.QueueDownload(package.Uri, installDetails.ZipPath);
213+
downloader.QueueDownload(gitZipUri, tempZipExtractPath);
222214
downloader.RunWithReturn(true);
223215

224-
var tempZipExtractPath = TestBasePath.Combine("Temp", "git_zip_extract_zip_paths");
225-
226216
var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();
227-
ZipHelper.Instance.Extract(installDetails.GitZipPath, gitExtractPath, TaskManager.Token, null);
217+
ZipHelper.Instance.Extract(tempZipExtractPath.Combine(gitZipUri.Filename), gitExtractPath, TaskManager.Token, null);
228218
var source = gitExtractPath;
229219
var target = customGitInstall;
230220
target.DeleteIfExists();
231221
target.EnsureParentDirectoryExists();
232222
source.Move(target);
233223
var gitExec = customGitInstall.Combine("cmd/git.exe");
224+
234225
var state = new GitInstaller.GitInstallationState();
235226
state.GitExecutablePath = gitExec;
236227
Environment.GitInstallationState = state;
237228

229+
var defaultGitInstall = TestBasePath.Combine("DefaultInstall");
230+
231+
var installDetails = new GitInstaller.GitInstallDetails(defaultGitInstall, DefaultEnvironment.OnWindows)
232+
{
233+
GitPackageFeed = "http://nope",
234+
GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}",
235+
};
236+
238237
var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, installDetails: installDetails);
239238

240239
state = gitInstaller.SetupGitIfNeeded();

src/tests/TestWebServer/TestWebServer.csproj

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,31 @@
5151
<Link>files\unity\git\mac\git.zip.md5</Link>
5252
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5353
</None-->
54-
<None Include="files\unity\git\windows\git-lfs.json">
54+
<None Include="..\..\GitHub.Api\PlatformResources\windows\git-lfs.json">
55+
<Link>files\unity\git\windows\git-lfs.json</Link>
5556
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5657
</None>
57-
<None Include="files\unity\git\windows\git-lfs.zip">
58+
<None Include="..\..\GitHub.Api\PlatformResources\windows\git-lfs.zip">
59+
<Link>files\unity\git\windows\git-lfs.zip</Link>
5860
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5961
</None>
60-
<None Include="files\unity\git\windows\git.json">
62+
<None Include="..\..\GitHub.Api\PlatformResources\windows\git.json">
63+
<Link>files\unity\git\windows\git.json</Link>
6164
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6265
</None>
63-
<None Include="files\unity\git\windows\git.zip">
66+
<None Include="..\..\GitHub.Api\PlatformResources\windows\git.zip">
67+
<Link>files\unity\git\windows\git.zip</Link>
6468
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6569
</None>
66-
<None Include="files\unity\git\mac\git-lfs.json">
70+
<None Include="..\..\GitHub.Api\PlatformResources\mac\git-lfs.json">
71+
<Link>files\unity\git\mac\git-lfs.json</Link>
6772
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6873
</None>
69-
<None Include="files\unity\git\mac\git-lfs.zip">
74+
<None Include="..\..\GitHub.Api\PlatformResources\mac\git-lfs.zip">
75+
<Link>files\unity\git\mac\git-lfs.zip</Link>
76+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
77+
</None>
78+
<None Include="files\unity\git\windows\git-slim.zip">
7079
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7180
</None>
7281
<None Include="files\unity\latest.json">

src/tests/TestWebServer/files/unity/git/windows/git-full.zip

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/tests/TestWebServer/files/unity/git/windows/git-lfs.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/TestWebServer/files/unity/git/windows/git-lfs.zip

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/tests/TestWebServer/files/unity/git/windows/git.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/tests/TestWebServer/files/unity/git/windows/gitconfig

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)