@@ -11,10 +11,12 @@ class GitPathView : Subview
11
11
private const string GitInstallTitle = "Git installation" ;
12
12
private const string PathToGit = "Path to Git" ;
13
13
private const string GitPathSaveButton = "Save Path" ;
14
- private const string GitInstallFindButton = "Find install" ;
14
+ private const string UseInternalGitButton = "Use internal git" ;
15
+ private const string FindSystemGitButton = "Find system git" ;
15
16
private const string BrowseButton = "..." ;
16
17
private const string GitInstallBrowseTitle = "Select git binary" ;
17
18
private const string ErrorInvalidPathMessage = "Invalid Path." ;
19
+ private const string ErrorInstallingInternalGit = "Error installing portable git." ;
18
20
private const string ErrorValidatingGitPath = "Error validating Git Path." ;
19
21
private const string ErrorGitNotFoundMessage = "Git not found." ;
20
22
private const string ErrorGitLfsNotFoundMessage = "Git LFS not found." ;
@@ -33,11 +35,15 @@ class GitPathView : Subview
33
35
[ NonSerialized ] private bool isBusy ;
34
36
[ NonSerialized ] private bool gitExecHasChanged ;
35
37
[ NonSerialized ] private bool gitExecutableIsSet ;
38
+ [ NonSerialized ] private string portableGitPath ;
36
39
37
40
public override void InitializeView ( IView parent )
38
41
{
39
42
base . InitializeView ( parent ) ;
40
43
gitExecutableIsSet = Environment . GitExecutablePath . IsInitialized ;
44
+
45
+ var gitInstallDetails = new GitInstaller . GitInstallDetails ( Environment . UserCachePath , Environment . IsWindows ) ;
46
+ portableGitPath = gitInstallDetails . GitExecutablePath ;
41
47
}
42
48
43
49
public override void OnEnable ( )
@@ -112,8 +118,21 @@ public override void OnGUI()
112
118
}
113
119
EditorGUI . EndDisabledGroup ( ) ;
114
120
121
+ // disable if we are not on windows
122
+ // disable if the newPath == portableGitPath
123
+ EditorGUI . BeginDisabledGroup ( ! Environment . IsWindows || Environment . IsWindows && newGitExec == portableGitPath ) ;
124
+ if ( GUILayout . Button ( UseInternalGitButton , GUILayout . ExpandWidth ( false ) ) )
125
+ {
126
+ GUI . FocusControl ( null ) ;
127
+
128
+ Logger . Trace ( "Expected portableGitPath: {0}" , portableGitPath ) ;
129
+ newGitExec = portableGitPath ;
130
+ CheckEnteredGitPath ( ) ;
131
+ }
132
+ EditorGUI . EndDisabledGroup ( ) ;
133
+
115
134
//Find button - for attempting to locate a new install
116
- if ( GUILayout . Button ( GitInstallFindButton , GUILayout . ExpandWidth ( false ) ) )
135
+ if ( GUILayout . Button ( FindSystemGitButton , GUILayout . ExpandWidth ( false ) ) )
117
136
{
118
137
GUI . FocusControl ( null ) ;
119
138
isBusy = true ;
@@ -213,72 +232,105 @@ private void CheckEnteredGitPath()
213
232
214
233
private void ValidateAndSetGitInstallPath ( string value )
215
234
{
216
- //Logger.Trace("Validating Git Path:{0}", value);
235
+ value = value . Trim ( ) ;
217
236
218
- gitVersionErrorMessage = null ;
237
+ if ( value == portableGitPath )
238
+ {
239
+ Logger . Trace ( "Attempting to restore portable Git Path:{0}" , value ) ;
219
240
220
- GitClient . ValidateGitInstall ( value . ToNPath ( ) )
221
- . FinallyInUI ( ( success , exception , result ) =>
222
- {
223
- if ( ! success )
224
- {
225
- Logger . Trace ( ErrorValidatingGitPath ) ;
226
- gitVersionErrorMessage = ErrorValidatingGitPath ;
227
- }
228
- else if ( ! result . IsValid )
229
- {
230
- Logger . Warning (
231
- "Software versions do not meet minimums Git:{0} (Minimum:{1}) GitLfs:{2} (Minimum:{3})" ,
232
- result . GitVersion , Constants . MinimumGitVersion , result . GitLfsVersion ,
233
- Constants . MinimumGitLfsVersion ) ;
241
+ var gitInstaller = new GitInstaller ( Environment , EntryPoint . ApplicationManager . ProcessManager ,
242
+ EntryPoint . ApplicationManager . TaskManager ) ;
234
243
235
- var errorMessageStringBuilder = new StringBuilder ( ) ;
244
+ gitInstaller . SetupGitIfNeeded ( )
245
+ . FinallyInUI ( ( success , exception , result ) =>
246
+ {
247
+ Logger . Trace ( "Setup Git Using the installer:{0}" , success ) ;
236
248
237
- if ( result . GitVersion == null )
249
+ if ( ! success )
238
250
{
239
- errorMessageStringBuilder . Append ( ErrorGitNotFoundMessage ) ;
251
+ Logger . Error ( exception , ErrorInstallingInternalGit ) ;
252
+ gitVersionErrorMessage = ErrorValidatingGitPath ;
240
253
}
241
- else if ( result . GitLfsVersion == null )
254
+ else
242
255
{
243
- errorMessageStringBuilder . Append ( ErrorGitLfsNotFoundMessage ) ;
256
+ Manager . SystemSettings . Unset ( Constants . GitInstallPathKey ) ;
257
+ Environment . GitExecutablePath = result ;
258
+
259
+ gitExecHasChanged = true ;
244
260
}
245
- else
261
+
262
+ isBusy = false ;
263
+ } ) . Start ( ) ;
264
+ }
265
+ else
266
+ {
267
+ //Logger.Trace("Validating Git Path:{0}", value);
268
+
269
+ gitVersionErrorMessage = null ;
270
+
271
+ GitClient . ValidateGitInstall ( value . ToNPath ( ) )
272
+ . FinallyInUI ( ( success , exception , result ) =>
273
+ {
274
+ if ( ! success )
275
+ {
276
+ Logger . Trace ( ErrorValidatingGitPath ) ;
277
+ gitVersionErrorMessage = ErrorValidatingGitPath ;
278
+ }
279
+ else if ( ! result . IsValid )
246
280
{
247
- if ( result . GitVersion < Constants . MinimumGitVersion )
281
+ Logger . Warning (
282
+ "Software versions do not meet minimums Git:{0} (Minimum:{1}) GitLfs:{2} (Minimum:{3})" ,
283
+ result . GitVersion , Constants . MinimumGitVersion , result . GitLfsVersion ,
284
+ Constants . MinimumGitLfsVersion ) ;
285
+
286
+ var errorMessageStringBuilder = new StringBuilder ( ) ;
287
+
288
+ if ( result . GitVersion == null )
248
289
{
249
- errorMessageStringBuilder . AppendFormat ( ErrorMinimumGitVersionMessageFormat ,
250
- result . GitVersion , Constants . MinimumGitVersion ) ;
290
+ errorMessageStringBuilder . Append ( ErrorGitNotFoundMessage ) ;
251
291
}
252
-
253
- if ( result . GitLfsVersion < Constants . MinimumGitLfsVersion )
292
+ else if ( result . GitLfsVersion == null )
254
293
{
255
- if ( errorMessageStringBuilder . Length > 0 )
294
+ errorMessageStringBuilder . Append ( ErrorGitLfsNotFoundMessage ) ;
295
+ }
296
+ else
297
+ {
298
+ if ( result . GitVersion < Constants . MinimumGitVersion )
256
299
{
257
- errorMessageStringBuilder . Append ( Environment . NewLine ) ;
300
+ errorMessageStringBuilder . AppendFormat ( ErrorMinimumGitVersionMessageFormat ,
301
+ result . GitVersion , Constants . MinimumGitVersion ) ;
258
302
}
259
303
260
- errorMessageStringBuilder . AppendFormat ( ErrorMinimumGitLfsVersionMessageFormat ,
261
- result . GitLfsVersion , Constants . MinimumGitLfsVersion ) ;
304
+ if ( result . GitLfsVersion < Constants . MinimumGitLfsVersion )
305
+ {
306
+ if ( errorMessageStringBuilder . Length > 0 )
307
+ {
308
+ errorMessageStringBuilder . Append ( Environment . NewLine ) ;
309
+ }
310
+
311
+ errorMessageStringBuilder . AppendFormat ( ErrorMinimumGitLfsVersionMessageFormat ,
312
+ result . GitLfsVersion , Constants . MinimumGitLfsVersion ) ;
313
+ }
262
314
}
263
- }
264
315
265
- gitVersionErrorMessage = errorMessageStringBuilder . ToString ( ) ;
266
- }
267
- else
268
- {
269
- Logger . Trace ( "Software versions meet minimums Git:{0} GitLfs:{1}" ,
270
- result . GitVersion ,
271
- result . GitLfsVersion ) ;
316
+ gitVersionErrorMessage = errorMessageStringBuilder . ToString ( ) ;
317
+ }
318
+ else
319
+ {
320
+ Logger . Trace ( "Software versions meet minimums Git:{0} GitLfs:{1}" ,
321
+ result . GitVersion ,
322
+ result . GitLfsVersion ) ;
272
323
273
- Manager . SystemSettings . Set ( Constants . GitInstallPathKey , value ) ;
274
- Environment . GitExecutablePath = value . ToNPath ( ) ;
324
+ Manager . SystemSettings . Set ( Constants . GitInstallPathKey , value ) ;
325
+ Environment . GitExecutablePath = value . ToNPath ( ) ;
275
326
276
- gitExecHasChanged = true ;
277
- }
327
+ gitExecHasChanged = true ;
328
+ }
278
329
279
- isBusy = false ;
330
+ isBusy = false ;
280
331
281
- } ) . Start ( ) ;
332
+ } ) . Start ( ) ;
333
+ }
282
334
}
283
335
284
336
public override bool IsBusy
0 commit comments