@@ -65,6 +65,9 @@ class SettingsView : Subview
6565 private const string EnableTraceLoggingLabel = "Enable Trace Logging" ;
6666 private const string MetricsOptInLabel = "Help us improve by sending anonymous usage data" ;
6767 private const string DefaultRepositoryRemoteName = "origin" ;
68+ private const string BrowseButton = "..." ;
69+ private const string PathToGit = "Path to Git" ;
70+ private const string GitPathSaveButton = "Save Path" ;
6871
6972 [ NonSerialized ] private int newGitIgnoreRulesSelection = - 1 ;
7073
@@ -89,12 +92,19 @@ class SettingsView : Subview
8992 [ SerializeField ] private string newRepositoryRemoteUrl ;
9093 [ SerializeField ] private User cachedUser ;
9194
95+ [ SerializeField ] private string gitExec ;
96+ [ SerializeField ] private string gitExecParent ;
97+ [ SerializeField ] private string gitExecExtension ;
98+ [ SerializeField ] private string newGitExec ;
99+ [ NonSerialized ] private bool gitExecHasChanged ;
100+
92101 public override void OnEnable ( )
93102 {
94103 base . OnEnable ( ) ;
95104 AttachHandlers ( Repository ) ;
96105
97106 remoteHasChanged = true ;
107+ gitExecHasChanged = true ;
98108 }
99109
100110 public override void OnDisable ( )
@@ -180,6 +190,35 @@ private void MaybeUpdateData()
180190 if ( lockedFiles == null )
181191 lockedFiles = new List < GitLock > ( ) ;
182192
193+ if ( gitExecHasChanged )
194+ {
195+ if ( Environment != null )
196+ {
197+ if ( gitExecExtension == null )
198+ {
199+ gitExecExtension = Environment . ExecutableExtension ;
200+
201+ if ( Environment . IsWindows )
202+ {
203+ gitExecExtension = gitExecExtension . TrimStart ( '.' ) ;
204+ }
205+ }
206+
207+ if ( Environment . GitExecutablePath != null )
208+ {
209+ newGitExec = gitExec = Environment . GitExecutablePath . ToString ( ) ;
210+ gitExecParent = Environment . GitExecutablePath . Parent . ToString ( ) ;
211+ }
212+
213+ if ( gitExecParent == null )
214+ {
215+ gitExecParent = Environment . GitInstallPath ;
216+ }
217+ }
218+
219+ gitExecHasChanged = false ;
220+ }
221+
183222 if ( Repository == null )
184223 {
185224 if ( ( cachedUser == null || String . IsNullOrEmpty ( cachedUser . Name ) ) && GitClient != null )
@@ -207,6 +246,7 @@ private void MaybeUpdateData()
207246 newGitEmail = gitEmail = cachedUser . Email ;
208247 userDataHasChanged = false ;
209248 }
249+
210250 return ;
211251 }
212252
@@ -371,20 +411,6 @@ private void OnRepositorySettingsGUI()
371411 EditorGUI . EndDisabledGroup ( ) ;
372412 }
373413
374- private bool ValidateGitInstall ( string path )
375- {
376- if ( String . IsNullOrEmpty ( path ) )
377- return false ;
378- if ( ! GitClient . ValidateGitInstall ( path . ToNPath ( ) ) )
379- {
380- EditorUtility . DisplayDialog ( GitInstallPickInvalidTitle , String . Format ( GitInstallPickInvalidMessage , path ) ,
381- GitInstallPickInvalidOK ) ;
382- return false ;
383- }
384-
385- return true ;
386- }
387-
388414 private bool OnIssuesGUI ( )
389415 {
390416 IList < ProjectConfigurationIssue > projectConfigurationIssues ;
@@ -660,69 +686,74 @@ private void OnGitLfsLocksGUI()
660686
661687 private void OnInstallPathGUI ( )
662688 {
663- string gitExecPath = null ;
664- string gitExecParentPath = null ;
665-
666- string extension = null ;
667-
668- if ( Environment != null )
669- {
670- extension = Environment . ExecutableExtension ;
671-
672- if ( Environment . IsWindows )
673- {
674- extension = extension . TrimStart ( '.' ) ;
675- }
676-
677- if ( Environment . GitExecutablePath != null )
678- {
679- gitExecPath = Environment . GitExecutablePath . ToString ( ) ;
680- gitExecParentPath = Environment . GitExecutablePath . Parent . ToString ( ) ;
681- }
682-
683- if ( gitExecParentPath == null )
684- {
685- gitExecParentPath = Environment . GitInstallPath ;
686- }
687- }
688-
689689 // Install path
690690 GUILayout . Label ( GitInstallTitle , EditorStyles . boldLabel ) ;
691691
692- EditorGUI . BeginDisabledGroup ( isBusy || gitExecPath == null ) ;
692+ EditorGUI . BeginDisabledGroup ( isBusy ) ;
693693 {
694694 // Install path field
695- EditorGUI . BeginChangeCheck ( ) ;
696- {
697- //TODO: Verify necessary value for a non Windows OS
698- Styles . PathField ( ref gitExecPath ,
699- ( ) => EditorUtility . OpenFilePanel ( GitInstallBrowseTitle ,
700- gitExecParentPath ,
701- extension ) , ValidateGitInstall ) ;
702- }
703- if ( EditorGUI . EndChangeCheck ( ) )
695+ //EditorGUI.BeginChangeCheck();
704696 {
705- Logger . Trace ( "Setting GitExecPath: " + gitExecPath ) ;
697+ GUILayout . BeginHorizontal ( ) ;
698+ {
699+ newGitExec = EditorGUILayout . TextField ( PathToGit , newGitExec ) ;
700+
701+ if ( GUILayout . Button ( BrowseButton , EditorStyles . miniButton , GUILayout . Width ( 25 ) ) )
702+ {
703+ GUI . FocusControl ( null ) ;
704+
705+ var newValue = EditorUtility . OpenFilePanel ( GitInstallBrowseTitle ,
706+ gitExecParent ,
707+ gitExecExtension ) ;
706708
707- Manager . SystemSettings . Set ( Constants . GitInstallPathKey , gitExecPath ) ;
708- Environment . GitExecutablePath = gitExecPath . ToNPath ( ) ;
709+ if ( ! string . IsNullOrEmpty ( newValue ) )
710+ {
711+ newGitExec = newValue ;
712+ }
713+ }
714+ }
715+ GUILayout . EndHorizontal ( ) ;
709716 }
710717
711718 GUILayout . Space ( EditorGUIUtility . standardVerticalSpacing ) ;
712719
713720 GUILayout . BeginHorizontal ( ) ;
714721 {
715- // Find button - for attempting to locate a new install
722+ var needsSaving = ! string . IsNullOrEmpty ( newGitExec )
723+ && newGitExec != gitExec
724+ && newGitExec . ToNPath ( ) . FileExists ( ) ;
725+
726+ EditorGUI . BeginDisabledGroup ( ! needsSaving ) ;
727+ {
728+ if ( GUILayout . Button ( GitPathSaveButton , GUILayout . ExpandWidth ( false ) ) )
729+ {
730+ Logger . Trace ( "Saving Git Path:{0}" , newGitExec ) ;
731+
732+ GUI . FocusControl ( null ) ;
733+
734+ Manager . SystemSettings . Set ( Constants . GitInstallPathKey , newGitExec ) ;
735+ Environment . GitExecutablePath = newGitExec . ToNPath ( ) ;
736+ gitExecHasChanged = true ;
737+ }
738+ }
739+ EditorGUI . EndDisabledGroup ( ) ;
740+
741+ //Find button - for attempting to locate a new install
716742 if ( GUILayout . Button ( GitInstallFindButton , GUILayout . ExpandWidth ( false ) ) )
717743 {
744+ GUI . FocusControl ( null ) ;
745+
718746 var task = new ProcessTask < NPath > ( Manager . CancellationToken , new FirstLineIsPathOutputProcessor ( ) )
719747 . Configure ( Manager . ProcessManager , Environment . IsWindows ? "where" : "which" , "git" )
720748 . FinallyInUI ( ( success , ex , path ) =>
721749 {
750+ Logger . Trace ( "Find Git Completed Success:{0} Path:{1}" , success , path ) ;
751+
722752 if ( success && ! string . IsNullOrEmpty ( path ) )
723753 {
754+ Manager . SystemSettings . Set ( Constants . GitInstallPathKey , path ) ;
724755 Environment . GitExecutablePath = path ;
725- GUIUtility . keyboardControl = GUIUtility . hotControl = 0 ;
756+ gitExecHasChanged = true ;
726757 }
727758 } ) ;
728759 }
0 commit comments