Skip to content

Commit 92faaf7

Browse files
committed
Merge remote-tracking branch 'origin/v3.4'
2 parents de02ffc + 1902982 commit 92faaf7

20 files changed

+567
-199
lines changed

3rdPartyNotices.txt

Lines changed: 243 additions & 0 deletions
Large diffs are not rendered by default.

azure-pipelines.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ trigger:
33
branches:
44
include:
55
- master
6-
- 'v*'
6+
- 'v*.*'
77
paths:
88
exclude:
99
- doc
@@ -58,10 +58,10 @@ stages:
5858
displayName: Configure git commit author for testing
5959
6060
- task: UseDotNet@2
61-
displayName: Install .NET Core SDK 5.0.100
61+
displayName: Install .NET Core SDK 5.0.202
6262
inputs:
6363
packageType: sdk
64-
version: 5.0.100
64+
version: 5.0.202
6565

6666
- task: UseDotNet@2
6767
displayName: Install .NET Core 3.1
@@ -306,10 +306,10 @@ stages:
306306
packageType: sdk
307307
version: 3.1.100
308308
- task: UseDotNet@2
309-
displayName: Install .NET Core SDK 5.0.100
309+
displayName: Install .NET Core SDK 5.0.202
310310
inputs:
311311
packageType: sdk
312-
version: 5.0.100
312+
version: 5.0.202
313313
- script: dotnet --info
314314
displayName: Show dotnet SDK info
315315
- bash: |

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "5.0.100"
3+
"version": "5.0.202"
44
}
55
}

src/Directory.Build.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)..\obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
55
<OutputPath>$(MSBuildThisFileDirectory)..\bin\$(MSBuildProjectName)\$(Configuration)\</OutputPath>
66
<DocumentationRootFolder>$(MSBuildThisFileDirectory)..\wiki\api</DocumentationRootFolder>
7-
<LangVersion>8.0</LangVersion>
7+
<LangVersion>9.0</LangVersion>
88

99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)strongname.snk</AssemblyOriginatorKeyFile>
@@ -28,6 +28,9 @@
2828
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
2929
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
3030
</ItemGroup>
31+
<ItemGroup>
32+
<None Include="$(MSBuildThisFileDirectory)..\3rdPartyNotices.txt" Pack="true" PackagePath="" />
33+
</ItemGroup>
3134

3235
<Target Name="PrepareReleaseNotes" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
3336
<PropertyGroup>

src/NerdBank.GitVersioning.Tests/GitContextTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,23 @@ public void SelectDirectory_SubDir()
162162
Assert.Equal("sub", this.Context.RepoRelativeProjectDirectory);
163163
Assert.Equal(absolutePath, this.Context.AbsoluteProjectDirectory);
164164
}
165+
166+
[Fact]
167+
public void GetVersion_PackedHead()
168+
{
169+
using var expandedRepo = TestUtilities.ExtractRepoArchive("PackedHeadRef");
170+
this.Context = this.CreateGitContext(Path.Combine(expandedRepo.RepoPath));
171+
var oracle = new VersionOracle(this.Context);
172+
Assert.Equal("1.0.1", oracle.SimpleVersion.ToString());
173+
this.Context.TrySelectCommit("HEAD");
174+
Assert.Equal("1.0.1", oracle.SimpleVersion.ToString());
175+
}
176+
177+
[Fact]
178+
public void HeadCanonicalName_PackedHead()
179+
{
180+
using var expandedRepo = TestUtilities.ExtractRepoArchive("PackedHeadRef");
181+
this.Context = this.CreateGitContext(Path.Combine(expandedRepo.RepoPath));
182+
Assert.Equal("refs/heads/main", this.Context.HeadCanonicalName);
183+
}
165184
}

src/NerdBank.GitVersioning.Tests/ManagedGit/GitRepositoryTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,47 @@ public void GetMissingObjectByShaTest()
286286
}
287287
}
288288

