@@ -11,48 +11,41 @@ public class GitInstaller
1111
1212 private readonly IEnvironment environment ;
1313 private readonly IProcessManager processManager ;
14- private readonly ISettings systemSettings ;
1514 private readonly GitInstallDetails installDetails ;
1615 private readonly IZipHelper sharpZipLibHelper ;
1716
1817 public IProgress Progress { get ; set ; }
1918
2019 public GitInstaller ( IEnvironment environment , IProcessManager processManager ,
2120 CancellationToken token ,
22- ISettings systemSettings ,
2321 GitInstallDetails installDetails = null )
2422 {
2523 this . environment = environment ;
2624 this . processManager = processManager ;
27- this . systemSettings = systemSettings ;
2825 this . sharpZipLibHelper = ZipHelper . Instance ;
2926 this . cancellationToken = token ;
3027 this . installDetails = installDetails ?? new GitInstallDetails ( environment . UserCachePath , environment . IsWindows ) ;
3128 }
3229
33- public GitInstallationState SetupGitIfNeeded ( )
30+ public GitInstallationState SetupGitIfNeeded ( GitInstallationState state = null )
3431 {
35- var state = new GitInstallationState ( ) ;
36- state = VerifyGitFromSettings ( state ) ;
32+ state = VerifyGitSettings ( state ) ;
3733 if ( state . GitIsValid && state . GitLfsIsValid )
3834 {
3935 Logger . Trace ( "Using git install path from settings: {0}" , state . GitExecutablePath ) ;
4036 state . GitLastCheckTime = DateTimeOffset . Now ;
41- systemSettings ? . Set ( Constants . GitInstallationState , state ) ;
4237 return state ;
4338 }
4439
45- if ( environment . IsWindows )
46- state = FindWindowsGit ( state ) ;
47- else
48- state = FindMacGit ( state ) ;
40+ if ( environment . IsMac )
41+ state = FindSystemGit ( state ) ;
42+ state = SetDefaultPaths ( state ) ;
4943
5044 state = CheckForUpdates ( state ) ;
5145
5246 if ( state . GitIsValid && state . GitLfsIsValid )
5347 {
5448 state . GitLastCheckTime = DateTimeOffset . Now ;
55- systemSettings ? . Set ( Constants . GitInstallationState , state ) ;
5649 return state ;
5750 }
5851
@@ -61,35 +54,42 @@ public GitInstallationState SetupGitIfNeeded()
6154 state = GrabZipFromResourcesIfNeeded ( state ) ;
6255 state = ExtractGit ( state ) ;
6356 state . GitLastCheckTime = DateTimeOffset . Now ;
64- systemSettings ? . Set ( Constants . GitInstallationState , state ) ;
6557 return state ;
6658 }
6759
68- public GitInstallationState VerifyGitFromSettings ( GitInstallationState state )
60+ public GitInstallationState VerifyGitSettings ( GitInstallationState state = null )
6961 {
70- if ( systemSettings == null )
62+ state = state ?? environment . GitInstallationState ;
63+ if ( ! state . GitExecutablePath . IsInitialized && ! state . GitLfsExecutablePath . IsInitialized )
7164 return state ;
7265
73- NPath gitExecutablePath = systemSettings . Get ( Constants . GitInstallPathKey ) . ToNPath ( ) ;
74- if ( ! gitExecutablePath . IsInitialized || ! gitExecutablePath . FileExists ( ) )
75- return state ;
76-
77- state . GitExecutablePath = gitExecutablePath ;
7866 state = ValidateGitVersion ( state ) ;
7967 if ( state . GitIsValid )
8068 state . GitInstallationPath = state . GitExecutablePath . Parent . Parent ;
81- state . GitLfsExecutablePath = ProcessManager . FindExecutableInPath ( installDetails . GitLfsExecutable , true , state . GitInstallationPath ) ;
69+
70+ var isDefaultGitLfs = ! state . GitLfsExecutablePath . IsInitialized || state . GitLfsInstallationPath == state . GitInstallationPath ;
71+ if ( isDefaultGitLfs )
72+ state . GitLfsExecutablePath = ProcessManager . FindExecutableInPath ( installDetails . GitLfsExecutable , true , state . GitInstallationPath ) ;
73+
8274 state = ValidateGitLfsVersion ( state ) ;
75+
8376 if ( state . GitLfsIsValid )
84- state . GitLfsInstallationPath = state . GitInstallationPath ;
77+ {
78+ if ( isDefaultGitLfs )
79+ state . GitLfsInstallationPath = state . GitInstallationPath ;
80+ else
81+ state . GitLfsInstallationPath = state . GitLfsExecutablePath . Parent ;
82+ }
83+
8584 return state ;
8685 }
8786
88- private GitInstallationState FindMacGit ( GitInstallationState state )
87+ public GitInstallationState FindSystemGit ( GitInstallationState state )
8988 {
9089 if ( ! state . GitIsValid )
9190 {
92- var gitPath = new FindExecTask ( "git" , cancellationToken ) . Configure ( processManager , dontSetupGit : true )
91+ var gitPath = new FindExecTask ( "git" , cancellationToken )
92+ . Configure ( processManager , dontSetupGit : true )
9393 . Catch ( e => true )
9494 . RunWithReturn ( true ) ;
9595 state . GitExecutablePath = gitPath ;
@@ -107,17 +107,12 @@ private GitInstallationState FindMacGit(GitInstallationState state)
107107 state . GitLfsExecutablePath = gitLfsPath ;
108108 state = ValidateGitLfsVersion ( state ) ;
109109 if ( state . GitLfsIsValid )
110- state . GitLfsInstallationPath = gitLfsPath . Parent . Parent ;
111- else
112- {
113- state . GitLfsInstallationPath = installDetails . GitInstallationPath ;
114- state . GitLfsExecutablePath = installDetails . GitLfsExecutablePath ;
115- }
110+ state . GitLfsInstallationPath = gitLfsPath . Parent ;
116111 }
117112 return state ;
118113 }
119114
120- private GitInstallationState FindWindowsGit ( GitInstallationState state )
115+ public GitInstallationState SetDefaultPaths ( GitInstallationState state )
121116 {
122117 if ( ! state . GitIsValid )
123118 {
@@ -128,8 +123,11 @@ private GitInstallationState FindWindowsGit(GitInstallationState state)
128123
129124 if ( ! state . GitLfsIsValid )
130125 {
131- state . GitLfsInstallationPath = installDetails . GitInstallationPath ;
132126 state . GitLfsExecutablePath = installDetails . GitLfsExecutablePath ;
127+ if ( state . GitIsValid && state . GitInstallationPath != installDetails . GitInstallationPath )
128+ state . GitLfsInstallationPath = state . GitLfsExecutablePath . Parent ;
129+ else
130+ state . GitLfsInstallationPath = installDetails . GitInstallationPath ;
133131 state = ValidateGitLfsVersion ( state ) ;
134132 }
135133 return state ;
0 commit comments