@@ -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 }
0 commit comments