2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Linq ;
5
+ using System . Text ;
5
6
using System . Threading . Tasks ;
6
7
using UnityEditor ;
7
8
using UnityEngine ;
@@ -11,35 +12,34 @@ namespace GitHub.Unity
11
12
[ Serializable ]
12
13
class GitPathView : Subview
13
14
{
14
- private const string BrowseButton = "..." ;
15
15
private const string GitInstallTitle = "Git installation" ;
16
- private const string GitInstallBrowseTitle = "Select git binary" ;
17
- private const string GitInstallPickInvalidTitle = "Invalid Git install" ;
18
- private const string GitInstallPickInvalidMessage = "The selected file is not a valid Git install. {0}" ;
19
- private const string GitInstallFindButton = "Find install" ;
20
- private const string GitInstallPickInvalidOK = "OK" ;
21
16
private const string PathToGit = "Path to Git" ;
22
17
private const string GitPathSaveButton = "Save Path" ;
18
+ private const string GitInstallFindButton = "Find install" ;
19
+ private const string BrowseButton = "..." ;
20
+ private const string GitInstallBrowseTitle = "Select git binary" ;
21
+ private const string ErrorInvalidPathMessage = "Invalid Path." ;
22
+ private const string ErrorGettingSoftwareVersionMessage = "Error getting software versions." ;
23
+ private const string ErrorMinimumGitVersionMessageFormat = "Git version {0} found. Git version {1} is required." ;
24
+ private const string ErrorMinimumGitLfsVersionMessageFormat = "Git LFS version {0} found. Git LFS version {1} is required." ;
23
25
24
26
[ SerializeField ] private string gitExec ;
25
27
[ SerializeField ] private string gitExecParent ;
26
28
[ SerializeField ] private string gitExecExtension ;
27
29
[ SerializeField ] private string newGitExec ;
28
- [ NonSerialized ] private bool gitExecHasChanged ;
29
30
30
31
[ NonSerialized ] private bool isBusy ;
32
+ [ NonSerialized ] private string gitFileErrorMessage ;
33
+ [ NonSerialized ] private string gitVersionErrorMessage ;
34
+ [ NonSerialized ] private bool gitExecHasChanged ;
35
+
31
36
public override void OnEnable ( )
32
37
{
33
38
base . OnEnable ( ) ;
34
39
35
40
gitExecHasChanged = true ;
36
41
}
37
42
38
- public override void OnDisable ( )
39
- {
40
- base . OnDisable ( ) ;
41
- }
42
-
43
43
public override void OnDataUpdate ( )
44
44
{
45
45
base . OnDataUpdate ( ) ;
@@ -89,11 +89,16 @@ public override void OnGUI()
89
89
90
90
GUILayout . BeginHorizontal ( ) ;
91
91
{
92
- var needsSaving = ! string . IsNullOrEmpty ( newGitExec )
93
- && newGitExec != gitExec
94
- && newGitExec . ToNPath ( ) . FileExists ( ) ;
92
+ var isValueChanged = ! string . IsNullOrEmpty ( newGitExec )
93
+ && newGitExec != gitExec ;
94
+
95
+ var isValueChangedAndFileExists = isValueChanged && newGitExec . ToNPath ( ) . FileExists ( ) ;
95
96
96
- EditorGUI . BeginDisabledGroup ( ! needsSaving ) ;
97
+ gitFileErrorMessage = isValueChanged && ! isValueChangedAndFileExists
98
+ ? ErrorInvalidPathMessage
99
+ : null ;
100
+
101
+ EditorGUI . BeginDisabledGroup ( ! isValueChangedAndFileExists ) ;
97
102
{
98
103
if ( GUILayout . Button ( GitPathSaveButton , GUILayout . ExpandWidth ( false ) ) )
99
104
{
@@ -138,6 +143,24 @@ public override void OnGUI()
138
143
}
139
144
}
140
145
GUILayout . EndHorizontal ( ) ;
146
+
147
+ if ( gitFileErrorMessage != null )
148
+ {
149
+ GUILayout . BeginHorizontal ( ) ;
150
+ {
151
+ GUILayout . Label ( gitFileErrorMessage , Styles . ErrorLabel ) ;
152
+ }
153
+ GUILayout . EndHorizontal ( ) ;
154
+ }
155
+
156
+ if ( gitVersionErrorMessage != null )
157
+ {
158
+ GUILayout . BeginHorizontal ( ) ;
159
+ {
160
+ GUILayout . Label ( gitVersionErrorMessage , Styles . ErrorLabel ) ;
161
+ }
162
+ GUILayout . EndHorizontal ( ) ;
163
+ }
141
164
}
142
165
EditorGUI . EndDisabledGroup ( ) ;
143
166
}
@@ -146,11 +169,16 @@ private void ValidateAndSetGitInstallPath(string value)
146
169
{
147
170
Logger . Trace ( "Validating Git Path:{0}" , value ) ;
148
171
172
+ gitVersionErrorMessage = null ;
173
+
149
174
GitClient . ValidateGitInstall ( value ) . ThenInUI ( ( sucess , result ) => {
150
175
if ( ! sucess )
151
176
{
152
- Logger . Trace ( "Error getting software versions" ) ;
177
+ Logger . Trace ( ErrorGettingSoftwareVersionMessage ) ;
178
+ gitVersionErrorMessage = ErrorGettingSoftwareVersionMessage ;
179
+
153
180
isBusy = false ;
181
+
154
182
return ;
155
183
}
156
184
@@ -162,6 +190,25 @@ private void ValidateAndSetGitInstallPath(string value)
162
190
result . GitLfsVersionTask ,
163
191
Constants . MinimumGitLfsVersion ) ;
164
192
193
+ var errorMessageStringBuilder = new StringBuilder ( ) ;
194
+
195
+ if ( result . GitVersionTask < Constants . MinimumGitVersion )
196
+ {
197
+ errorMessageStringBuilder . AppendFormat ( ErrorMinimumGitVersionMessageFormat , result . GitVersionTask , Constants . MinimumGitVersion ) ;
198
+ }
199
+
200
+ if ( result . GitLfsVersionTask < Constants . MinimumGitLfsVersion )
201
+ {
202
+ if ( errorMessageStringBuilder . Length > 0 )
203
+ {
204
+ errorMessageStringBuilder . Append ( Environment . NewLine ) ;
205
+ }
206
+
207
+ errorMessageStringBuilder . AppendFormat ( ErrorMinimumGitLfsVersionMessageFormat , result . GitLfsVersionTask , Constants . MinimumGitLfsVersion ) ;
208
+ }
209
+
210
+ gitVersionErrorMessage = errorMessageStringBuilder . ToString ( ) ;
211
+
165
212
isBusy = false ;
166
213
return ;
167
214
}
0 commit comments