@@ -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,11 +39,14 @@ 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 = FindGit ( state ) ;
46+ }
4347
44- state = CheckForUpdates ( state ) ;
48+ state = SetDefaultPaths ( state ) ;
49+ state = CheckForGitUpdates ( state ) ;
4550
4651 if ( state . GitIsValid && state . GitLfsIsValid )
4752 {
@@ -53,6 +58,12 @@ public GitInstallationState SetupGitIfNeeded(GitInstallationState state = null)
5358 state = GetZipsIfNeeded ( state ) ;
5459 state = GrabZipFromResourcesIfNeeded ( state ) ;
5560 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 ) ;
5667 state . GitLastCheckTime = DateTimeOffset . Now ;
5768 return state ;
5869 }
@@ -82,6 +93,13 @@ public GitInstallationState VerifyGitSettings(GitInstallationState state = null)
8293 }
8394
8495 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 )
85103 {
86104 if ( ! state . GitIsValid )
87105 {
@@ -94,7 +112,11 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
94112 if ( state . GitIsValid )
95113 state . GitInstallationPath = gitPath . Parent . Parent ;
96114 }
115+ return state ;
116+ }
97117
118+ private GitInstallationState FindGitLfs ( GitInstallationState state )
119+ {
98120 if ( ! state . GitLfsIsValid )
99121 {
100122 var gitLfsPath = new FindExecTask ( "git-lfs" , cancellationToken )
@@ -111,7 +133,7 @@ public GitInstallationState FindSystemGit(GitInstallationState state)
111133
112134 public GitInstallationState SetDefaultPaths ( GitInstallationState state )
113135 {
114- if ( ! state . GitIsValid )
136+ if ( ! state . GitIsValid && environment . IsWindows )
115137 {
116138 state . GitInstallationPath = installDetails . GitInstallationPath ;
117139 state . GitExecutablePath = installDetails . GitExecutablePath ;
@@ -150,8 +172,7 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
150172 state . GitLfsIsValid = false ;
151173 return state ;
152174 }
153- var version =
154- new ProcessTask < TheVersion > ( cancellationToken , "version" , new LfsVersionOutputProcessor ( ) )
175+ var version = new ProcessTask < TheVersion > ( cancellationToken , "version" , new LfsVersionOutputProcessor ( ) )
155176 . Configure ( processManager , state . GitLfsExecutablePath , dontSetupGit : true )
156177 . Catch ( e => true )
157178 . RunWithReturn ( true ) ;
@@ -160,29 +181,35 @@ public GitInstallationState ValidateGitLfsVersion(GitInstallationState state)
160181 return state ;
161182 }
162183
163- private GitInstallationState CheckForUpdates ( GitInstallationState state )
184+ private GitInstallationState CheckForGitUpdates ( GitInstallationState state )
164185 {
165- state . GitPackage = Package . Load ( environment , installDetails . GitPackageFeed ) ;
166- if ( state . GitPackage != null )
186+ if ( state . GitInstallationPath == installDetails . GitInstallationPath )
167187 {
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 )
170190 {
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+ }
176200 }
177201 }
178202
179- state . GitLfsPackage = Package . Load ( environment , installDetails . GitLfsPackageFeed ) ;
180- if ( state . GitLfsPackage != null )
203+ if ( state . GitLfsInstallationPath == installDetails . GitLfsInstallationPath )
181204 {
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 )
184207 {
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+ }
186213 }
187214 }
188215 return state ;
@@ -218,8 +245,7 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
218245 return state ;
219246
220247 var downloader = new Downloader ( ) ;
221- downloader
222- . Catch ( e =>
248+ downloader . Catch ( e =>
223249 {
224250 LogHelper . Trace ( e , "Failed to download" ) ;
225251 return true ;
@@ -240,11 +266,14 @@ private GitInstallationState GetZipsIfNeeded(GitInstallationState state)
240266
241267 private GitInstallationState GrabZipFromResourcesIfNeeded ( GitInstallationState state )
242268 {
243- if ( ! state . GitZipExists && ! state . GitIsValid )
269+ if ( ! state . GitZipExists && ! state . GitIsValid && state . GitInstallationPath == installDetails . GitInstallationPath )
244270 AssemblyResources . ToFile ( ResourceType . Platform , "git.zip" , installDetails . ZipPath , environment ) ;
245271 state . GitZipExists = installDetails . GitZipPath . FileExists ( ) ;
246272
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 )
248277 AssemblyResources . ToFile ( ResourceType . Platform , "git-lfs.zip" , installDetails . ZipPath , environment ) ;
249278 state . GitLfsZipExists = installDetails . GitLfsZipPath . FileExists ( ) ;
250279 return state ;
@@ -292,10 +321,10 @@ private GitInstallationState ExtractGit(GitInstallationState state)
292321 } ) ;
293322 unzipTask . Progress ( p => ( ( Progress ) Progress ) ? . UpdateProgress ( 60 + ( long ) ( 20 * p . Percentage ) , 100 , unzipTask . Name ) ) ;
294323 var path = unzipTask . RunWithReturn ( true ) ;
295- var target = state . GitLfsExecutablePath ;
324+ var target = state . GitLfsInstallationPath ;
296325 if ( unzipTask . Successful )
297326 {
298- var source = path . Combine ( installDetails . GitLfsExecutable ) ;
327+ var source = path ;
299328 target . DeleteIfExists ( ) ;
300329 target . EnsureParentDirectoryExists ( ) ;
301330 source . Move ( target ) ;
@@ -335,8 +364,8 @@ public class GitInstallDetails
335364 private const string packageFeed = "http://github-vs.s3.amazonaws.com/unity/git/" ;
336365#endif
337366
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 " ;
340369
341370 private const string gitZip = "git.zip" ;
342371 private const string gitLfsZip = "git-lfs.zip" ;
@@ -352,46 +381,33 @@ public GitInstallDetails(NPath baseDataPath, bool onWindows)
352381 GitZipPath = ZipPath . Combine ( gitZip ) ;
353382 GitLfsZipPath = ZipPath . Combine ( gitLfsZip ) ;
354383
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 ) ;
357389
358390 if ( onWindows )
359391 {
360- GitExecutable += "git.exe" ;
361- GitLfsExecutable += "git-lfs.exe" ;
362- GitExecutablePath = gitInstallPath . Combine ( "cmd" , GitExecutable ) ;
363392 GitPackageFeed = packageFeed + $ "windows/{ GitPackageName } ";
364393 GitLfsPackageFeed = packageFeed + $ "windows/{ GitLfsPackageName } ";
365394 }
366395 else
367396 {
368- GitExecutable = "git" ;
369- GitLfsExecutable = "git-lfs" ;
370- GitExecutablePath = gitInstallPath . Combine ( "bin" , GitExecutable ) ;
371397 GitPackageFeed = packageFeed + $ "mac/{ GitPackageName } ";
372398 GitLfsPackageFeed = packageFeed + $ "mac/{ GitLfsPackageName } ";
373399 }
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 ) ;
382400 }
383401
384402 public NPath ZipPath { get ; }
385403 public NPath GitZipPath { get ; }
386404 public NPath GitLfsZipPath { get ; }
387405 public NPath GitInstallationPath { get ; }
388- public string GitExecutable { get ; }
406+ public NPath GitLfsInstallationPath { get ; }
389407 public NPath GitExecutablePath { get ; }
390- public string GitLfsExecutable { get ; }
391408 public NPath GitLfsExecutablePath { get ; }
392409 public UriString GitPackageFeed { get ; set ; }
393410 public UriString GitLfsPackageFeed { get ; set ; }
394- public string PackageNameWithVersion => PackageName + "_" + PackageVersion ;
395411 }
396412 }
397413}
0 commit comments