@@ -29,6 +29,8 @@ public GitInstaller(IEnvironment environment, IProcessManager processManager,
29
29
30
30
public GitInstallationState SetupGitIfNeeded ( GitInstallationState state = null )
31
31
{
32
+ var skipSystemProbing = state != null ;
33
+
32
34
state = VerifyGitSettings ( state ) ;
33
35
if ( state . GitIsValid && state . GitLfsIsValid )
34
36
{
@@ -37,11 +39,14 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
37
39
return state ;
38
40
}
39
41
40
- if ( environment . IsMac )
41
- state = FindSystemGit ( state ) ;
42
- state = SetDefaultPaths ( state ) ;
42
+ if ( ! skipSystemProbing )
43
+ {
44
+ if ( environment . IsMac )
45
+ state = FindGit ( state ) ;
46
+ }
43
47
44
- state = CheckForUpdates ( state ) ;
48
+ state = SetDefaultPaths ( state ) ;
49
+ state = CheckForGitUpdates ( state ) ;
45
50
46
51
if ( state . GitIsValid && state . GitLfsIsValid )
47
52
{
@@ -53,6 +58,12 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
53
58
state = GetZipsIfNeeded ( state ) ;
54
59
state = GrabZipFromResourcesIfNeeded ( state ) ;
55
60
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 ) ;
56
67
state . GitLastCheckTime = DateTimeOffset . Now ;
57
68
return state ;
58
69
}
@@ -82,6 +93,13 @@ public GitInstallationState VerifyGitSettings(GitInstallationState state = null)
82
93
}
83
94
84
95
public GitInstallationState FindSystemGit ( GitInstallationState state )
96
+ {
97
+ state = FindGit ( state ) ;
98
+ state = FindGitLfs ( state ) ;
99
+ return state ;
100
+ }
101
+
102
+ private GitInstallationState FindGit ( GitInstallationState state )
85
103
{
86
104
if ( ! state . GitIsValid )
87
105
{
@@ -94,7 +112,11 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
94
112
if ( state . GitIsValid )
95
113
state . GitInstallationPath = gitPath . Parent . Parent ;
96
114
}
115
+ return state ;
116
+ }
97
117
118
+ private GitInstallationState FindGitLfs ( GitInstallationState state )
119
+ {
98
120
if ( ! state . GitLfsIsValid )
99
121
{
100
122
var gitLfsPath = new FindExecTask ( "git-lfs" , cancellationToken )
@@ -111,7 +133,7 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
111
133
112
134
public GitInstallationState SetDefaultPaths ( GitInstallationState state )
113
135
{
114
- if ( ! state . GitIsValid )
136
+ if ( ! state . GitIsValid && environment . IsWindows )
115
137
{
116
138
state . GitInstallationPath = installDetails . GitInstallationPath ;
117
139
state . GitExecutablePath = installDetails . GitExecutablePath ;
@@ -150,8 +172,7 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
150
172
state . GitLfsIsValid = false ;
151
173
return state ;
152
174
}
153
- var version =
154
- new ProcessTask < TheVersion > ( cancellationToken , "version" , new LfsVersionOutputProcessor ( ) )
175
+ var version = new ProcessTask < TheVersion > ( cancellationToken , "version" , new LfsVersionOutputProcessor ( ) )
155
176
. Configure ( processManager , state . GitLfsExecutablePath , dontSetupGit : true )
156
177
. Catch ( e => true )
157
178
. RunWithReturn ( true ) ;
@@ -160,29 +181,35 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
160
181
return state ;
161
182
}
162
183
163
- private GitInstallationState CheckForUpdates ( GitInstallationState state )
184
+ private GitInstallationState CheckForGitUpdates ( GitInstallationState state )
164
185
{
165
- state . GitPackage = Package . Load ( environment , installDetails . GitPackageFeed ) ;
166
- if ( state . GitPackage != null )
186
+ if ( state . GitInstallationPath == installDetails . GitInstallationPath )
167
187
{
168
- state . GitIsValid = state . GitVersion >= state . GitPackage . Version ;
169
- if ( state . GitIsValid )
188
+ state . GitPackage = Package . Load ( environment , installDetails . GitPackageFeed ) ;
189
+ if ( state . GitPackage != null )
170
190
{
171
- state . IsCustomGitPath = state . GitExecutablePath != installDetails . GitExecutablePath ;
172
- }
173
- else
174
- {
175
- Logger . Trace ( $ "{ installDetails . GitExecutablePath } is out of date") ;
191
+ state . GitIsValid = state . GitVersion >= state . GitPackage . Version ;
192
+ if ( state . GitIsValid )
193
+ {
194
+ state . IsCustomGitPath = state . GitExecutablePath != installDetails . GitExecutablePath ;
195
+ }
196
+ else
197
+ {
198
+ Logger . Trace ( $ "{ installDetails . GitExecutablePath } is out of date") ;
199
+ }
176
200
}
177
201
}
178
202
179
- state . GitLfsPackage = Package . Load ( environment , installDetails . GitLfsPackageFeed ) ;
180
- if ( state . GitLfsPackage != null )
203
+ if ( state . GitLfsInstallationPath == installDetails . GitLfsInstallationPath )
181
204
{
182
- state . GitLfsIsValid = state . GitLfsVersion >= state . GitLfsPackage . Version ;
183
- if ( ! state . GitLfsIsValid )
205
+ state . GitLfsPackage = Package . Load ( environment , installDetails . GitLfsPackageFeed ) ;
206
+ if ( state . GitLfsPackage != null )
184
207
{
185
- Logger . Trace ( $ "{ installDetails . GitLfsExecutablePath } is out of date") ;
208
+ state . GitLfsIsValid = state . GitLfsVersion >= state . GitLfsPackage . Version ;
209
+ if ( ! state . GitLfsIsValid )
210
+ {
211
+ Logger . Trace ( $ "{ installDetails . GitLfsExecutablePath } is out of date") ;
212
+ }
186
213
}
187
214
}
188
215
return state ;
@@ -218,8 +245,7 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
218
245
return state ;
219
246
220
247
var downloader = new Downloader ( ) ;
221
- downloader
222
- . Catch ( e =>
248
+ downloader . Catch ( e =>
223
249
{
224
250
LogHelper . Trace ( e , "Failed to download" ) ;
225
251
return true ;
@@ -240,11 +266,14 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
240
266
241
267
private GitInstallationState GrabZipFromResourcesIfNeeded ( GitInstallationState state )
242
268
{
243
- if ( ! state . GitZipExists && ! state . GitIsValid )
269
+ if ( ! state . GitZipExists && ! state . GitIsValid && state . GitInstallationPath == installDetails . GitInstallationPath )
244
270
AssemblyResources . ToFile ( ResourceType . Platform , "git.zip" , installDetails . ZipPath , environment ) ;
245
271
state . GitZipExists = installDetails . GitZipPath . FileExists ( ) ;
246
272
247
- if ( ! state . GitLfsZipExists && ! state . GitLfsIsValid )
273
+ if ( state . GitLfsInstallationPath != installDetails . GitLfsInstallationPath )
274
+ return state ;
275
+
276
+ if ( ! state . GitLfsZipExists && ! state . GitLfsIsValid && state . GitLfsInstallationPath == installDetails . GitLfsInstallationPath )
248
277
AssemblyResources . ToFile ( ResourceType . Platform , "git-lfs.zip" , installDetails . ZipPath , environment ) ;
249
278
state . GitLfsZipExists = installDetails . GitLfsZipPath . FileExists ( ) ;
250
279
return state ;
@@ -292,10 +321,10 @@ private GitInstallationState ExtractGit(GitInstallationState state)
292
321
} ) ;
293
322
unzipTask . Progress ( p => ( ( Progress ) Progress ) ? . UpdateProgress ( 60 + ( long ) ( 20 * p . Percentage ) , 100 , unzipTask . Name ) ) ;
294
323
var path = unzipTask . RunWithReturn ( true ) ;
295
- var target = state . GitLfsExecutablePath ;
324
+ var target = state . GitLfsInstallationPath ;
296
325
if ( unzipTask . Successful )
297
326
{
298
- var source = path . Combine ( installDetails . GitLfsExecutable ) ;
327
+ var source = path ;
299
328
target . DeleteIfExists ( ) ;
300
329
target . EnsureParentDirectoryExists ( ) ;
301
330
source . Move ( target ) ;
@@ -335,8 +364,8 @@ public class GitInstallDetails
335
364
private const string packageFeed = "http://github-vs.s3.amazonaws.com/unity/git/" ;
336
365
#endif
337
366
338
- private const string PackageVersion = "f02737a78695063deace08e96d5042710d3e32db " ;
339
- private const string PackageName = "PortableGit " ;
367
+ public const string GitDirectory = "git " ;
368
+ public const string GitLfsDirectory = "git-lfs " ;
340
369
341
370
private const string gitZip = "git.zip" ;
342
371
private const string gitLfsZip = "git-lfs.zip" ;
@@ -352,46 +381,33 @@ public GitInstallDetails(NPath baseDataPath, bool onWindows)
352
381
GitZipPath = ZipPath . Combine ( gitZip ) ;
353
382
GitLfsZipPath = ZipPath . Combine ( gitLfsZip ) ;
354
383
355
- var gitInstallPath = baseDataPath . Combine ( PackageNameWithVersion ) ;
356
- GitInstallationPath = gitInstallPath ;
384
+ GitInstallationPath = baseDataPath . Combine ( GitDirectory ) ;
385
+ GitExecutablePath = GitInstallationPath . Combine ( onWindows ? "cmd" : "bin" , "git" + DefaultEnvironment . ExecutableExt ) ;
386
+
387
+ GitLfsInstallationPath = baseDataPath . Combine ( GitLfsDirectory ) ;
388
+ GitLfsExecutablePath = GitLfsInstallationPath . Combine ( "git-lfs" + DefaultEnvironment . ExecutableExt ) ;
357
389
358
390
if ( onWindows )
359
391
{
360
- GitExecutable += "git.exe" ;
361
- GitLfsExecutable += "git-lfs.exe" ;
362
- GitExecutablePath = gitInstallPath . Combine ( "cmd" , GitExecutable ) ;
363
392
GitPackageFeed = packageFeed + $ "windows/{ GitPackageName } ";
364
393
GitLfsPackageFeed = packageFeed + $ "windows/{ GitLfsPackageName } ";
365
394
}
366
395
else
367
396
{
368
- GitExecutable = "git" ;
369
- GitLfsExecutable = "git-lfs" ;
370
- GitExecutablePath = gitInstallPath . Combine ( "bin" , GitExecutable ) ;
371
397
GitPackageFeed = packageFeed + $ "mac/{ GitPackageName } ";
372
398
GitLfsPackageFeed = packageFeed + $ "mac/{ GitLfsPackageName } ";
373
399
}
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 ) ;
382
400
}
383
401
384
402
public NPath ZipPath { get ; }
385
403
public NPath GitZipPath { get ; }
386
404
public NPath GitLfsZipPath { get ; }
387
405
public NPath GitInstallationPath { get ; }
388
- public string GitExecutable { get ; }
406
+ public NPath GitLfsInstallationPath { get ; }
389
407
public NPath GitExecutablePath { get ; }
390
- public string GitLfsExecutable { get ; }
391
408
public NPath GitLfsExecutablePath { get ; }
392
409
public UriString GitPackageFeed { get ; set ; }
393
410
public UriString GitLfsPackageFeed { get ; set ; }
394
- public string PackageNameWithVersion => PackageName + "_" + PackageVersion ;
395
411
}
396
412
}
397
413
}
0 commit comments