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

Commit c4d410f

Browse files
Merge pull request #272 from github-for-unity/enhancements/git-path-view
Isolating the git path functionality into GitPathView
2 parents f441bbd + 0271aca commit c4d410f

21 files changed

+629
-180
lines changed

src/GitHub.Api/Git/GitClient.cs

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

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

@@ -77,6 +77,10 @@ ITask<string> Unlock(string file, bool force,
7777
IOutputProcessor<string> processor = null);
7878

7979
ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> processor = null);
80+
81+
ITask<Version> Version(IOutputProcessor<Version> processor = null);
82+
83+
ITask<Version> LfsVersion(IOutputProcessor<Version> processor = null);
8084
}
8185

8286
class GitClient : IGitClient
@@ -87,7 +91,6 @@ class GitClient : IGitClient
8791
private readonly ITaskManager taskManager;
8892
private readonly CancellationToken cancellationToken;
8993

90-
9194
public GitClient(IEnvironment environment, IProcessManager processManager,
9295
ICredentialManager credentialManager, ITaskManager taskManager)
9396
{
@@ -167,9 +170,28 @@ private async Task<NPath> LookForSystemGit()
167170
return path;
168171
}
169172

170-
public bool ValidateGitInstall(NPath path)
173+
public ITask<ValidateGitInstallResult> ValidateGitInstall(NPath path)
171174
{
172-
return path.FileExists();
175+
if (!path.FileExists())
176+
{
177+
return new FuncTask<ValidateGitInstallResult>(TaskEx.FromResult(new ValidateGitInstallResult(false, null, null)));
178+
}
179+
180+
Version gitVersion = null;
181+
Version gitLfsVersion = null;
182+
183+
var gitVersionTask = new GitVersionTask(cancellationToken).Configure(processManager, path);
184+
var gitLfsVersionTask = new GitLfsVersionTask(cancellationToken).Configure(processManager, path);
185+
186+
return gitVersionTask
187+
.Then((result, version) => gitVersion = version)
188+
.Then(gitLfsVersionTask)
189+
.Then((result, version) => gitLfsVersion = version)
190+
.Then(success => new ValidateGitInstallResult(success &&
191+
gitVersion?.CompareTo(Constants.MinimumGitVersion) >= 0 &&
192+
gitLfsVersion?.CompareTo(Constants.MinimumGitLfsVersion) >= 0,
193+
gitVersion, gitLfsVersion)
194+
);
173195
}
174196

175197
public ITask Init(IOutputProcessor<string> processor = null)
@@ -202,6 +224,22 @@ public ITask<List<GitLogEntry>> Log(BaseOutputListProcessor<GitLogEntry> process
202224
.Configure(processManager);
203225
}
204226

