Skip to content

Commit b0937d0

Browse files
authored
Merge pull request #2028 from libgit2/minver
Switch to MinVer for versioning
2 parents a7ded29 + 8e1fe56 commit b0937d0

File tree

8 files changed

+39
-55
lines changed

8 files changed

+39
-55
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,7 @@ jobs:
8585
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
8686
- name: Run ${{ matrix.tfm }} tests
8787
run: |
88+
git_command="git config --global --add safe.directory /app"
8889
test_command="dotnet test LibGit2Sharp.sln --configuration Release -p:TargetFrameworks=${{ matrix.tfm }} --logger "GitHubActions" -p:ExtraDefine=LEAKS_IDENTIFYING"
89-
docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$test_command"
90+
docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$git_command && $test_command"
91+

LibGit2Sharp.Tests/GlobalSettingsFixture.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,25 @@ public void CanGetMinimumCompiledInFeatures()
2323
public void CanRetrieveValidVersionString()
2424
{
2525
// Version string format is:
26-
// Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features)
26+
// Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features)
2727
// Example output:
28-
// "0.25.0-preview.52+871d13a67f.libgit2-15e1193 (x86 - Threads, Https)"
28+
// "0.27.0-preview.0.1896+libgit2-c058aa8.c1ac3ed74487da5fac24cf1e48dc8ea71e917b75 (x64 - Threads, Https, NSec)"
2929

3030
string versionInfo = GlobalSettings.Version.ToString();
3131

3232
// The GlobalSettings.Version returned string should contain :
3333
// version: '0.25.0[-previewTag]' LibGit2Sharp version number.
34-
// git2SharpHash: '871d13a67f' LibGit2Sharp hash.
34+
// git2SharpHash: 'c1ac3ed74487da5fac24cf1e48dc8ea71e917b75' LibGit2Sharp hash.
3535
// arch: 'x86' or 'x64' libgit2 target.
3636
// git2Features: 'Threads, Ssh' libgit2 features compiled with.
37-
string regex = @"^(?<version>\d+\.\d+\.\d+(-[\w\-\.]+)?\+((?<git2SharpHash>[a-f0-9]{10})\.)?libgit2-[a-f0-9]{7}) \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
37+
string regex = @"^(?<version>\d+\.\d+\.\d+(-[\w\-\.]+)?)\+libgit2-[a-f0-9]{7}\.((?<git2SharpHash>[a-f0-9]{40}))? \((?<arch>\w+) - (?<git2Features>(?:\w*(?:, )*\w+)*)\)$";
3838

3939
Assert.NotNull(versionInfo);
4040

4141
Match regexResult = Regex.Match(versionInfo, regex);
4242

4343
Assert.True(regexResult.Success, "The following version string format is enforced:" +
44-
"Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features). " +
44+
"Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features). " +
4545
"But found \"" + versionInfo + "\" instead.");
4646
}
4747

LibGit2Sharp.sln

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio Version 16
3-
VisualStudioVersion = 16.0.28803.202
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.33516.290
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibGit2Sharp", "LibGit2Sharp\LibGit2Sharp.csproj", "{EE6ED99F-CB12-4683-B055-D28FC7357A34}"
66
EndProject
@@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1313
Directory.Build.props = Directory.Build.props
1414
Targets\GenerateNativeDllName.targets = Targets\GenerateNativeDllName.targets
1515
nuget.config = nuget.config
16-
version.json = version.json
1716
EndProjectSection
1817
EndProject
1918
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeLibraryLoadTestApp.x86", "NativeLibraryLoadTestApp\x86\NativeLibraryLoadTestApp.x86.csproj", "{86453D2C-4953-4DF4-B12A-ADE579608BAA}"

LibGit2Sharp/LibGit2Sharp.csproj

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<PackageIcon>square-logo.png</PackageIcon>
1818
<PackageLicenseFile>App_Readme/LICENSE.md</PackageLicenseFile>
1919
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
20+
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
21+
<MinVerBuildMetadata Condition="'$(libgit2_hash)' != ''">libgit2-$(libgit2_hash.Substring(0,7))</MinVerBuildMetadata>
2022
</PropertyGroup>
2123

2224
<ItemGroup>
@@ -32,15 +34,15 @@
3234
<ItemGroup>
3335
<PackageReference Include="LibGit2Sharp.NativeBinaries" Version="[2.0.319]" PrivateAssets="none" />
3436
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="all" />
35-
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.220" PrivateAssets="all" />
37+
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="all" />
3638
</ItemGroup>
3739

3840
<Import Project="..\Targets\CodeGenerator.targets" />
3941
<Import Project="..\Targets\GenerateNativeDllName.targets" />
4042

41-
<Target Name="SetNuSpecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
43+
<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
4244
<PropertyGroup>
43-
<PackageReleaseNotes>https://github.com/libgit2/libgit2sharp/blob/$(GitCommitIdShort)/CHANGES.md#libgit2sharp-changes</PackageReleaseNotes>
45+
<PackageReleaseNotes>https://github.com/libgit2/libgit2sharp/blob/$(SourceRevisionId)/CHANGES.md</PackageReleaseNotes>
4446
</PropertyGroup>
4547
</Target>
4648

LibGit2Sharp/Version.cs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Globalization;
2+
using System.Reflection;
23
using LibGit2Sharp.Core;
34

45
namespace LibGit2Sharp
@@ -22,7 +23,14 @@ internal static Version Build()
2223
/// <summary>
2324
/// Returns version of the LibGit2Sharp library.
2425
/// </summary>
25-
public virtual string InformationalVersion => ThisAssembly.AssemblyInformationalVersion;
26+
public virtual string InformationalVersion
27+
{
28+
get
29+
{
30+
var attribute = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>();
31+
return attribute.InformationalVersion;
32+
}
33+
}
2634

