Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 700500b

Browse files
Adding functionality to change to the internal portable git if available
1 parent 85cd131 commit 700500b

File tree

1 file changed

+99
-47
lines changed

1 file changed

+99
-47
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs

Lines changed: 99 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ class GitPathView : Subview
1111
private const string GitInstallTitle = "Git installation";
1212
private const string PathToGit = "Path to Git";
1313
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";
1516
private const string BrowseButton = "...";
1617
private const string GitInstallBrowseTitle = "Select git binary";
1718
private const string ErrorInvalidPathMessage = "Invalid Path.";
19+
private const string ErrorInstallingInternalGit = "Error installing portable git.";
1820
private const string ErrorValidatingGitPath = "Error validating Git Path.";
1921
private const string ErrorGitNotFoundMessage = "Git not found.";
2022
private const string ErrorGitLfsNotFoundMessage = "Git LFS not found.";
@@ -33,11 +35,15 @@ class GitPathView : Subview
3335
[NonSerialized] private bool isBusy;
3436
[NonSerialized] private bool gitExecHasChanged;
3537
[NonSerialized] private bool gitExecutableIsSet;
38+
[NonSerialized] private string portableGitPath;
3639

3740
public override void InitializeView(IView parent)
3841
{
3942
base.InitializeView(parent);
4043
gitExecutableIsSet = Environment.GitExecutablePath.IsInitialized;
44+
45+
var gitInstallDetails = new GitInstaller.GitInstallDetails(Environment.UserCachePath, Environment.IsWindows);
46+
portableGitPath = gitInstallDetails.GitExecutablePath;
4147
}
4248

4349
public override void OnEnable()
@@ -112,8 +118,21 @@ public override void OnGUI()
112118
}
113119
EditorGUI.EndDisabledGroup();
114120

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+
115134
//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)))
117136
{
118137
GUI.FocusControl(null);
119138
isBusy = true;
@@ -213,72 +232,105 @@ private void CheckEnteredGitPath()
213232

214233
private void ValidateAndSetGitInstallPath(string value)
215234
{
216-
//Logger.Trace("Validating Git Path:{0}", value);
235+
value = value.Trim();
217236

218-
gitVersionErrorMessage = null;
237+
if (value == portableGitPath)
238+
{
239+
Logger.Trace("Attempting to restore portable Git Path:{0}", value);
219240

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);
234243

235-
var errorMessageStringBuilder = new StringBuilder();
244+
gitInstaller.SetupGitIfNeeded()
245+
.FinallyInUI((success, exception, result) =>
246+
{
247+
Logger.Trace("Setup Git Using the installer:{0}", success);
236248

237-
if (result.GitVersion == null)
249+
if (!success)
238250
{
239-
errorMessageStringBuilder.Append(ErrorGitNotFoundMessage);
251+
Logger.Error(exception, ErrorInstallingInternalGit);
252+
gitVersionErrorMessage = ErrorValidatingGitPath;
240253
}
241-
else if (result.GitLfsVersion == null)
254+
else
242255
{
243-
errorMessageStringBuilder.Append(ErrorGitLfsNotFoundMessage);
256+
Manager.SystemSettings.Unset(Constants.GitInstallPathKey);
257+
Environment.GitExecutablePath = result;
258+
259+
gitExecHasChanged = true;
244260
}
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)
246280
{
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)
248289
{
249-
errorMessageStringBuilder.AppendFormat(ErrorMinimumGitVersionMessageFormat,
250-
result.GitVersion, Constants.MinimumGitVersion);
290+
errorMessageStringBuilder.Append(ErrorGitNotFoundMessage);
251291
}
252-
253-
if (result.GitLfsVersion < Constants.MinimumGitLfsVersion)
292+
else if (result.GitLfsVersion == null)
254293
{
255-
if (errorMessageStringBuilder.Length > 0)
294+
errorMessageStringBuilder.Append(ErrorGitLfsNotFoundMessage);
295+
}
296+
else
297+
{
298+
if (result.GitVersion < Constants.MinimumGitVersion)
256299
{
257-
errorMessageStringBuilder.Append(Environment.NewLine);
300+
errorMessageStringBuilder.AppendFormat(ErrorMinimumGitVersionMessageFormat,
301+
result.GitVersion, Constants.MinimumGitVersion);
258302
}
259303

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+
}
262314
}
263-
}
264315

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);
272323

273-
Manager.SystemSettings.Set(Constants.GitInstallPathKey, value);
274-
Environment.GitExecutablePath = value.ToNPath();
324+
Manager.SystemSettings.Set(Constants.GitInstallPathKey, value);
325+
Environment.GitExecutablePath = value.ToNPath();
275326

276-
gitExecHasChanged = true;
277-
}
327+
gitExecHasChanged = true;
328+
}
278329

279-
isBusy = false;
330+
isBusy = false;
280331

281-
}).Start();
332+
}).Start();
333+
}
282334
}
283335

284336
public override bool IsBusy

0 commit comments

Comments
 (0)