227+
public ITask<Version> Version(IOutputProcessor<Version> processor = null)
228+
{
229+
Logger.Trace("Version");
230+
231+
return new GitVersionTask(cancellationToken, processor)
232+
.Configure(processManager);
233+
}
234+
235+
public ITask<Version> LfsVersion(IOutputProcessor<Version> processor = null)
236+
{
237+
Logger.Trace("LfsVersion");
238+
239+
return new GitLfsVersionTask(cancellationToken, processor)
240+
.Configure(processManager);
241+
}
242+
205243
public ITask<string> GetConfig(string key, GitConfigSource configSource, IOutputProcessor<string> processor = null)
206244
{
207245
Logger.Trace("GetConfig");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Threading;
3+
4+
namespace GitHub.Unity
5+
{
6+
class GitLfsVersionTask : ProcessTask<Version>
7+
{
8+
private const string TaskName = "git lfs version";
9+
10+
public GitLfsVersionTask(CancellationToken token, IOutputProcessor<Version> processor = null)
11+
: base(token, processor ?? new LfsVersionOutputProcessor())
12+
{
13+
Name = TaskName;
14+
}
15+
16+
public override string ProcessArguments { get { return "lfs version"; } }
17+
public override TaskAffinity Affinity { get { return TaskAffinity.Concurrent; } }
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Threading;
3+
4+
namespace GitHub.Unity
5+
{
6+
class GitVersionTask : ProcessTask<Version>
7+
{
8+
private const string TaskName = "git --version";
9+
10+
public GitVersionTask(CancellationToken token, IOutputProcessor<Version> processor = null)
11+
: base(token, processor ?? new VersionOutputProcessor())
12+
{
13+
Name = TaskName;
14+
}
15+
16+
public override string ProcessArguments { get { return "--version"; } }
17+
public override TaskAffinity Affinity { get { return TaskAffinity.Concurrent; } }
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
3+
namespace GitHub.Unity
4+
{
5+
struct ValidateGitInstallResult
6+
{
7+
public bool IsValid;
8+
public Version GitVersion;
9+
public Version GitLfsVersion;
10+
11+
public ValidateGitInstallResult(bool isValid, Version gitVersion, Version gitLfsVersion)
12+
{
13+
IsValid = isValid;
14+
GitVersion = gitVersion;
15+
GitLfsVersion = gitLfsVersion;
16+
}
17+
}
18+
}

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
<Compile Include="Application\LoginResult.cs" />
101101
<Compile Include="Application\AppConfiguration.cs" />
102102
<Compile Include="Extensions\ListExtensions.cs" />
103+
<Compile Include="Git\Tasks\GitLfsVersionTask.cs" />
104+
<Compile Include="Git\Tasks\GitVersionTask.cs" />
105+
<Compile Include="Git\ValidateGitInstallResult.cs" />
103106
<Compile Include="Helpers\AssemblyResources.cs" />
104107
<Compile Include="Authentication\IKeychain.cs" />
105108
<Compile Include="Authentication\Keychain.cs" />
@@ -109,6 +112,8 @@
109112
<Compile Include="Helpers\Constants.cs" />
110113
<Compile Include="Cache\IBranchCache.cs" />
111114
<Compile Include="Helpers\Validation.cs" />
115+
<Compile Include="OutputProcessors\LfsVersionOutputProcessor.cs" />
116+
<Compile Include="OutputProcessors\VersionOutputProcessor.cs" />
112117
<Compile Include="Helpers\TaskHelpers.cs" />
113118
<Compile Include="Platform\DefaultEnvironment.cs" />
114119
<Compile Include="Extensions\EnvironmentExtensions.cs" />

src/GitHub.Api/GitHub.Api.csproj.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean>
66
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=git/@EntryIndexedValue">True</s:Boolean>
77
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=git_005Ctasks/@EntryIndexedValue">True</s:Boolean>
8+
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=helpers/@EntryIndexedValue">True</s:Boolean>
89
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=installer/@EntryIndexedValue">True</s:Boolean>
910
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=io/@EntryIndexedValue">True</s:Boolean>
1011
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=io_005Cwatchers/@EntryIndexedValue">True</s:Boolean>

src/GitHub.Api/Helpers/Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
namespace GitHub.Unity
24
{
35
static class Constants
@@ -7,5 +9,8 @@ static class Constants
79
public const string UsageFile = "usage.json";
810
public const string GitInstallPathKey = "GitInstallPath";
911
public const string TraceLoggingKey = "EnableTraceLogging";
12+
13+
public static readonly Version MinimumGitVersion = new Version(2, 11, 0);
14+
public static readonly Version MinimumGitLfsVersion = new Version(2, 2, 0);
1015
}
1116
}

src/GitHub.Api/NewTaskSystem/ProcessTask.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ namespace GitHub.Unity
1111
{
1212
static class ProcessTaskExtensions
1313
{
14-
public static T Configure<T>(this T task, IProcessManager processManager, bool withInput = false)
14+
public static T Configure<T>(this T task, IProcessManager processManager, bool withInput)
1515
where T : IProcess
1616
{
17-
return processManager.Configure(task, withInput);
17+
return processManager.Configure(task, withInput: withInput);
1818
}
1919

20-
public static T Configure<T>(this T task, IProcessManager processManager, string executable, string arguments,
21-
NPath workingDirectory = null, bool withInput = false)
20+
public static T Configure<T>(this T task, IProcessManager processManager, string executable = null,
21+
string arguments = null,
22+
NPath workingDirectory = null,
23+
bool withInput = false)
2224
where T : IProcess
2325
{
24-
return processManager.Configure(task, executable, arguments, workingDirectory, withInput);
26+
return processManager.Configure(task, executable?.ToNPath(), arguments, workingDirectory, withInput);
2527
}
2628
}
2729

src/GitHub.Api/OutputProcessors/IProcessManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ namespace GitHub.Unity
44
{
55
interface IProcessManager
66
{
7-
T Configure<T>(T processTask, bool withInput = false) where T : IProcess;
8-
T Configure<T>(T processTask, string executableFileName, string arguments, NPath workingDirectory = null, bool withInput = false)
7+
T Configure<T>(T processTask, NPath executable = null, string arguments = null, NPath workingDirectory = null, bool withInput = false)
98
where T : IProcess;
109
IProcess Reconnect(IProcess processTask, int i);
1110
CancellationToken CancellationToken { get; }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Text.RegularExpressions;
3+
4+
namespace GitHub.Unity
5+
{
6+
class LfsVersionOutputProcessor : BaseOutputProcessor<Version>
7+
{
8+
public static Regex GitLfsVersionRegex = new Regex(@"git-lfs/([\d]+)\.([\d]+)\.([\d]+)");
9+
10+
public override void LineReceived(string line)
11+
{
12+
if (String.IsNullOrEmpty(line))
13+
return;
14+
15+
var match = GitLfsVersionRegex.Match(line);
16+
17+
if (match.Groups.Count > 0)
18+
{
19+
var major = Int32.Parse(match.Groups[1].Value);
20+
var minor = Int32.Parse(match.Groups[2].Value);
21+
var build = Int32.Parse(match.Groups[3].Value);
22+
var version = new Version(major, minor, build);
23+
RaiseOnEntry(version);
24+
}
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)