Skip to content

Commit 9803c23

Browse files
authored
Merge pull request #521 from qmfrederik/features/managed-git
Add a managed Git implementation
2 parents 13d1fd6 + 670cbe6 commit 9803c23

File tree

107 files changed

+8161
-1815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+8161
-1815
lines changed

azure-pipelines.yml

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ stages:
3939
matrix:
4040
linux:
4141
imageName: 'ubuntu-20.04'
42-
testModifier: -f netcoreapp3.1
42+
testModifier: -f net5.0
4343
windows:
4444
imageName: 'windows-2019'
4545
testModifier:
@@ -58,10 +58,17 @@ stages:
5858
displayName: Configure git commit author for testing
5959
6060
- task: UseDotNet@2
61-
displayName: Install .NET Core SDK 3.1.100
61+
displayName: Install .NET Core SDK 5.0.100
6262
inputs:
6363
packageType: sdk
64-
version: 3.1.100
64+
version: 5.0.100
65+
66+
- task: UseDotNet@2
67+
displayName: Install .NET Core 3.1
68+
inputs:
69+
packageType: runtime
70+
version: 3.1.x
71+
6572
- script: dotnet --info
6673
displayName: Show dotnet SDK info
6774

@@ -107,8 +114,8 @@ stages:
107114
--filter "TestCategory!=FailsOnAzurePipelines"
108115
--logger "trx;LogFileName=$(Build.ArtifactStagingDirectory)/TestLogs/TestResults.trx"
109116
--results-directory $(Build.ArtifactStagingDirectory)/CodeCoverage/
110-
--collect:"XPlat Code Coverage"
111-
--
117+
--collect:"XPlat Code Coverage"
118+
--
112119
RunConfiguration.DisableAppDomain=true
113120
displayName: Run tests
114121
workingDirectory: src
@@ -197,6 +204,7 @@ stages:
197204
condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['System.TeamFoundationCollectionUri'], 'https://dev.azure.com/andrewarnott/'), ne(variables['Build.Reason'], 'PullRequest'))
198205
199206
- stage: Test
207+
displayName: Functional testing
200208
jobs:
201209
- job: linux
202210
strategy:
@@ -229,3 +237,79 @@ stages:
229237
vmImage: macOS-10.15
230238
steps:
231239
- template: azure-pipelines/xplattest-pipeline.yml
240+
241+
- stage: PerfAnalysis
242+
displayName: Perf analysis
243+
dependsOn: []
244+
jobs:
245+
- job: PerfTest
246+
strategy:
247+
matrix:
248+
ubuntu:
249+
imageName: ubuntu-18.04
250+
repoDir: '~/git'
251+
windows:
252+
imageName: windows-2019
253+
repoDir: '${USERPROFILE}/source/repos'
254+
macOS:
255+
imageName: macOS-10.15
256+
repoDir: '~/git'
257+
pool:
258+
vmImage: $(imageName)
259+
steps:
260+
- task: UseDotNet@2
261+
displayName: Install .NET Core SDK 2.1.811
262+
inputs:
263+
packageType: sdk
264+
version: 2.1.811
265+
- task: UseDotNet@2
266+
displayName: Install .NET Core SDK 3.1.100
267+
inputs:
268+
packageType: sdk
269+
version: 3.1.100
270+
- task: UseDotNet@2
271+
displayName: Install .NET Core SDK 5.0.100
272+
inputs:
273+
packageType: sdk
274+
version: 5.0.100
275+
- script: dotnet --info
276+
displayName: Show dotnet SDK info
277+
- bash: |
278+
mkdir -p $(repoDir)
279+
git clone https://github.com/xunit/xunit $(repoDir)/xunit
280+
git clone https://github.com/gimlichael/Cuemon $(repoDir)/Cuemon
281+
git clone https://github.com/kerryjiang/SuperSocket $(repoDir)/SuperSocket
282+
git clone https://github.com/dotnet/NerdBank.GitVersioning $(repoDir)/NerdBank.GitVersioning
283+
displayName: Clone test repositories
284+
- script: |
285+
dotnet build -c Release
286+
workingDirectory: src/
287+
displayName: Build in Release mode
288+
- script: |
289+
dotnet run -c Release -f netcoreapp3.1 -- --filter GetVersionBenchmarks --artifacts $(Build.ArtifactStagingDirectory)/benchmarks/packed/$(imageName)
290+
workingDirectory: src/NerdBank.GitVersioning.Benchmarks
291+
displayName: Run benchmarks (packed)
292+
- bash: |
293+
cd $(repoDir)/xunit
294+
git unpack-objects < .git/objects/pack/*.pack
295+
296+
cd $(repoDir)/Cuemon
297+
git unpack-objects < .git/objects/pack/*.pack
298+
299+
cd $(repoDir)/SuperSocket
300+
git unpack-objects < .git/objects/pack/*.pack
301+
302+
cd $(repoDir)/NerdBank.GitVersioning
303+
git unpack-objects < .git/objects/pack/*.pack
304+
displayName: Unpack Git repositories
305+
- script: |
306+
dotnet run -c Release -f netcoreapp3.1 -- --filter GetVersionBenchmarks --artifacts $(Build.ArtifactStagingDirectory)/benchmarks/unpacked/$(imageName)
307+
workingDirectory: src/NerdBank.GitVersioning.Benchmarks
308+
displayName: Run benchmarks (unpacked)
309+
- task: PublishBuildArtifacts@1
310+
inputs:
311+
PathtoPublish: $(Build.ArtifactStagingDirectory)/benchmarks
312+
ArtifactName: benchmarks
313+
ArtifactType: Container
314+
displayName: Publish benchmarks artifacts
315+
condition: succeededOrFailed()

doc/nuget-acquisition.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ If in a project that uses PackageReference for this package reference, you shoul
1414
After installing this NuGet package, you may need to configure the version generation logic
1515
in order for it to work properly.
1616

17-
When using packages.config, the configuration is handled automatically via the tools\Install.ps1 script.
18-
When using project.json or PackageReference, you can run the script tools\Create-VersionFile.ps1 to help
19-
you create the version.json file and remove the old assembly attributes.
17+
We recommend installing the `nbgv` tool using `dotnet tool install -g nbgv`.
18+
Then use `nbgv install` to add the package reference and `version.json` file to your repo.
19+
But you can simply add the package reference yourself, and create the `version.json` in your repo
20+
with content conforming to [this doc](versionJson.md).
2021

2122
The scripts will look for the presence of a version.json or version.txt file.
2223
If one already exists, nothing happens. If the version file does not exist,

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": "3.1.100"
3+
"version": "5.0.100"
44
}
55
}

src/Cake.GitVersioning/Cake.GitVersioning.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<ItemGroup>
3333
<PackageReference Include="Cake.Core" Version="0.33.0" PrivateAssets="all" />
3434
<PackageReference Include="DotNetMDDocs" Version="0.111.0" Condition=" '$(GenerateMarkdownApiDocs)' == 'true' " />
35-
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.1.93" />
35+
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.3.37" />
3636
</ItemGroup>
3737

3838
<ItemGroup>

src/Cake.GitVersioning/GitVersioningAliases.cs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public static class GitVersioningAliases
2727
/// Information(GetVersioningGetVersion().SemVer2)
2828
/// });
2929
/// </example>
30-
/// <param name="context">The context.</param>
30+
/// <param name="cakeContext">The context.</param>
3131
/// <param name="projectDirectory">Directory to start the search for version.json.</param>
3232
/// <returns>The version information from Git Versioning.</returns>
3333
[CakeMethodAlias]
34-
public static VersionOracle GitVersioningGetVersion(this ICakeContext context, string projectDirectory = ".")
34+
public static VersionOracle GitVersioningGetVersion(this ICakeContext cakeContext, string projectDirectory = ".")
3535
{
3636
var fullProjectDirectory = (new DirectoryInfo(projectDirectory)).FullName;
3737

@@ -42,30 +42,8 @@ public static VersionOracle GitVersioningGetVersion(this ICakeContext context, s
4242
throw new InvalidOperationException("Could not locate the Cake.GitVersioning library");
4343
}
4444

45-
// Even after adding the folder containing the native libgit2 DLL to the PATH, DllNotFoundException is still thrown
46-
// Workaround this by copying the contents of the found folder to the current directory
47-
GitExtensions.HelpFindLibGit2NativeBinaries(directoryName, out var attemptedDirectory);
48-
49-
// The HelpFindLibGit2NativeBinaries method throws if the directory does not exist
50-
var directoryInfo = new DirectoryInfo(attemptedDirectory);
51-
52-
// There should only be a single file in the directory, but we do not know its extension
53-
// So, we will just get a list of all files rather than trying to determine the correct name and extension
54-
// If there are other files there for some reason, it should not matter as long as we don't overwrite anything in the current directory
55-
var fileInfos = directoryInfo.GetFiles();
56-
57-
foreach (var fileInfo in fileInfos)
58-
{
59-
// Copy the file to the Cake.GitVersioning DLL directory, without overwriting anything
60-
string destFileName = Path.Combine(directoryName, fileInfo.Name);
61-
62-
if (!File.Exists(destFileName))
63-
{
64-
File.Copy(fileInfo.FullName, destFileName);
65-
}
66-
}
67-
68-
return VersionOracle.Create(fullProjectDirectory, null, CloudBuild.Active);
45+
var gitContext = GitContext.Create(fullProjectDirectory);
46+
return new VersionOracle(gitContext, cloudBuild: CloudBuild.Active);
6947
}
7048
}
7149
}

src/Directory.Build.props

Lines changed: 2 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>7.3</LangVersion>
7+
<LangVersion>8.0</LangVersion>
88

99
<SignAssembly>true</SignAssembly>
1010
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)strongname.snk</AssemblyOriginatorKeyFile>
@@ -24,6 +24,7 @@
2424
<LibGit2SharpNativeVersion>2.0.306</LibGit2SharpNativeVersion>
2525
</PropertyGroup>
2626
<ItemGroup>
27+
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.8.0-5.final" PrivateAssets="all" />
2728
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
2829
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
2930
</ItemGroup>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.IO;
3+
using System.Runtime.InteropServices;
4+
using BenchmarkDotNet.Attributes;
5+
using BenchmarkDotNet.Jobs;
6+
7+
namespace Nerdbank.GitVersioning.Benchmarks
8+
{
9+
[SimpleJob(RuntimeMoniker.NetCoreApp31, baseline: true)]
10+
[SimpleJob(RuntimeMoniker.NetCoreApp21)]
11+
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
12+
[SimpleJob(RuntimeMoniker.Net461)]
13+
public class GetVersionBenchmarks
14+
{
15+
// You must manually clone these repositories:
16+
// - On Windows, to %USERPROFILE%\Source\Repose
17+
// - On Unix, to ~/git/
18+
[Params(
19+
"xunit",
20+
"Cuemon",
21+
"SuperSocket",
22+
"NerdBank.GitVersioning")]
23+
public string ProjectDirectory;
24+
25+
public Version Version { get; set; }
26+
27+
[Benchmark(Baseline = true)]
28+
public void GetVersionLibGit2()
29+
{
30+
using var context = GitContext.Create(GetPath(this.ProjectDirectory), writable: true);
31+
var oracle = new VersionOracle(context, cloudBuild: null);
32+
this.Version = oracle.Version;
33+
}
34+
35+
[Benchmark]
36+
public void GetVersionManaged()
37+
{
38+
using var context = GitContext.Create(GetPath(this.ProjectDirectory), writable: false);
39+
var oracle = new VersionOracle(context, cloudBuild: null);
40+
this.Version = oracle.Version;
41+
}
42+
43+
private static string GetPath(string repositoryName)
44+
{
45+
string path = null;
46+
47+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
48+
{
49+
path = Path.Combine(
50+
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
51+
@"Source\Repos",
52+
repositoryName);
53+
}
54+
else
55+
{
56+
path = Path.Combine(
57+
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
58+
@"git",
59+
repositoryName);
60+
}
61+
62+
if (!Directory.Exists(path))
63+
{
64+
throw new DirectoryNotFoundException($"The directory '{path}' could not be found");
65+
}
66+
67+
return path;
68+
}
69+
}
70+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net5.0</TargetFrameworks>
5+
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net461</TargetFrameworks>
6+
<OutputType>Exe</OutputType>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8+
<PlatformTarget>AnyCPU</PlatformTarget>
9+
<IsPackable>false</IsPackable>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
14+
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.12.0" />
15+
<PackageReference Include="Nerdbank.GitVersioning.LKG" Version="3.3.37" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="../NerdBank.GitVersioning/NerdBank.GitVersioning.csproj" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using BenchmarkDotNet.Running;
3+
4+
namespace Nerdbank.GitVersioning.Benchmarks
5+
{
6+
class Program
7+
{
8+
static void Main(string[] args) =>
9+
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
10+
}
11+
}

0 commit comments

Comments
 (0)