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

ValidateGitInstall may fail in error #658

Merged
merged 5 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
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
31 changes: 21 additions & 10 deletions src/GitHub.Api/Git/GitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,29 @@ public ITask<ValidateGitInstallResult> ValidateGitInstall(NPath path)
Version gitVersion = null;
Version gitLfsVersion = null;

var gitVersionTask = new GitVersionTask(cancellationToken).Configure(processManager, path);
var gitLfsVersionTask = new GitLfsVersionTask(cancellationToken).Configure(processManager, path);

return gitVersionTask
.Then((result, version) => gitVersion = version)
.Then(gitLfsVersionTask)
.Then((result, version) => gitLfsVersion = version)
.Then(success => new ValidateGitInstallResult(success &&
var endTask = new FuncTask<ValidateGitInstallResult>(cancellationToken,
() => new ValidateGitInstallResult(
gitVersion?.CompareTo(Constants.MinimumGitVersion) >= 0 &&
gitLfsVersion?.CompareTo(Constants.MinimumGitLfsVersion) >= 0,
gitVersion, gitLfsVersion)
);
gitVersion, gitLfsVersion));

var gitLfsVersionTask = new GitLfsVersionTask(cancellationToken).Configure(processManager, path);

gitLfsVersionTask
.Then((result, version) => {return gitLfsVersion = version;})
.Then(endTask, taskIsTopOfChain: true);

gitLfsVersionTask.Then(endTask, TaskRunOptions.OnFailure, taskIsTopOfChain:true);

var gitVersionTask = new GitVersionTask(cancellationToken).Configure(processManager, path);

gitVersionTask
.Then((result, version) => { return gitVersion = version; })
.Then(gitLfsVersionTask, taskIsTopOfChain: true);

gitVersionTask.Then(endTask, TaskRunOptions.OnFailure, taskIsTopOfChain:true);

return endTask;
}

public ITask Init(IOutputProcessor<string> processor = null)
Expand Down
43 changes: 28 additions & 15 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/GitPathView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class GitPathView : Subview
private const string BrowseButton = "...";
private const string GitInstallBrowseTitle = "Select git binary";
private const string ErrorInvalidPathMessage = "Invalid Path.";
private const string ErrorGettingSoftwareVersionMessage = "Error getting software versions.";
private const string ErrorValidatingGitPath = "Error validating Git Path.";
private const string ErrorGitNotFoundMessage = "Git not found.";
private const string ErrorGitLfsNotFoundMessage = "Git LFS not found.";
private const string ErrorMinimumGitVersionMessageFormat = "Git version {0} found. Git version {1} is required.";
private const string ErrorMinimumGitLfsVersionMessageFormat = "Git LFS version {0} found. Git LFS version {1} is required.";

Expand Down Expand Up @@ -216,12 +218,12 @@ private void ValidateAndSetGitInstallPath(string value)
gitVersionErrorMessage = null;

GitClient.ValidateGitInstall(value.ToNPath())
.ThenInUI((sucess, result) =>
.FinallyInUI((success, exception, result) =>
{
if (!sucess)
if (!success)
{
Logger.Trace(ErrorGettingSoftwareVersionMessage);
gitVersionErrorMessage = ErrorGettingSoftwareVersionMessage;
Logger.Trace(ErrorValidatingGitPath);
gitVersionErrorMessage = ErrorValidatingGitPath;
}
else if (!result.IsValid)
{
Expand All @@ -232,28 +234,39 @@ private void ValidateAndSetGitInstallPath(string value)

var errorMessageStringBuilder = new StringBuilder();

if (result.GitVersion < Constants.MinimumGitVersion)
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.Warning("Software versions meet minimums Git:{0} GitLfs:{1}",
Logger.Trace("Software versions meet minimums Git:{0} GitLfs:{1}",
result.GitVersion,
result.GitLfsVersion);

Expand Down