2735
/// <summary>
2836
/// Returns all the optional features that were compiled into
@@ -55,7 +63,7 @@ private string RetrieveAbbrevShaFrom(string sha)
5563
/// </summary>
5664
/// <para>
5765
/// The format of the version number is as follows:
58-
/// <para>Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features)</para>
66+
/// <para>Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features)</para>
5967
/// </para>
6068
/// <returns></returns>
6169
public override string ToString()

Targets/CodeGenerator.targets

+13-24
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<Project>
22

3-
<PropertyGroup>
4-
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5-
</PropertyGroup>
6-
73
<Target Name="DefineProperties">
84
<PropertyGroup>
5+
<SourceRevisionIdPath>$(IntermediateOutputPath)SourceRevisionId.txt</SourceRevisionIdPath>
96
<UniqueIdentifierPath>$(IntermediateOutputPath)UniqueIdentifier.g.cs</UniqueIdentifierPath>
107
<AssemblyCommitIdsPath>$(IntermediateOutputPath)AssemblyCommitIds.g.cs</AssemblyCommitIdsPath>
118
</PropertyGroup>
129
</Target>
1310

11+
<Target Name="WriteSourceRevisionIdToFile" AfterTargets="AddSourceRevisionToInformationalVersion" DependsOnTargets="DefineProperties">
12+
<WriteLinesToFile File="$(SourceRevisionIdPath)" Lines="$(SourceRevisionId)" Overwrite="true" WriteOnlyWhenDifferent="true" />
13+
<ItemGroup>
14+
<FileWrites Include="$(SourceRevisionIdPath)" />
15+
</ItemGroup>
16+
</Target>
1417

15-
<Target Name="GenerateUniqueIdentifierCs" Inputs="$(VersionSourceFile)" Outputs="$(UniqueIdentifierPath)" BeforeTargets="CoreCompile" AfterTargets="GenerateAssemblyVersionInfo" DependsOnTargets="DefineProperties">
16-
18+
<Target Name="GenerateUniqueIdentifierCs" Inputs="$(SourceRevisionIdPath)" Outputs="$(UniqueIdentifierPath)" BeforeTargets="CoreCompile" AfterTargets="WriteSourceRevisionIdToFile" DependsOnTargets="DefineProperties">
1719
<PropertyGroup>
18-
<UniqueIdentifier>$([System.Guid]::NewGuid())</UniqueIdentifier>
19-
<UniqueIdentifier Condition="'$(GitCommitId)' != ''">$(GitCommitId)</UniqueIdentifier>
20+
<UniqueIdentifier>$(SourceRevisionId)</UniqueIdentifier>
21+
<UniqueIdentifier Condition="'$(UniqueIdentifier)' == ''">$([System.Guid]::NewGuid())</UniqueIdentifier>
2022
<UniqueIdSourceLines>
2123
namespace LibGit2Sharp.Core
2224
{
@@ -34,24 +36,12 @@
3436
<Compile Include="$(UniqueIdentifierPath)" />
3537
<FileWrites Include="$(UniqueIdentifierPath)" />
3638
</ItemGroup>
37-
38-
</Target>
39-
40-
41-
<Target Name="AddNativeDllCommitShaToBuildMetadata" BeforeTargets="GetBuildVersion">
42-
43-
<ItemGroup>
44-
<BuildMetadata Include="libgit2-$(libgit2_hash.Substring(0,7))" />
45-
</ItemGroup>
46-
4739
</Target>
4840

49-
50-
<Target Name="GenerateAssemblyCommitIdsCs" Inputs="$(libgit2_propsfile);$(VersionSourceFile)" Outputs="$(AssemblyCommitIdsPath)" BeforeTargets="CoreCompile" AfterTargets="GenerateAssemblyVersionInfo" DependsOnTargets="DefineProperties">
51-
41+
<Target Name="GenerateAssemblyCommitIdsCs" Inputs="$(libgit2_propsfile);$(SourceRevisionIdPath)" Outputs="$(AssemblyCommitIdsPath)" BeforeTargets="CoreCompile" AfterTargets="WriteSourceRevisionIdToFile" DependsOnTargets="DefineProperties">
5242
<PropertyGroup>
53-
<LibGit2SharpCommitSha>unknown</LibGit2SharpCommitSha>
54-
<LibGit2SharpCommitSha Condition="'$(GitCommitId)' != ''">$(GitCommitId)</LibGit2SharpCommitSha>
43+
<LibGit2SharpCommitSha>$(SourceRevisionId)</LibGit2SharpCommitSha>
44+
<LibGit2SharpCommitSha Condition="'$(LibGit2SharpCommitSha)' == ''">unknown</LibGit2SharpCommitSha>
5545
<AssemblyCommitIdsSourceLines>
5646
namespace LibGit2Sharp
5747
{
@@ -70,7 +60,6 @@
7060
<Compile Include="$(AssemblyCommitIdsPath)" />
7161
<FileWrites Include="$(AssemblyCommitIdsPath)" />
7262
</ItemGroup>
73-
7463
</Target>
7564

7665
</Project>

Targets/GenerateNativeDllName.targets

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<Project>
22

3-
<PropertyGroup>
4-
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5-
</PropertyGroup>
6-
73
<Target Name="DefineNativeDllName">
84
<PropertyGroup>
95
<NativeDllNamePath>$(IntermediateOutputPath)NativeDllName.g.cs</NativeDllNamePath>
@@ -30,4 +26,5 @@
3026
<FileWrites Include="$(NativeDllNamePath)" />
3127
</ItemGroup>
3228
</Target>
29+
3330
</Project>

version.json

-13
This file was deleted.

0 commit comments

Comments
 (0)