Repository navigation
Expand file tree
/
Copy pathUnityCsReferenceRepository.cs
More file actions
90 lines (76 loc) · 2.57 KB
/
Copy pathUnityCsReferenceRepository.cs
File metadata and controls
90 lines (76 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using LibGit2Sharp;
using Microsoft.Extensions.Logging;
using ZLogger;
namespace UnityApiAnalyzer;
public sealed class UnityCsReferenceRepository : IDisposable
{
public UnityCsReferenceRepository(ILogger<UnityCsReferenceRepository> logger, Workspace rootWorkspace)
{
_logger = logger;
var workspace = rootWorkspace.GetOrCreateDirectory("UnityCsReference");
_logger.ZLogInformation($"Checkout UnityCsReference to {workspace.FullName}");
_logger.LogInformation("Cloning...");
if (!Repository.IsValid(workspace.FullName))
{
Repository.Clone(GitUrl, workspace.FullName, new CloneOptions
{
OnCheckoutProgress =
(s, steps, totalSteps) => { _logger.ZLogInformation($"{s} ({steps} / {totalSteps})"); },
IsBare = false
});
_logger.LogInformation("Cloned");
}
_repository = new Repository(workspace.FullName);
}
private readonly ILogger<UnityCsReferenceRepository> _logger;
private readonly Repository _repository;
private const string GitUrl = "https://github.com/Unity-Technologies/UnityCsReference.git";
public DirectoryInfo Path => new(_repository.Info.WorkingDirectory);
public IEnumerable<UnityVersion> GetVersions()
{
foreach (var tag in _repository.Tags)
{
if (UnityVersion.TryParse(tag.FriendlyName, out var version))
{
yield return version;
}
}
}
public void Fetch()
{
var remote = _repository.Network.Remotes["origin"];
_logger.LogInformation($"Fetching...");
Commands.Fetch(
_repository,
remote.Name,
remote.FetchRefSpecs.Select(x => x.Specification),
new FetchOptions
{
TagFetchMode = TagFetchMode.Auto,
OnProgress = message =>
{
_logger.LogInformation(message);
return true;
}
},
"Fetch");
_logger.LogInformation("Fetched.");
}
public void CheckoutVersion(UnityVersion version)
{
_logger.ZLogInformation($"Checking out version {version}...");
var canonicalName = $"refs/tags/{version}";
Commands.Checkout(
_repository,
canonicalName,
new CheckoutOptions
{
CheckoutModifiers = CheckoutModifiers.Force
}
);
}
public void Dispose()
{
_repository.Dispose();
}
}