Skip to content

Commit b0e3fd3

Browse files
authored
Merge pull request Unity-Technologies#2 from Unity-Technologies/fixes/1-installer-throws
Fix issues with the git installer not handling a failed update check properly
2 parents ea3a3b3 + c5286cb commit b0e3fd3

File tree

13 files changed

+336
-187
lines changed

13 files changed

+336
-187
lines changed

package.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh -eu
2+
{ set +x; } 2>/dev/null
3+
SOURCE="${BASH_SOURCE[0]}"
4+
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
5+
6+
dotnet tool install --tool-path . nbgv || true
7+
pushd $DIR/src/com.unity.git.api
8+
version=$($DIR/nbgv get-version|grep AssemblyInformationalVersion|cut -d' ' -f2)
9+
popd
10+
11+
echo "Packaging version $version"
12+
scripts/create-packages.sh -v $version -t "$DIR/PackageSources" -u -p

packaging/create-unity-packages/src/upmPackager.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ export class UpmPackager extends Packager {
1212

1313
public async prepare(sourcePath: string, version: string, ignores: Ignores, outputPath: string, baseInstallationPath?: string) : Promise<string | undefined> {
1414
const ret = await super.prepare(sourcePath, version, ignores, outputPath, baseInstallationPath);
15+
1516
var today = new Date().toISOString().substring(0, 10);
16-
await asyncfile.writeTextFile(p.join(outputPath, "CHANGELOG.md"), `# Changelog
17+
const changelogFile = p.join(outputPath, "CHANGELOG.md");
18+
const changelogHeader = '# Changelog'
19+
const changelogEntryHeader = `## [${version}] - ${today}`;
20+
let changelog = '';
21+
22+
if (await asyncfile.exists(changelogFile)) {
23+
changelog = await asyncfile.readTextFile(changelogFile);
24+
}
1725

18-
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
26+
changelog = `${changelogHeader}
1927
20-
## [${version}] - ${today}
21-
`
22-
);
28+
${changelogEntryHeader}
29+
${changelog}
30+
`;
31+
32+
await asyncfile.writeTextFile(changelogFile, changelog);
2333
return ret;
2434
}
2535

scripts/create-packages.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ while (( "$#" )); do
2727
;;
2828
-u|--skipUnity)
2929
FLAGS="$FLAGS $1"
30-
shift 2
30+
shift
3131
;;
3232
-p|--skipPackman)
3333
FLAGS="$FLAGS $1"
34-
shift 2
34+
shift
3535
;;
3636
-m|--skipUpm)
3737
FLAGS="$FLAGS $1"
38-
shift 2
38+
shift
3939
;;
4040
--) # end argument parsing
4141
shift

src/com.unity.git.api/Api/Installer/DugiteReleaseManifest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public static DugiteReleaseManifest Load(NPath localCacheFile, UriString package
7676
{
7777
DugiteReleaseManifest package = null;
7878
var filename = localCacheFile.FileName;
79+
var cacheDir = localCacheFile.Parent;
7980
var key = localCacheFile.FileNameWithoutExtension + "_updatelastCheckTime";
8081
var now = DateTimeOffset.Now;
8182

@@ -96,8 +97,7 @@ public static DugiteReleaseManifest Load(NPath localCacheFile, UriString package
9697
if (!localCacheFile.IsInitialized)
9798
{
9899
// try from assembly resources
99-
localCacheFile = AssemblyResources.ToFile(ResourceType.Platform, packageFeed.Filename,
100-
localCacheFile.Parent, environment);
100+
localCacheFile = AssemblyResources.ToFile(ResourceType.Platform, filename, cacheDir, environment);
101101
}
102102

103103
if (localCacheFile.IsInitialized)

src/com.unity.git.api/Api/Installer/GitInstaller.cs

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,10 @@ private GitInstallationState SetupGitIfNeeded()
5353
{
5454
UpdateTask("Setting up git...", 100);
5555

56-
var skipSystemProbing = currentState != null;
56+
bool skipSystemProbing = currentState != null;
5757

5858
try
5959
{
60-
6160
currentState = VerifyGitSettings(currentState);
6261
if (currentState.GitIsValid && currentState.GitLfsIsValid)
6362
{
@@ -66,11 +65,11 @@ private GitInstallationState SetupGitIfNeeded()
6665
return currentState;
6766
}
6867

69-
if (!skipSystemProbing)
70-
{
71-
if (environment.IsMac)
72-
currentState = FindGit(currentState);
73-
}
68+
//if (!skipSystemProbing)
69+
//{
70+
// if (environment.IsMac)
71+
// currentState = FindGit(currentState);
72+
//}
7473

7574
currentState = SetDefaultPaths(currentState);
7675
currentState = CheckForGitUpdates(currentState);
@@ -85,11 +84,17 @@ private GitInstallationState SetupGitIfNeeded()
8584
currentState = GetZipsIfNeeded(currentState);
8685
currentState = ExtractGit(currentState);
8786

88-
// if installing from zip failed (internet down maybe?), try to find a usable system git
89-
if (!currentState.GitIsValid && currentState.GitInstallationPath == installDetails.GitInstallationPath)
90-
currentState = FindGit(currentState);
91-
if (!currentState.GitLfsIsValid && currentState.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
92-
currentState = FindGitLfs(currentState);
87+
if (!skipSystemProbing)
88+
{
89+
// if installing from zip failed (internet down maybe?), try to find a usable system git
90+
if (!currentState.GitIsValid &&
91+
currentState.GitInstallationPath == installDetails.GitInstallationPath)
92+
currentState = FindGit(currentState);
93+
if (!currentState.GitLfsIsValid &&
94+
currentState.GitLfsInstallationPath == installDetails.GitLfsInstallationPath)
95+
currentState = FindGitLfs(currentState);
96+
}
97+
9398
currentState.GitLastCheckTime = DateTimeOffset.Now;
9499
return currentState;
95100
}
@@ -229,7 +234,7 @@ private GitInstallationState CheckForGitUpdates(GitInstallationState state)
229234
if (state.GitInstallationPath != installDetails.GitInstallationPath)
230235
return state;
231236

232-
state.GitPackage = DugiteReleaseManifest.Load(installDetails.GitManifest, installDetails.GitPackageFeed, environment);
237+
state.GitPackage = DugiteReleaseManifest.Load(installDetails.GitManifest, GitInstallDetails.GitPackageFeed, environment);
233238
if (state.GitPackage == null)
234239
return state;
235240

@@ -327,19 +332,81 @@ private GitInstallationState ExtractGit(GitInstallationState state)
327332

328333
public class GitInstallationState
329334
{
330-
public bool GitIsValid { get; set; }
331-
public bool GitLfsIsValid { get; set; }
332-
public bool GitZipExists { get; set; }
333-
public NPath GitZipPath { get; set; }
334-
public NPath GitInstallationPath { get; set; }
335-
public NPath GitExecutablePath { get; set; }
336-
public NPath GitLfsInstallationPath { get; set; }
337-
public NPath GitLfsExecutablePath { get; set; }
338-
public DugiteReleaseManifest GitPackage { get; set; }
335+
private readonly Dictionary<string, object> fields = new Dictionary<string, object>();
336+
337+
private T TryGetField<T>(string field)
338+
{
339+
if (fields.TryGetValue(field, out object val))
340+
{
341+
return (T)val;
342+
}
343+
return default(T);
344+
}
345+
346+
public bool GitIsValid { get => TryGetField<bool>(nameof(GitIsValid)); set => fields[nameof(GitIsValid)] = value; }
347+
public bool GitLfsIsValid { get => TryGetField<bool>(nameof(GitLfsIsValid)); set => fields[nameof(GitLfsIsValid)] = value; }
348+
public bool GitZipExists { get => TryGetField<bool>(nameof(GitZipExists)); set => fields[nameof(GitZipExists)] = value; }
349+
public NPath GitZipPath { get => TryGetField<NPath>(nameof(GitZipPath)); set => fields[nameof(GitZipPath)] = value; }
350+
public NPath GitInstallationPath { get => TryGetField<NPath>(nameof(GitInstallationPath)); set => fields[nameof(GitInstallationPath)] = value; }
351+
public NPath GitExecutablePath { get => TryGetField<NPath>(nameof(GitExecutablePath)); set => fields[nameof(GitExecutablePath)] = value; }
352+
public NPath GitLfsInstallationPath { get => TryGetField<NPath>(nameof(GitLfsInstallationPath)); set => fields[nameof(GitLfsInstallationPath)] = value; }
353+
public NPath GitLfsExecutablePath { get => TryGetField<NPath>(nameof(GitLfsExecutablePath)); set => fields[nameof(GitLfsExecutablePath)] = value; }
354+
public DugiteReleaseManifest GitPackage { get => TryGetField<DugiteReleaseManifest>(nameof(GitPackage)); set => fields[nameof(GitPackage)] = value; }
339355
public DateTimeOffset GitLastCheckTime { get; set; }
340-
public bool IsCustomGitPath { get; set; }
341-
public TheVersion GitVersion { get; set; }
342-
public TheVersion GitLfsVersion { get; set; }
356+
public bool IsCustomGitPath { get => TryGetField<bool>(nameof(IsCustomGitPath)); set => fields[nameof(IsCustomGitPath)] = value; }
357+
public TheVersion GitVersion { get => TryGetField<TheVersion>(nameof(GitVersion)); set => fields[nameof(GitVersion)] = value; }
358+
public TheVersion GitLfsVersion { get => TryGetField<TheVersion>(nameof(GitLfsVersion)); set => fields[nameof(GitLfsVersion)] = value; }
359+
360+
public GitInstallationState()
361+
{
362+
GitIsValid = GitLfsIsValid = GitZipExists = IsCustomGitPath = default(bool);
363+
GitZipPath = GitInstallationPath = GitExecutablePath = GitLfsInstallationPath = GitLfsExecutablePath = default(NPath);
364+
GitPackage = default(DugiteReleaseManifest);
365+
GitVersion = GitLfsVersion = default(TheVersion);
366+
}
367+
368+
public override int GetHashCode()
369+
{
370+
int hash = 17;
371+
foreach (var val in fields.Values)
372+
{
373+
hash *= 23 + (val?.GetHashCode() ?? 0);
374+
}
375+
return hash;
376+
}
377+
378+
public override bool Equals(object other)
379+
{
380+
if (other is GitInstallationState state)
381+
return Equals(state);
382+
return false;
383+
}
384+
385+
public bool Equals(GitInstallationState other)
386+
{
387+
if ((object)other == null)
388+
return false;
389+
return GetHashCode() == other.GetHashCode();
390+
}
391+
392+
public static bool operator ==(GitInstallationState lhs, GitInstallationState rhs)
393+
{
394+
// If both are null, or both are same instance, return true.
395+
if (ReferenceEquals(lhs, rhs))
396+
return true;
397+
398+
// If one is null, but not both, return false.
399+
if (((object)lhs == null) || ((object)rhs == null))
400+
return false;
401+
402+
// Return true if the fields match:
403+
return Equals(lhs.fields, rhs.fields);
404+
}
405+
406+
public static bool operator !=(GitInstallationState lhs, GitInstallationState rhs)
407+
{
408+
return !(lhs == rhs);
409+
}
343410
}
344411

345412
public class GitInstallDetails
@@ -380,7 +447,7 @@ public GitInstallationState GetDefaults()
380447
public NPath GitLfsInstallationPath { get; }
381448
public NPath GitExecutablePath { get; }
382449
public NPath GitLfsExecutablePath { get; }
383-
public UriString GitPackageFeed { get; set; } = packageFeed;
450+
public static UriString GitPackageFeed { get; set; } = packageFeed;
384451
public NPath GitManifest { get; set; }
385452
}
386453
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
### Fixes
3+
4+
- [#1](https://github.com/Unity-Technologies/Git-for-Unity/issues/4) - GitInstaller throws after failing to download the update manifest

0 commit comments

Comments
 (0)