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

Commit e9e6996

Browse files
committed
Fix resetting to bundled git
1 parent 3d3e745 commit e9e6996

File tree

5 files changed

+37
-39
lines changed

5 files changed

+37
-39
lines changed

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 19 additions & 27 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,9 +39,12 @@ 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 = FindSystemGit(state);
46+
state = SetDefaultPaths(state);
47+
}
4348

4449
state = CheckForUpdates(state);
4550

@@ -111,7 +116,7 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
111116

112117
public GitInstallationState SetDefaultPaths(GitInstallationState state)
113118
{
114-
if (!state.GitIsValid)
119+
if (!state.GitIsValid && environment.IsWindows)
115120
{
116121
state.GitInstallationPath = installDetails.GitInstallationPath;
117122
state.GitExecutablePath = installDetails.GitExecutablePath;
@@ -292,10 +297,10 @@ private GitInstallationState ExtractGit(GitInstallationState state)
292297
});
293298
unzipTask.Progress(p => ((Progress)Progress)?.UpdateProgress(60 + (long)(20 * p.Percentage), 100, unzipTask.Name));
294299
var path = unzipTask.RunWithReturn(true);
295-
var target = state.GitLfsExecutablePath;
300+
var target = state.GitLfsInstallationPath;
296301
if (unzipTask.Successful)
297302
{
298-
var source = path.Combine(installDetails.GitLfsExecutable);
303+
var source = path;
299304
target.DeleteIfExists();
300305
target.EnsureParentDirectoryExists();
301306
source.Move(target);
@@ -335,8 +340,8 @@ public class GitInstallDetails
335340
private const string packageFeed = "http://github-vs.s3.amazonaws.com/unity/git/";
336341
#endif
337342

338-
private const string PackageVersion = "f02737a78695063deace08e96d5042710d3e32db";
339-
private const string PackageName = "PortableGit";
343+
public const string GitDirectory = "git";
344+
public const string GitLfsDirectory = "git-lfs";
340345

341346
private const string gitZip = "git.zip";
342347
private const string gitLfsZip = "git-lfs.zip";
@@ -352,46 +357,33 @@ public GitInstallDetails(NPath baseDataPath, bool onWindows)
352357
GitZipPath = ZipPath.Combine(gitZip);
353358
GitLfsZipPath = ZipPath.Combine(gitLfsZip);
354359

355-
var gitInstallPath = baseDataPath.Combine(PackageNameWithVersion);
356-
GitInstallationPath = gitInstallPath;
360+
GitInstallationPath = baseDataPath.Combine(GitDirectory);
361+
GitExecutablePath = GitInstallationPath.Combine(onWindows ? "cmd" : "bin", "git" + DefaultEnvironment.ExecutableExt);
362+
363+
GitLfsInstallationPath = baseDataPath.Combine(GitLfsDirectory);
364+
GitLfsExecutablePath = GitLfsInstallationPath.Combine("git-lfs" + DefaultEnvironment.ExecutableExt);
357365

358366
if (onWindows)
359367
{
360-
GitExecutable += "git.exe";
361-
GitLfsExecutable += "git-lfs.exe";
362-
GitExecutablePath = gitInstallPath.Combine("cmd", GitExecutable);
363368
GitPackageFeed = packageFeed + $"windows/{GitPackageName}";
364369
GitLfsPackageFeed = packageFeed + $"windows/{GitLfsPackageName}";
365370
}
366371
else
367372
{
368-
GitExecutable = "git";
369-
GitLfsExecutable = "git-lfs";
370-
GitExecutablePath = gitInstallPath.Combine("bin", GitExecutable);
371373
GitPackageFeed = packageFeed + $"mac/{GitPackageName}";
372374
GitLfsPackageFeed = packageFeed + $"mac/{GitLfsPackageName}";
373375
}
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);
382376
}
383377

