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

Commit fbe4d82

Browse files
Adding an object to summarize the result; Adding an undefined state
1 parent 14587b4 commit fbe4d82

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface IGitClient
1010
{
1111
Task<NPath> FindGitInstallation();
1212

13-
ITask<bool> ValidateGitInstall(string path);
13+
ITask<ValidateGitInstallResult> ValidateGitInstall(string path);
1414

1515
ITask Init(IOutputProcessor<string> processor = null);
1616

@@ -92,7 +92,6 @@ class GitClient : IGitClient
9292
private readonly ITaskManager taskManager;
9393
private readonly CancellationToken cancellationToken;
9494

95-
9695
public GitClient(IEnvironment environment, IProcessManager processManager,
9796
ICredentialManager credentialManager, ITaskManager taskManager)
9897
{
@@ -153,15 +152,16 @@ private async Task<NPath> LookForSystemGit()
153152
return path;
154153
}
155154

156-
public ITask<bool> ValidateGitInstall(string path)
155+
public ITask<ValidateGitInstallResult> ValidateGitInstall(string path)
157156
{
158157
if (!path.ToNPath().FileExists())
159158
{
160-
return new FuncTask<bool>(cancellationToken, () => false);
159+
return new FuncTask<ValidateGitInstallResult>(cancellationToken,
160+
() => new ValidateGitInstallResult(false, SoftwareVersion.Undefined, SoftwareVersion.Undefined));
161161
}
162162

163-
SoftwareVersion? gitVersion = null;
164-
SoftwareVersion? gitLfsVersion = null;
163+
var gitVersion = SoftwareVersion.Undefined;
164+
var gitLfsVersion = SoftwareVersion.Undefined;
165165

166166
var gitVersionTask = new GitVersionTask(cancellationToken);
167167
gitVersionTask.Configure(processManager, path,
@@ -176,11 +176,15 @@ public ITask<bool> ValidateGitInstall(string path)
176176
.Then(gitLfsVersionTask)
177177
.Then((result, version) => {
178178
gitLfsVersion = version;
179-
}).Then(result => result &&
180-
gitVersion.HasValue &&
181-
gitVersion.Value >= new SoftwareVersion(2, 1, 0) &&
182-
gitLfsVersion.HasValue &&
183-
gitLfsVersion.Value >= new SoftwareVersion(2, 1, 0));
179+
}).Then(result => {
180+
var b = result
181+
&& gitVersion != SoftwareVersion.Undefined
182+
&& gitVersion >= Constants.MinimumGitVersion
183+
&& gitLfsVersion != SoftwareVersion.Undefined
184+
&& gitLfsVersion >= Constants.MinimumGitLfsVersion;
185+
186+
return new ValidateGitInstallResult(b, gitVersion, gitLfsVersion);
187+
});
184188
}
185189

186190
public ITask Init(IOutputProcessor<string> processor = null)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace GitHub.Unity
2+
{
3+
struct ValidateGitInstallResult
4+
{
5+
public bool IsValid;
6+
public SoftwareVersion GitVersionTask;
7+
public SoftwareVersion GitLfsVersionTask;
8+
9+
public ValidateGitInstallResult(bool isValid, SoftwareVersion gitVersionTask, SoftwareVersion gitLfsVersionTask)
10+
{
11+
IsValid = isValid;
12+
GitVersionTask = gitVersionTask;
13+
GitLfsVersionTask = gitLfsVersionTask;
14+
}
15+
}
16+
}

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<Compile Include="Extensions\ListExtensions.cs" />
103103
<Compile Include="Git\Tasks\GitLfsVersionTask.cs" />
104104
<Compile Include="Git\Tasks\GitVersionTask.cs" />
105+
<Compile Include="Git\ValidateGitInstallResult.cs" />
105106
<Compile Include="Helpers\AssemblyResources.cs" />
106107
<Compile Include="Authentication\IKeychain.cs" />
107108
<Compile Include="Authentication\Keychain.cs" />

src/GitHub.Api/Helpers/Constants.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ static class Constants
77
public const string UsageFile = "usage.json";
88
public const string GitInstallPathKey = "GitInstallPath";
99
public const string TraceLoggingKey = "EnableTraceLogging";
10+
11+
public static readonly SoftwareVersion MinimumGitVersion = new SoftwareVersion(2, 1, 0);
12+
public static readonly SoftwareVersion MinimumGitLfsVersion = new SoftwareVersion(2, 1, 0);
1013
}
1114
}

src/GitHub.Api/OutputProcessors/SoftwareVersion.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ namespace GitHub.Unity
22
{
33
public struct SoftwareVersion
44
{
5-
public int Major;
6-
public int Minor;
7-
public int Build;
5+
public static SoftwareVersion Undefined = new SoftwareVersion(-1, -1, -1);
6+
7+
public readonly int Major;
8+
public readonly int Minor;
9+
public readonly int Build;
810

911
public SoftwareVersion(int major, int minor, int build)
1012
{
@@ -19,6 +21,18 @@ public SoftwareVersion(string major, string minor, string build) :
1921

2022
}
2123

24+
public static bool operator ==(SoftwareVersion lhs, SoftwareVersion rhs)
25+
{
26+
return lhs.Major == rhs.Major
27+
&& lhs.Minor == rhs.Minor
28+
&& lhs.Build == rhs.Build;
29+
}
30+
31+
public static bool operator !=(SoftwareVersion lhs, SoftwareVersion rhs)
32+
{
33+
return !(lhs == rhs);
34+
}
35+
2236
public static bool operator <(SoftwareVersion lhs, SoftwareVersion rhs)
2337
{
2438
if (lhs.Major < rhs.Major)

0 commit comments

Comments
 (0)