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

Commit 9e424f6

Browse files
Merge pull request #562 from github-for-unity/enhancements/git-setup-download
Functionality to download portable git
2 parents 9a36b39 + 7ce90cf commit 9e424f6

File tree

3 files changed

+80
-19
lines changed

3 files changed

+80
-19
lines changed

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,27 @@ class GitInstaller
6565
private readonly IZipHelper sharpZipLibHelper;
6666
private readonly CancellationToken cancellationToken;
6767
private readonly GitInstallDetails installDetails;
68+
private NPath gitArchiveFilePath;
69+
private NPath gitLfsArchivePath;
6870

6971
public GitInstaller(IEnvironment environment, CancellationToken cancellationToken, GitInstallDetails installDetails)
70-
: this(environment, ZipHelper.Instance, cancellationToken, installDetails)
72+
: this(environment, ZipHelper.Instance, cancellationToken, installDetails, null, null)
7173
{
7274
}
7375

74-
public GitInstaller(IEnvironment environment, IZipHelper sharpZipLibHelper, CancellationToken cancellationToken, GitInstallDetails installDetails)
76+
public GitInstaller(IEnvironment environment, CancellationToken cancellationToken, GitInstallDetails installDetails, NPath gitArchiveFilePath, NPath gitLfsArchivePath)
77+
: this(environment, ZipHelper.Instance, cancellationToken, installDetails, gitArchiveFilePath, gitLfsArchivePath)
78+
{
79+
}
80+
81+
public GitInstaller(IEnvironment environment, IZipHelper sharpZipLibHelper, CancellationToken cancellationToken, GitInstallDetails installDetails, NPath gitArchiveFilePath, NPath gitLfsArchivePath)
7582
{
7683
this.environment = environment;
7784
this.sharpZipLibHelper = sharpZipLibHelper;
7885
this.cancellationToken = cancellationToken;
7986
this.installDetails = installDetails;
87+
this.gitArchiveFilePath = gitArchiveFilePath;
88+
this.gitLfsArchivePath = gitLfsArchivePath;
8089
}
8190

8291
public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
@@ -90,8 +99,7 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
9099
}
91100

92101
new FuncTask<bool>(cancellationToken, IsGitExtracted)
93-
.Then((success, isPortableGitExtracted) => {
94-
102+
.Finally((success, ex, isPortableGitExtracted) => {
95103
Logger.Trace("IsPortableGitExtracted: {0}", isPortableGitExtracted);
96104

97105
if (isPortableGitExtracted)
@@ -104,18 +112,25 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
104112
}
105113
else
106114
{
107-
var tempZipPath = NPath.CreateTempDirectory("git_zip_paths");
108-
var gitArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", tempZipPath, environment);
109-
var gitLfsArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", tempZipPath, environment);
110-
111-
var gitExtractPath = tempZipPath.Combine("git").CreateDirectory();
112-
var gitLfsExtractPath = tempZipPath.Combine("git-lfs").CreateDirectory();
113-
114-
new UnzipTask(cancellationToken, gitArchivePath, gitExtractPath, sharpZipLibHelper, environment.FileSystem, GitInstallDetails.GitExtractedMD5)
115+
ITask downloadFilesTask = null;
116+
if (gitArchiveFilePath == null || gitLfsArchivePath == null)
117+
{
118+
downloadFilesTask = CreateDownloadTask();
119+
}
120+
121+
var tempZipExtractPath = NPath.CreateTempDirectory("git_zip_extract_zip_paths");
122+
var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();
123+
var gitLfsExtractPath = tempZipExtractPath.Combine("git-lfs").CreateDirectory();
124+
125+
var resultTask = new UnzipTask(cancellationToken, gitArchiveFilePath, gitExtractPath, sharpZipLibHelper, environment.FileSystem, GitInstallDetails.GitExtractedMD5)
115126
.Then(new UnzipTask(cancellationToken, gitLfsArchivePath, gitLfsExtractPath, sharpZipLibHelper, environment.FileSystem, GitInstallDetails.GitLfsExtractedMD5))
116127
.Then(() => {
117128
var targetGitLfsExecPath = installDetails.GetGitLfsExecPath(gitExtractPath);
118129
var extractGitLfsExePath = gitLfsExtractPath.Combine(installDetails.GitLfsExec);
130+
131+
Logger.Trace("Moving Git LFS Exe:\"{0}\" to target in tempDirectory:\"{1}\" ", extractGitLfsExePath,
132+
targetGitLfsExecPath);
133+
119134
extractGitLfsExePath.Move(targetGitLfsExecPath);
120135

121136
Logger.Trace("Moving tempDirectory:\"{0}\" to extractTarget:\"{1}\"", gitExtractPath,
@@ -127,10 +142,10 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
127142
Logger.Trace("Deleting targetGitLfsExecPath:\"{0}\"", targetGitLfsExecPath);
128143
targetGitLfsExecPath.DeleteIfExists();
129144

130-
Logger.Trace("Deleting tempZipPath:\"{0}\"", tempZipPath);
131-
tempZipPath.DeleteIfExists();
132-
133-
}).Finally((b, exception) => {
145+
Logger.Trace("Deleting tempZipPath:\"{0}\"", tempZipExtractPath);
146+
tempZipExtractPath.DeleteIfExists();
147+
})
148+
.Finally((b, exception) => {
134149
if (b)
135150
{
136151
Logger.Trace("SetupGitIfNeeded: Success");
@@ -145,11 +160,47 @@ public void SetupGitIfNeeded(ActionTask<NPath> onSuccess, ITask onFailure)
145160

146161
onFailure.Start();
147162
}
148-
}).Start();
163+
});
164+
165+
if (downloadFilesTask != null)
166+
{
167+
resultTask = downloadFilesTask.Then(resultTask);
168+
}
169+
170+
resultTask.Start();
149171
}
150172
}).Start();
151173
}
152174

