8000 Make GlobalSettings.Version expose the full version · odedw/libgit2sharp@fabaa5d · GitHub
[go: up one dir, main page]

Skip to content

Commit fabaa5d

Browse files
committed
Make GlobalSettings.Version expose the full version
1 parent 22bf587 commit fabaa5d

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

LibGit2Sharp.Tests/GlobalSettingsFixture.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Text.RegularExpressions;
1+
using System;
2+
using System.Text.RegularExpressions;
23
using LibGit2Sharp.Tests.TestHelpers;
34
using Xunit;
45

@@ -26,26 +27,31 @@ public void CanRetrieveValidVersionString()
2627
string versionInfo = GlobalSettings.Version.ToString();
2728

2829
// The GlobalSettings.Version returned string should contain :
29-
// version:'0.17.0' LibGit2Sharp version number.
30+
// version: '0.17.0[.198[-pre]]' LibGit2Sharp version number.
3031
// git2SharpHash:'unknown' ( when compiled from source ) else LibGit2Sharp library hash.
3132
// git2hash: '06d772d' LibGit2 library hash.
3233
// arch: 'x86' or 'amd64' LibGit2 target.
3334
// git2Features: 'Threads, Ssh' LibGit2 features compiled with.
34-
string regex = @"^(?<version>\d{1,}\.\d{1,2}\.\d{1,3})-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
35+
string regex = @"^(?<version>\d{1,}\.\d{1,2}\.\d{1,3}(\.\d{1,5}(-pre)?)?)-(?<git2SharpHash>\w+)-(?<git2Hash>\w+) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
3536

3637
Assert.NotNull(versionInfo);
3738

3839
Match regexResult = Regex.Match(versionInfo, regex);
3940

4041
Assert.True(regexResult.Success, "The following version string format is enforced:" +
41-
"Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)");
42+
"Major.Minor.Patch[.Build['-pre']]-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - features)");
4243

4344
GroupCollection matchGroups = regexResult.Groups;
4445

4546
// Check that all groups are valid
46-
foreach (Group group in matchGroups)
47+
for (int i = 0; i < matchGroups.Count; i++)
4748
{
48-
Assert.True(group.Success);
49+
if (i == 1 || i == 2) // Build number and '-pre' are optional
50+
{
51+
continue;
52+
}
53+
54+
Assert.True(matchGroups[i].Success);
4955
}
5056
}
5157
}

LibGit2Sharp/Version.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System.Globalization;
1+
using System;
2+
using System.Globalization;
23
using System.IO;
4+
using System.Linq;
35
using System.Reflection;
46
using LibGit2Sharp.Core;
57

@@ -24,9 +26,10 @@ internal static Version Build()
2426
}
2527

2628
/// <summary>
27-
/// Returns the <see cref="System.Version" /> of the
29+
/// Returns the <see cref="System.Version" /> of the
2830
/// the LibGit2Sharp library.
2931
/// </summary>
32+
[Obsolete("This property will be removed in the next release. Please use InformationalVersion instead.")]
3033
public virtual System.Version MajorMinorPatch
3134
{
3235
get
@@ -35,6 +38,21 @@ public virtual System.Version MajorMinorPatch
3538
}
3639
}
3740

41+
/// <summary>
42+
/// Returns version of the LibGit2Sharp library.
43+
/// </summary>
44+
public virtual string InformationalVersion
45+
{
46+
get
47+
{
48+
var attribute = (AssemblyInformationalVersionAttribute)assembly
49+
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)
50+
.Single();
51+
52+
return attribute.InformationalVersion;
53+
}
54+
}
55+
3856
/// <summary>
3957
/// Returns all the optional features that were compiled into
4058
/// libgit2.
@@ -49,7 +67,7 @@ public virtual BuiltInFeatures Features
4967
}
5068

5169
/// <summary>
52-
/// Returns the SHA hash for the libgit2 library.
70+
/// Returns the SHA hash for the libgit2 library.
5371
/// </summary>
5472
public virtual string LibGit2CommitSha
5573
{
@@ -90,7 +108,7 @@ private string RetrieveVersion()
90108
return string.Format(
91109
CultureInfo.InvariantCulture,
92110
"{0}-{1}-{2} ({3} - {4})",
93-
MajorMinorPatch.ToString(3),
111+
InformationalVersion,
94112
LibGit2SharpCommitSha,
95113
LibGit2CommitSha,
96114
NativeMethods.ProcessorArchitecture,

0 commit comments

Comments
 (0)
0