289+
[Fact]
290+
public void ParseAlternates_SingleValue_Test()
291+
{
292+
var alternates = GitRepository.ParseAlternates(Encoding.UTF8.GetBytes("/home/git/nbgv/.git/objects\n"));
293+
Assert.Collection(
294+
alternates,
295+
a => Assert.Equal("/home/git/nbgv/.git/objects", a));
296+
}
297+
298+
[Fact]
299+
public void ParseAlternates_SingleValue_NoTrailingNewline_Test()
300+
{
301+
var alternates = GitRepository.ParseAlternates(Encoding.UTF8.GetBytes("../repo/.git/objects"));
302+
Assert.Collection(
303+
alternates,
304+
a => Assert.Equal("../repo/.git/objects", a));
305+
}
306+
307+
[Fact]
308+
public void ParseAlternates_TwoValues_Test()
309+
{
310+
var alternates = GitRepository.ParseAlternates(Encoding.UTF8.GetBytes("/home/git/nbgv/.git/objects:../../clone/.git/objects\n"));
311+
Assert.Collection(
312+
alternates,
313+
a => Assert.Equal("/home/git/nbgv/.git/objects", a),
314+
a => Assert.Equal("../../clone/.git/objects", a));
315+
}
316+
317+
[Fact]
318+
public void ParseAlternates_PathWithColon_Test()
319+
{
320+
var alternates = GitRepository.ParseAlternates(
321+
Encoding.UTF8.GetBytes("C:/Users/nbgv/objects:C:/Users/nbgv2/objects/:../../clone/.git/objects\n"),
322+
2);
323+
Assert.Collection(
324+
alternates,
325+
a => Assert.Equal("C:/Users/nbgv/objects", a),
326+
a => Assert.Equal("C:/Users/nbgv2/objects/", a),
327+
a => Assert.Equal("../../clone/.git/objects", a));
328+
}
329+
289330
private static void AssertPath(string expected, string actual)
290331
{
291332
Assert.Equal(

src/NerdBank.GitVersioning.Tests/NerdBank.GitVersioning.Tests.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@
2525
<EmbeddedResource Include="ManagedGit\tree*" />
2626
<EmbeddedResource Include="test.vcprj" />
2727
<EmbeddedResource Include="test.prj" />
28-
<EmbeddedResource Include="repos\submodules.7z" />
28+
<EmbeddedResource Include="repos\*" />
2929
</ItemGroup>
3030
<ItemGroup>
3131
<ProjectReference Include="..\Nerdbank.GitVersioning.Tasks\Nerdbank.GitVersioning.Tasks.csproj" />
3232
<ProjectReference Include="..\NerdBank.GitVersioning\NerdBank.GitVersioning.csproj" />
3333
</ItemGroup>
3434
<ItemGroup>
35-
<PackageReference Include="7z.NET" Version="1.0.3" />
3635
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.10" />
3736
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
3837
<PackageReference Include="Microsoft.Build" Version="15.1.548" ExcludeAssets="runtime" />
@@ -51,7 +50,4 @@
5150
<PackageReference Include="Xunit.SkippableFact" Version="1.3.12" />
5251
<PackageReference Include="Moq" Version="4.14.7" />
5352
</ItemGroup>
54-
<ItemGroup>
55-
<Folder Include="LibGit2\" />
56-
</ItemGroup>
5753
</Project>

src/NerdBank.GitVersioning.Tests/TestUtilities.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#if NET461
2-
using SevenZipNET;
3-
#endif
4-
using Validation;
1+
using Validation;
52

63
using System;
74
using System.Collections.Generic;
@@ -67,36 +64,19 @@ internal static void ExtractEmbeddedResource(string resourcePath, string extract
6764

6865
internal static ExpandedRepo ExtractRepoArchive(string repoArchiveName)
6966
{
70-
#if NET461
7167
string archiveFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
7268
string expandedFolderPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
7369

74-
ExtractEmbeddedResource($"repos.{repoArchiveName}.7z", archiveFilePath);
70+
ExtractEmbeddedResource($"repos.{repoArchiveName}.zip", archiveFilePath);
7571
try
7672
{
77-
for (int retryCount = 0; ; retryCount++)
78-
{
79-
try
80-
{
81-
var extractor = new SevenZipExtractor(archiveFilePath);
82-
extractor.ExtractAll(expandedFolderPath);
83-
return new ExpandedRepo(expandedFolderPath);
84-
}
85-
catch (System.ComponentModel.Win32Exception) when (retryCount < 2)
86-
{
87-
}
88-
}
73+
System.IO.Compression.ZipFile.ExtractToDirectory(archiveFilePath, expandedFolderPath);
74+
return new ExpandedRepo(expandedFolderPath);
8975
}
9076
finally
9177
{
92-
if (File.Exists(archiveFilePath))
93-
{
94-
File.Delete(archiveFilePath);
95-
}
78+
File.Delete(archiveFilePath);
9679
}
97-
#else
98-
throw new PlatformNotSupportedException();
99-
#endif
10080
}
10181

10282
internal class ExpandedRepo : IDisposable

src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,17 @@ public void NotRepo()
4949
Assert.Equal(0, oracle.VersionHeight);
5050
}
5151

52-
[Fact(Skip = "Unstable test. See issue #125")]
52+
[Fact]
5353
public void Submodule_RecognizedWithCorrectVersion()
5454
{
5555
using (var expandedRepo = TestUtilities.ExtractRepoArchive("submodules"))
5656
{
57-
this.Context = this.CreateGitContext(expandedRepo.RepoPath);
58-
59-
this.Context.RepoRelativeProjectDirectory = "a";
57+
this.Context = this.CreateGitContext(Path.Combine(expandedRepo.RepoPath, "a"));
6058
var oracleA = new VersionOracle(this.Context);
6159
Assert.Equal("1.3.1", oracleA.SimpleVersion.ToString());
6260
Assert.Equal("e238b03e75", oracleA.GitCommitIdShort);
6361

64-
this.Context.RepoRelativeProjectDirectory = Path.Combine("b", "projB");
62+
this.Context = this.CreateGitContext(Path.Combine(expandedRepo.RepoPath, "b", "projB"));
6563
var oracleB = new VersionOracle(this.Context);
6664
Assert.Equal("2.5.2", oracleB.SimpleVersion.ToString());
6765
Assert.Equal("3ea7f010c3", oracleB.GitCommitIdShort);
@@ -444,7 +442,7 @@ public void Worktree_Support(bool detachedHead)
444442
var context = this.CreateGitContext(workTreePath);
445443
var oracleWorkTree = new VersionOracle(context);
446444
Assert.Equal(oracleOriginal.Version, oracleWorkTree.Version);
447-
445+
448446
Assert.True(context.TrySelectCommit("HEAD"));
449447
Assert.True(context.TrySelectCommit(this.LibGit2Repository.Head.Tip.Sha));
450448
}
@@ -731,6 +729,28 @@ public void GetVersionHeight_IncludeRootExcludeSome()
731729
Assert.Equal(2, this.GetVersionHeight(relativeDirectory));
732730
}
733731

732+
[Fact]
733+
public void GetVersion_PathFilterInTwoDeepSubDirAndVersionBump()
734+
{
735+
this.InitializeSourceControl();
736+
737+
const string relativeDirectory = "src/lib";
738+
var versionOptions = new VersionOptions
739+
{
740+
Version = new SemanticVersion("1.1"),
741+
PathFilters = new FilterPath[]
742+
{
743+
new FilterPath(".", relativeDirectory),
744+
},
745+
};
746+
this.WriteVersionFile(versionOptions, relativeDirectory);
747+
Assert.Equal(1, this.GetVersionHeight(relativeDirectory));
748+
749+
versionOptions.Version = new SemanticVersion("1.2");
750+
this.WriteVersionFile(versionOptions, relativeDirectory);
751+
Assert.Equal(1, this.GetVersionHeight(relativeDirectory));
752+
}
753+
734754
[Fact]
735755
public void GetVersionHeight_ProjectDirectoryDifferentToVersionJsonDirectory()
736756
{
18.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)