384378
public NPath ZipPath { get; }
385379
public NPath GitZipPath { get; }
386380
public NPath GitLfsZipPath { get; }
387381
public NPath GitInstallationPath { get; }
388-
public string GitExecutable { get; }
382+
public NPath GitLfsInstallationPath { get; }
389383
public NPath GitExecutablePath { get; }
390-
public string GitLfsExecutable { get; }
391384
public NPath GitLfsExecutablePath { get; }
392385
public UriString GitPackageFeed { get; set; }
393386
public UriString GitLfsPackageFeed { get; set; }
394-
public string PackageNameWithVersion => PackageName + "_" + PackageVersion;
395387
}
396388
}
397389
}

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
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,13 @@ private void ValidateAndSetGitInstallPath()
219219
{
220220
var gitInstaller = new GitInstaller(Environment, Manager.ProcessManager, Manager.CancellationToken);
221221
var state = new GitInstaller.GitInstallationState();
222+
state = gitInstaller.SetDefaultPaths(state);
223+
// on non-windows we only bundle git-lfs
222224
if (!Environment.IsWindows)
225+
{
223226
state.GitExecutablePath = installationState.GitExecutablePath;
227+
state.GitInstallationPath = installationState.GitInstallationPath;
228+
}
224229
state = gitInstaller.SetupGitIfNeeded(state);
225230
if (state.GitIsValid && state.GitLfsIsValid)
226231
{

src/tests/IntegrationTests/BaseIntegrationTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ protected void SetupGit(NPath pathToSetupGitInto, string testName)
156156
path = new UnzipTask(TaskManager.Token, installDetails.GitLfsZipPath, extractPath, null, Environment.FileSystem)
157157
.Catch(e => true)
158158
.RunWithReturn(true);
159-
source = path.Combine(installDetails.GitLfsExecutable);
160-
source.Move(installDetails.GitLfsExecutablePath);
159+
installDetails.GitLfsInstallationPath.EnsureParentDirectoryExists();
160+
path.Move(installDetails.GitLfsInstallationPath);
161161
}
162162

163163
[TestFixtureSetUp]

src/tests/IntegrationTests/Installer/GitInstallerTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public void GitInstallWindows()
6767
var state = gitInstaller.SetupGitIfNeeded();
6868
state.Should().NotBeNull();
6969

70-
Assert.AreEqual(gitInstallationPath.Combine(installDetails.PackageNameWithVersion), state.GitInstallationPath);
71-
state.GitExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "cmd", "git" + Environment.ExecutableExtension));
72-
state.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "mingw32", "libexec", "git-core", "git-lfs" + Environment.ExecutableExtension));
70+
Assert.AreEqual(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitDirectory), state.GitInstallationPath);
71+
state.GitExecutablePath.Should().Be(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitDirectory, "cmd", "git" + Environment.ExecutableExtension));
72+
state.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(GitInstaller.GitInstallDetails.GitLfsDirectory, "git-lfs" + Environment.ExecutableExtension));
7373

7474
Environment.GitInstallationState = state;
7575

@@ -102,7 +102,7 @@ public void MacSkipsInstallWhenSettingsGitExists()
102102
};
103103

104104
var ret = new string[] { gitLfsExecutablePath };
105-
filesystem.GetFiles(Arg.Any<string>(), Arg.Is<string>(installDetails.GitLfsExecutable), Arg.Any<SearchOption>())
105+
filesystem.GetFiles(Arg.Any<string>(), Arg.Is<string>(installDetails.GitLfsExecutablePath.FileName), Arg.Any<SearchOption>())
106106
.Returns(ret);
107107

108108
var settings = Substitute.For<ISettings>();
@@ -141,7 +141,7 @@ public void WindowsSkipsInstallWhenSettingsGitExists()
141141
};
142142

143143
var ret = new string[] { gitLfsExecutablePath };
144-
filesystem.GetFiles(Arg.Any<string>(), Arg.Is<string>(installDetails.GitLfsExecutable), Arg.Any<SearchOption>())
144+
filesystem.GetFiles(Arg.Any<string>(), Arg.Is<string>(installDetails.GitLfsExecutablePath.FileName), Arg.Any<SearchOption>())
145145
.Returns(ret);
146146

147147
var settings = Substitute.For<ISettings>();
@@ -198,9 +198,9 @@ public void GitLfsIsInstalledIfMissing()
198198
var result = gitInstaller.SetupGitIfNeeded();
199199
result.Should().NotBeNull();
200200

201-
Assert.AreEqual(gitInstallationPath.Combine(installDetails.PackageNameWithVersion), result.GitInstallationPath);
202-
result.GitExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "cmd", "git" + Environment.ExecutableExtension));
203-
result.GitLfsExecutablePath.Should().Be(gitInstallationPath.Combine(installDetails.PackageNameWithVersion, "mingw32", "libexec", "git-core", "git-lfs" + Environment.ExecutableExtension));
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));
204204
}
205205

206206
[Test]
@@ -240,8 +240,8 @@ public void GitLfsIsInstalledIfMissingWithCustomGitPath()
240240
state = gitInstaller.SetupGitIfNeeded();
241241
state.Should().NotBeNull();
242242

243-
var gitLfsBasePath = defaultGitInstall.Combine(installDetails.PackageNameWithVersion);
244-
var gitLfsExec = gitLfsBasePath.Combine("mingw32", "libexec", "git-core", "git-lfs.exe");
243+
var gitLfsBasePath = defaultGitInstall.Combine(GitInstaller.GitInstallDetails.GitLfsDirectory);
244+
var gitLfsExec = gitLfsBasePath.Combine("git-lfs.exe");
245245
state.GitInstallationPath.Should().Be(customGitInstall);
246246
state.GitExecutablePath.Should().Be(gitExec);
247247
state.GitLfsInstallationPath.Should().Be(gitLfsExec.Parent);

0 commit comments

Comments
 (0)