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

Commit bae457b

Browse files
committed
Fix git installer and git version check tests
Add a slimmed down git installation suitable for testing the git installer process and version checks, so that they won't take so long to execute. Fix a few bugs in the package generation script and in the installer.
1 parent c4ff1cf commit bae457b

File tree

6 files changed

+53
-22
lines changed

6 files changed

+53
-22
lines changed

generate-package.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#!/bin/sh -eu
22
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33
if [ $# -lt 3 ]; then
4-
echo "Usage: generate-package.sh [git|lfs|ghu] [version] [path to file] [host url (optional)] [release notes file (optional)] [message file (optional)]"
4+
echo "Usage: generate-package.sh [git|lfs|ghu] [windows|mac|linux] [version] [path to file] [host url (optional)] [release notes file (optional)] [message file (optional)]"
55
exit 1
66
fi
77

88
URL="http://ghfvs-installer.github.com"
9-
if [ $# -ge 4 ]; then
10-
URL=$4
9+
if [ $# -ge 5 ]; then
10+
URL=$5
1111
fi
1212

1313
if [ "$1" == "git" ]; then
14-
URL="$URL/unity/git"
14+
URL="$URL/unity/git/$2"
1515
fi
1616
if [ "$1" == "lfs" ]; then
17-
URL="$URL/unity/git"
17+
URL="$URL/unity/git/$2"
1818
fi
1919
if [ "$1" == "ghu" ]; then
2020
URL="$URL/unity/releases"
2121
fi
2222

2323
RN=""
2424
MSG=""
25-
if [ $# -ge 5 ]; then
26-
RN="$5"
25+
if [ $# -ge 6 ]; then
26+
RN="$6"
2727
fi
2828

29-
if [ $# -ge 6 ]; then
30-
MSG="$6"
29+
if [ $# -ge 7 ]; then
30+
MSG="$7"
3131
fi
3232

3333
EXEC="mono"
@@ -39,4 +39,4 @@ if [ ! -e "$DIR/build/CommandLine/CommandLine.exe" ]; then
3939
>&2 xbuild /target:CommandLine "$DIR/GitHub.Unity.sln" /verbosity:minimal
4040
fi
4141

42-
"$EXEC""$DIR/build/CommandLine/CommandLine.exe" --gen-package --version "$2" --path "$3" --url "$URL" --rn "$RN" --msg "$MSG"
42+
"$EXEC""$DIR/build/CommandLine/CommandLine.exe" --gen-package --version "$3" --path "$4" --url "$URL" --rn "$RN" --msg "$MSG"

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public GitInstallationState SetupGitIfNeeded()
5757
}
5858

5959
state = VerifyZipFiles(state);
60-
state = GrabZipFromResourcesIfNeeded(state);
6160
state = GetZipsIfNeeded(state);
61+
state = GrabZipFromResourcesIfNeeded(state);
6262
state = ExtractGit(state);
6363
state.GitLastCheckTime = DateTimeOffset.Now;
6464
systemSettings?.Set(Constants.GitInstallationState, state);
@@ -76,6 +76,13 @@ public GitInstallationState VerifyGitFromSettings(GitInstallationState state)
7676

7777
state.GitExecutablePath = gitExecutablePath;
7878
state = ValidateGitVersion(state);
79+
if (state.GitIsValid)
80+
state.GitInstallationPath = state.GitExecutablePath.Parent.Parent;
81+
else
82+
{
83+
state.GitLfsInstallationPath = NPath.Default;
84+
state.GitLfsExecutablePath = NPath.Default;
85+
}
7986
NPath gitLfsPath = ProcessManager.FindExecutableInPath(installDetails.GitLfsExecutable, true, state.GitInstallationPath);
8087
state = ValidateGitLfsVersion(state);
8188
return state;
@@ -94,8 +101,8 @@ private GitInstallationState FindMacGit(GitInstallationState state)
94101
state.GitInstallationPath = gitPath.Parent.Parent;
95102
else
96103
{
97-
state.GitLfsInstallationPath = NPath.Default;
98-
state.GitLfsExecutablePath = NPath.Default;
104+
state.GitInstallationPath = NPath.Default;
105+
state.GitExecutablePath = NPath.Default;
99106
}
100107
}
101108

@@ -137,8 +144,11 @@ private GitInstallationState FindWindowsGit(GitInstallationState state)
137144

138145
private GitInstallationState ValidateGitVersion(GitInstallationState state)
139146
{
140-
if (!state.GitExecutablePath.IsInitialized)
147+
if (!state.GitExecutablePath.IsInitialized || !state.GitExecutablePath.FileExists())
148+
{
149+
state.GitIsValid = false;
141150
return state;
151+
}
142152
var version = new GitVersionTask(cancellationToken)
143153
.Configure(processManager, state.GitExecutablePath, dontSetupGit: true)
144154
.Catch(e => true)
@@ -150,8 +160,11 @@ private GitInstallationState ValidateGitVersion(GitInstallationState state)
150160

151161
private GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
152162
{
153-
if (!state.GitLfsExecutablePath.IsInitialized)
163+
if (!state.GitLfsExecutablePath.IsInitialized || !state.GitLfsExecutablePath.FileExists())
164+
{
165+
state.GitLfsIsValid = false;
154166
return state;
167+
}
155168
var version =
156169
new ProcessTask<TheVersion>(cancellationToken, "version", new LfsVersionOutputProcessor())
157170
.Configure(processManager, state.GitLfsExecutablePath, dontSetupGit: true)
@@ -181,7 +194,7 @@ private GitInstallationState CheckForUpdates(GitInstallationState state)
181194
state.GitLfsPackage = Package.Load(environment, installDetails.GitLfsPackageFeed);
182195
if (state.GitLfsPackage != null)
183196
{
184-
state.GitIsValid = state.GitLfsVersion >= state.GitLfsPackage.Version;
197+
state.GitLfsIsValid = state.GitLfsVersion >= state.GitLfsPackage.Version;
185198
if (!state.GitLfsIsValid)
186199
{
187200
Logger.Trace($"{installDetails.GitLfsExecutablePath} is out of date");

src/tests/IntegrationTests/Installer/GitInstallerTests.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,31 @@ public void GitLfsIsInstalledIfMissingWithCustomGitPath()
213213
{
214214
var defaultGitInstall = TestBasePath.Combine("DefaultInstall").CreateDirectory();
215215
var customGitInstall = TestBasePath.Combine("CustomGitInstall").CreateDirectory();
216-
var gitExec = customGitInstall.Combine("cmd/git.exe");
217-
gitExec.WriteAllText("");
218-
Environment.SystemSettings.Set(Constants.GitInstallPathKey, gitExec.ToString());
219216

220217
var installDetails = new GitInstaller.GitInstallDetails(defaultGitInstall, DefaultEnvironment.OnWindows)
221218
{
222219
GitPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitPackageName}",
223220
GitLfsPackageFeed = $"http://localhost:{server.Port}/unity/git/windows/{GitInstaller.GitInstallDetails.GitLfsPackageName}",
224221
};
225222

223+
var package = Package.Load(Environment, installDetails.GitPackageFeed);
224+
var downloader = new Downloader();
225+
downloader.Catch(e => true);
226+
downloader.QueueDownload(package.Uri, installDetails.ZipPath);
227+
downloader.RunWithReturn(true);
228+
229+
var tempZipExtractPath = TestBasePath.Combine("Temp", "git_zip_extract_zip_paths");
230+
231+
var gitExtractPath = tempZipExtractPath.Combine("git").CreateDirectory();
232+
ZipHelper.Instance.Extract(installDetails.GitZipPath, gitExtractPath, TaskManager.Token, null);
233+
var source = gitExtractPath;
234+
var target = customGitInstall;
235+
target.DeleteIfExists();
236+
target.EnsureParentDirectoryExists();
237+
source.Move(target);
238+
var gitExec = customGitInstall.Combine("cmd/git.exe");
239+
Environment.SystemSettings.Set(Constants.GitInstallPathKey, gitExec.ToString());
240+
226241
var gitInstaller = new GitInstaller(Environment, ProcessManager, TaskManager.Token, Environment.SystemSettings, installDetails: installDetails);
227242

228243
var state = gitInstaller.SetupGitIfNeeded();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:24864bd6ed4d60a516330107932082ae17ae5b98b0819d6cb6eba4a96b7ae0e4
3+
size 83230267
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"md5":"ea5d5a38a6b9e9bc2b10011602c65a0d","url":"http://localhost:50000/unity/git/windows/git.zip","releaseNotes":null,"releaseNotesUrl":null,"message":null,"executableMd5":"50570ed932559f294d1a1361801740b9","version":"2.11.0"}
1+
{"md5":"e0e61633dce7c5aa0ac6ae76c71724ae","url":"http://localhost:50000/unity/git/windows/git.zip","releaseNotes":null,"releaseNotesUrl":null,"message":null,"version":"2.11.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:886979483c46838de1b0a6a4399c2c6e5ff03c6306c17cf46fee595d04dcfe1b
3+
size 30251695

0 commit comments

Comments
 (0)