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

Commit 043bdff

Browse files
Merge branch 'enhancements/git-install-validation' into enhancements/git-path-view
# Conflicts: # src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs
2 parents e1097b5 + 3f4fa09 commit 043bdff

File tree

4 files changed

+124
-5
lines changed

4 files changed

+124
-5
lines changed

src/GitHub.Api/Git/GitClient.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace GitHub.Unity
99
interface IGitClient
1010
{
1111
Task<NPath> FindGitInstallation();
12-
bool ValidateGitInstall(NPath path);
12+
13+
ITask<bool> ValidateGitInstall(NPath path);
1314

1415
ITask Init(IOutputProcessor<string> processor = null);
1516

@@ -152,9 +153,40 @@ private async Task<NPath> LookForSystemGit()
152153
return path;
153154
}
154155

155-
public bool ValidateGitInstall(NPath path)
156+
public ITask<bool> ValidateGitInstall(NPath path)
156157
{
157-
return path.FileExists();
158+
if (!path.FileExists())
159+
{
160+
return new FuncTask<bool>(cancellationToken, () => false);
161+
}
162+
163+
SoftwareVersion? gitVersion = null;
164+
SoftwareVersion? gitLfsVersion = null;
165+
166+
var gitVersionTask = new GitVersionTask(cancellationToken);
167+
gitVersionTask.Configure(processManager, path.ToString(),
168+
gitVersionTask.ProcessArguments, environment.RepositoryPath);
169+
170+
var gitLfsVersionTask = new GitLfsVersionTask(cancellationToken);
171+
gitLfsVersionTask.Configure(processManager, path.ToString(),
172+
gitLfsVersionTask.ProcessArguments, environment.RepositoryPath);
173+
174+
return gitVersionTask
175+
.Then((result, version) => { gitVersion = version; })
176+
.Then(gitLfsVersionTask)
177+
.Then((result, version) => {
178+
gitLfsVersion = version;
179+
}).Then(result => {
180+
if (result)
181+
{
182+
return gitVersion.HasValue &&
183+
gitVersion.Value >= new SoftwareVersion(2, 1, 0) &&
184+
gitLfsVersion.HasValue &&
185+
gitLfsVersion.Value >= new SoftwareVersion(2, 1, 0);
186+
}
187+
188+
return false;
189+
});
158190
}
159191

160192
public ITask Init(IOutputProcessor<string> processor = null)

src/GitHub.Api/OutputProcessors/SoftwareVersion.cs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,72 @@ public SoftwareVersion(int major, int minor, int build)
1313
Build = build;
1414
}
1515

16-
public SoftwareVersion(string major, string minor, string build):
16+
public SoftwareVersion(string major, string minor, string build) :
1717
this(int.Parse(major), int.Parse(minor), int.Parse(build))
1818
{
19-
19+
20+
}
21+
22+
public static bool operator <(SoftwareVersion lhs, SoftwareVersion rhs)
23+
{
24+
if (lhs.Major < rhs.Major)
25+
{
26+
return true;
27+
}
28+
29+
if (lhs.Major == rhs.Major)
30+
{
31+
if (lhs.Minor < rhs.Minor)
32+
{
33+
return true;
34+
}
35+
36+
if (lhs.Minor == rhs.Minor)
37+
{
38+
if (lhs.Build < rhs.Build)
39+
{
40+
return true;
41+
}
42+
}
43+
}
44+
45+
return false;
46+
}
47+
48+
public static bool operator >(SoftwareVersion lhs, SoftwareVersion rhs)
49+
{
50+
if (lhs.Major > rhs.Major)
51+
{
52+
return true;
53+
}
54+
55+
if (lhs.Major == rhs.Major)
56+
{
57+
if (lhs.Minor > rhs.Minor)
58+
{
59+
return true;
60+
}
61+
62+
if (lhs.Minor == rhs.Minor)
63+
{
64+
if (lhs.Build > rhs.Build)
65+
{
66+
return true;
67+
}
68+
}
69+
}
70+
71+
return false;
72+
}
73+
74+
public static bool operator <=(SoftwareVersion lhs, SoftwareVersion rhs)
75+
{
76+
return lhs.Equals(rhs) || lhs < rhs;
77+
}
78+
79+
public static bool operator >=(SoftwareVersion lhs, SoftwareVersion rhs)
80+
{
81+
return lhs.Equals(rhs) || lhs > rhs;
2082
}
2183
}
2284
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using FluentAssertions;
2+
using GitHub.Unity;
3+
using NUnit.Framework;
4+
5+
namespace UnitTests
6+
{
7+
[TestFixture]
8+
class SoftwareVersionTests
9+
{
10+
[Test]
11+
public void LessThanOrEqualTo()
12+
{
13+
(new SoftwareVersion(1, 1, 0) <= new SoftwareVersion(1, 1, 0)).Should().BeTrue();
14+
(new SoftwareVersion(1, 0, 0) <= new SoftwareVersion(1, 1, 0)).Should().BeTrue();
15+
}
16+
17+
[Test]
18+
public void LessThan()
19+
{
20+
(new SoftwareVersion(1, 1, 0) < new SoftwareVersion(1, 1, 0)).Should().BeFalse();
21+
(new SoftwareVersion(1, 0, 0) < new SoftwareVersion(1, 1, 0)).Should().BeTrue();
22+
}
23+
}
24+
}

src/tests/UnitTests/UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<Compile Include="Extensions\EnvironmentExtensionTests.cs" />
8585
<Compile Include="IO\LfsVersionOutputProcessorTests.cs" />
8686
<Compile Include="IO\LockOutputProcessorTests.cs" />
87+
<Compile Include="IO\SoftwareVersionTests.cs" />
8788
<Compile Include="IO\VersionOutputProcessorTests.cs" />
8889
<Compile Include="IO\RemoteListOutputProcessorTests.cs" />
8990
<Compile Include="IO\BaseOutputProcessorTests.cs" />

0 commit comments

Comments
 (0)