-
Notifications
You must be signed in to change notification settings - Fork 892
/
Copy pathVersion.cs
85 lines (75 loc) · 2.61 KB
/
Version.cs
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
using System.Globalization;
using System.Reflection;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// Gets the current LibGit2Sharp version.
/// </summary>
public class Version
{
/// <summary>
/// Needed for mocking purposes.
/// </summary>
protected Version()
{ }
internal static Version Build()
{
return new Version();
}
/// <summary>
/// Returns version of the LibGit2Sharp library.
/// </summary>
public virtual string InformationalVersion
{
get
{
var attribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>();
return attribute.InformationalVersion;
}
}
/// <summary>
/// Returns all the optional features that were compiled into
/// libgit2.
/// </summary>
/// <returns>A <see cref="BuiltInFeatures"/> enumeration.</returns>
public virtual BuiltInFeatures Features
{
get { return Proxy.git_libgit2_features(); }
}
/// <summary>
/// Returns the SHA hash for the libgit2 library.
/// </summary>
public virtual string LibGit2CommitSha => RetrieveAbbrevShaFrom(AssemblyCommitIds.LibGit2CommitSha);
/// <summary>
/// Returns the SHA hash for the LibGit2Sharp library.
/// </summary>
public virtual string LibGit2SharpCommitSha => RetrieveAbbrevShaFrom(AssemblyCommitIds.LibGit2SharpCommitSha);
private string RetrieveAbbrevShaFrom(string sha)
{
var index = sha.Length > 7 ? 7 : sha.Length;
return sha.Substring(0, index);
}
/// <summary>
/// Returns a string representing the LibGit2Sharp version.
/// </summary>
/// <para>
/// The format of the version number is as follows:
/// <para>Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features)</para>
/// </para>
/// <returns></returns>
public override string ToString()
{
return RetrieveVersion();
}
private string RetrieveVersion()
{
string features = Features.ToString();
return string.Format(CultureInfo.InvariantCulture,
"{0} ({1} - {2})",
InformationalVersion,
Platform.ProcessorArchitecture,
features);
}
}
}