175+
private ITask CreateDownloadTask()
176+
{
177+
var tempZipPath = NPath.CreateTempDirectory("git_zip_paths");
178+
gitArchiveFilePath = tempZipPath.Combine("git.zip");
179+
gitLfsArchivePath = tempZipPath.Combine("git-lfs.zip");
180+
181+
var downloadGitMd5Task = new DownloadTextTask(CancellationToken.None,
182+
"https://ghfvs-installer.github.com/unity/portable_git/git.zip.MD5.txt");
183+
184+
var downloadGitTask = new DownloadTask(CancellationToken.None, environment.FileSystem,
185+
"https://ghfvs-installer.github.com/unity/portable_git/git.zip", gitArchiveFilePath, retryCount: 1);
186+
187+
var downloadGitLfsMd5Task = new DownloadTextTask(CancellationToken.None,
188+
"https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip.MD5.txt");
189+
190+
var downloadGitLfsTask = new DownloadTask(CancellationToken.None, environment.FileSystem,
191+
"https://ghfvs-installer.github.com/unity/portable_git/git-lfs.zip", gitLfsArchivePath, retryCount: 1);
192+
193+
return downloadGitMd5Task.Then((b, s) => {
194+
downloadGitTask.ValidationHash = s;
195+
})
196+
.Then(downloadGitTask)
197+
.Then(downloadGitLfsMd5Task)
198+
.Then((b, s) => {
199+
downloadGitLfsTask.ValidationHash = s;
200+
})
201+
.Then(downloadGitLfsTask);
202+
}
203+
153204
private bool IsGitExtracted()
154205
{
155206
if (!installDetails.GitInstallPath.DirectoryExists())

src/tests/IntegrationTests/BasePlatformIntegrationTest.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ protected void InitializePlatform(NPath repoPath, NPath environmentPath, bool en
3535

3636
var applicationDataPath = Environment.GetSpecialFolder(System.Environment.SpecialFolder.LocalApplicationData).ToNPath();
3737
var installDetails = new GitInstallDetails(applicationDataPath, true);
38-
var gitInstaller = new GitInstaller(Environment, CancellationToken.None, installDetails);
38+
39+
var zipArchivesPath = TestBasePath.Combine("ZipArchives").CreateDirectory();
40+
var gitArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment);
41+
var gitLfsArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment);
42+
43+
var gitInstaller = new GitInstaller(Environment, CancellationToken.None, installDetails, gitArchivePath, gitLfsArchivePath);
3944

4045
NPath result = null;
4146
Exception ex = null;

src/tests/IntegrationTests/Installer/GitInstallerTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ public void GitInstallTest()
2222

2323
var installDetails = new GitInstallDetails(gitInstallationPath, DefaultEnvironment.OnWindows);
2424

25-
var gitInstaller = new GitInstaller(Environment, CancellationToken.None, installDetails);
25+
var zipArchivesPath = TestBasePath.Combine("ZipArchives").CreateDirectory();
26+
27+
var gitArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git.zip", zipArchivesPath, Environment);
28+
var gitLfsArchivePath = AssemblyResources.ToFile(ResourceType.Platform, "git-lfs.zip", zipArchivesPath, Environment);
29+
30+
var gitInstaller = new GitInstaller(Environment, CancellationToken.None, installDetails, gitArchivePath, gitLfsArchivePath);
2631

2732
var autoResetEvent = new AutoResetEvent(false);
2833

0 commit comments

Comments
 (0)