Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 99 additions & 47 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class GitPathView : Subview
private const string GitInstallTitle = "Git installation";
private const string PathToGit = "Path to Git";
private const string GitPathSaveButton = "Save Path";
private const string GitInstallFindButton = "Find install";
private const string UseInternalGitButton = "Use internal git";
private const string FindSystemGitButton = "Find system git";
private const string BrowseButton = "...";
private const string GitInstallBrowseTitle = "Select git binary";
private const string ErrorInvalidPathMessage = "Invalid Path.";
private const string ErrorInstallingInternalGit = "Error installing portable git.";
private const string ErrorValidatingGitPath = "Error validating Git Path.";
private const string ErrorGitNotFoundMessage = "Git not found.";
private const string ErrorGitLfsNotFoundMessage = "Git LFS not found.";
Expand All @@ -33,11 +35,15 @@ class GitPathView : Subview
[NonSerialized] private bool isBusy;
[NonSerialized] private bool gitExecHasChanged;
[NonSerialized] private bool gitExecutableIsSet;
[NonSerialized] private string portableGitPath;

public override void InitializeView(IView parent)
{
base.InitializeView(parent);
gitExecutableIsSet = Environment.GitExecutablePath.IsInitialized;

var gitInstallDetails = new GitInstaller.GitInstallDetails(Environment.UserCachePath, Environment.IsWindows);
portableGitPath = gitInstallDetails.GitExecutablePath;
}

public override void OnEnable()
Expand Down Expand Up @@ -112,8 +118,21 @@ public override void OnGUI()
}
EditorGUI.EndDisabledGroup();

// disable if we are not on windows
// disable if the newPath == portableGitPath
EditorGUI.BeginDisabledGroup(!Environment.IsWindows || Environment.IsWindows && newGitExec == portableGitPath);
if (GUILayout.Button(UseInternalGitButton, GUILayout.ExpandWidth(false)))
{
GUI.FocusControl(null);

Logger.Trace("Expected portableGitPath: {0}", portableGitPath);
newGitExec = portableGitPath;
CheckEnteredGitPath();
}
EditorGUI.EndDisabledGroup();

//Find button - for attempting to locate a new install
if (GUILayout.Button(GitInstallFindButton, GUILayout.ExpandWidth(false)))
if (GUILayout.Button(FindSystemGitButton, GUILayout.ExpandWidth(false)))
{
GUI.FocusControl(null);
isBusy = true;
Expand Down Expand Up @@ -213,72 +232,105 @@ private void CheckEnteredGitPath()

private void ValidateAndSetGitInstallPath(string value)
{
//Logger.Trace("Validating Git Path:{0}", value);
value = value.Trim();

gitVersionErrorMessage = null;
if (value == portableGitPath)
{
Logger.Trace("Attempting to restore portable Git Path:{0}", value);

GitClient.ValidateGitInstall(value.ToNPath())
.ThenInUI((success, result) =>
{
if (!success)
{
Logger.Trace(ErrorValidatingGitPath);
gitVersionErrorMessage = ErrorValidatingGitPath;
}
else if (!result.IsValid)
{
Logger.Warning(
"Software versions do not meet minimums Git:{0} (Minimum:{1}) GitLfs:{2} (Minimum:{3})",
result.GitVersion, Constants.MinimumGitVersion, result.GitLfsVersion,
Constants.MinimumGitLfsVersion);
var gitInstaller = new GitInstaller(Environment, EntryPoint.ApplicationManager.ProcessManager,
EntryPoint.ApplicationManager.TaskManager);

var errorMessageStringBuilder = new StringBuilder();
gitInstaller.SetupGitIfNeeded()
.FinallyInUI((success, exception, result) =>
{
Logger.Trace("Setup Git Using the installer:{0}", success);

if (result.GitVersion == null)
if (!success)
{
errorMessageStringBuilder.Append(ErrorGitNotFoundMessage);
Logger.Error(exception, ErrorInstallingInternalGit);
gitVersionErrorMessage = ErrorValidatingGitPath;
}
else if (result.GitLfsVersion == null)
else
{
errorMessageStringBuilder.Append(ErrorGitLfsNotFoundMessage);
Manager.SystemSettings.Unset(Constants.GitInstallPathKey);
Environment.GitExecutablePath = result;

gitExecHasChanged = true;
}
else

isBusy = false;
}).Start();
}
else
{
//Logger.Trace("Validating Git Path:{0}", value);

gitVersionErrorMessage = null;

GitClient.ValidateGitInstall(value.ToNPath())
.ThenInUI((success, result) =>
{
if (!success)
{
Logger.Trace(ErrorValidatingGitPath);
gitVersionErrorMessage = ErrorValidatingGitPath;
}
else if (!result.IsValid)
{
if (result.GitVersion < Constants.MinimumGitVersion)
Logger.Warning(
"Software versions do not meet minimums Git:{0} (Minimum:{1}) GitLfs:{2} (Minimum:{3})",
result.GitVersion, Constants.MinimumGitVersion, result.GitLfsVersion,
Constants.MinimumGitLfsVersion);

var errorMessageStringBuilder = new StringBuilder();

if (result.GitVersion == null)
{
errorMessageStringBuilder.AppendFormat(ErrorMinimumGitVersionMessageFormat,
result.GitVersion, Constants.MinimumGitVersion);
errorMessageStringBuilder.Append(ErrorGitNotFoundMessage);
}

if (result.GitLfsVersion < Constants.MinimumGitLfsVersion)
else if (result.GitLfsVersion == null)
{
errorMessageStringBuilder.Append(ErrorGitLfsNotFoundMessage);
}
else
{
if (errorMessageStringBuilder.Length > 0)
if (result.GitVersion < Constants.MinimumGitVersion)
{
errorMessageStringBuilder.Append(Environment.NewLine);
errorMessageStringBuilder.AppendFormat(ErrorMinimumGitVersionMessageFormat,
result.GitVersion, Constants.MinimumGitVersion);
}

errorMessageStringBuilder.AppendFormat(ErrorMinimumGitLfsVersionMessageFormat,
result.GitLfsVersion, Constants.MinimumGitLfsVersion);
if (result.GitLfsVersion < Constants.MinimumGitLfsVersion)
{
if (errorMessageStringBuilder.Length > 0)
{
errorMessageStringBuilder.Append(Environment.NewLine);
}

errorMessageStringBuilder.AppendFormat(ErrorMinimumGitLfsVersionMessageFormat,
result.GitLfsVersion, Constants.MinimumGitLfsVersion);
}
}
}

gitVersionErrorMessage = errorMessageStringBuilder.ToString();
}
else
{
Logger.Trace("Software versions meet minimums Git:{0} GitLfs:{1}",
result.GitVersion,
result.GitLfsVersion);
gitVersionErrorMessage = errorMessageStringBuilder.ToString();
}
else
{
Logger.Trace("Software versions meet minimums Git:{0} GitLfs:{1}",
result.GitVersion,
result.GitLfsVersion);

Manager.SystemSettings.Set(Constants.GitInstallPathKey, value);
Environment.GitExecutablePath = value.ToNPath();
Manager.SystemSettings.Set(Constants.GitInstallPathKey, value);
Environment.GitExecutablePath = value.ToNPath();

gitExecHasChanged = true;
}
gitExecHasChanged = true;
}

isBusy = false;
isBusy = false;

}).Start();
}).Start();
}
}

public override bool IsBusy
Expand Down