Skip to content

Commit

Permalink
Merge pull request #2085 from libgit2/net8-updates
Browse files Browse the repository at this point in the history
Updates for .NET 8
  • Loading branch information
bording authored Mar 16, 2024
2 parents d9bf967 + 729ef8d commit bfdb02a
Show file tree
Hide file tree
Showing 93 changed files with 422 additions and 295 deletions.
56 changes: 39 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3.5.0
uses: actions/checkout@v4.1.2
with:
fetch-depth: 0
- name: Install .NET SDK
uses: actions/setup-dotnet@v3.0.3
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 8.0.x
- name: Build
run: dotnet build LibGit2Sharp.sln --configuration Release
- name: Upload packages
uses: actions/upload-artifact@v3.1.2
uses: actions/upload-artifact@v4.3.1
with:
name: NuGet packages
path: bin/Packages/
path: artifacts/package/
retention-days: 7
- name: Verify trimming compatibility
run: dotnet publish TrimmingTestApp
Expand All @@ -37,24 +37,36 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
arch: [ amd64 ]
os: [ windows-2019, macos-11 ]
tfm: [ net472, net6.0, net7.0 ]
arch: [ x64 ]
os: [ windows-2019, windows-2022, macos-11, macos-12, macos-13 ]
tfm: [ net472, net6.0, net8.0 ]
exclude:
- os: macos-11
tfm: net472
- os: macos-11
tfm: net8.0
- os: macos-12
tfm: net472
- os: macos-13
tfm: net472
include:
- arch: arm64
os: macos-14
tfm: net6.0
- arch: arm64
os: macos-14
tfm: net8.0
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3.5.0
uses: actions/checkout@v4.1.2
with:
fetch-depth: 0
- name: Install .NET SDK
uses: actions/setup-dotnet@v3.0.3
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: |
8.0.x
7.0.x
6.0.x
- name: Run ${{ matrix.tfm }} tests
run: dotnet test LibGit2Sharp.sln --configuration Release --framework ${{ matrix.tfm }} --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
Expand All @@ -65,22 +77,32 @@ jobs:
matrix:
arch: [ amd64 ]
# arch: [ amd64, arm64 ]
distro: [ alpine.3.13, alpine.3.14, alpine.3.15, alpine.3.16, alpine.3.17, centos.stream.8, debian.10, debian.11, fedora.36, ubuntu.18.04, ubuntu.20.04, ubuntu.22.04 ]
sdk: [ '6.0', '7.0' ]
distro: [ alpine.3.13, alpine.3.14, alpine.3.15, alpine.3.16, alpine.3.17, alpine.3.18, centos.stream.8, debian.10, debian.11, fedora.36, fedora.37, ubuntu.18.04, ubuntu.20.04, ubuntu.22.04 ]
sdk: [ '6.0', '8.0' ]
exclude:
- distro: alpine.3.13
sdk: '7.0'
sdk: '8.0'
- distro: alpine.3.14
sdk: '7.0'
sdk: '8.0'
- distro: alpine.3.15
sdk: '8.0'
- distro: alpine.3.16
sdk: '8.0'
- distro: debian.10
sdk: '8.0'
- distro: fedora.36
sdk: '8.0'
- distro: ubuntu.18.04
sdk: '8.0'
include:
- sdk: '6.0'
tfm: net6.0
- sdk: '7.0'
tfm: net7.0
- sdk: '8.0'
tfm: net8.0
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3.5.0
uses: actions/checkout@v4.1.2
with:
fetch-depth: 0
- name: Setup QEMU
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ _ReSharper*/
*.DotSettings

_NCrunch_LibGit2Sharp/
packages/
artifacts/
worktree.playlist
5 changes: 2 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project>

<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputPath>$(MSBuildThisFileDirectory)bin\$(MSBuildProjectName)\$(Configuration)\</OutputPath>
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
<PackageOutputPath>$(MSBuildThisFileDirectory)bin\Packages\</PackageOutputPath>
<UseArtifactsOutput>true</UseArtifactsOutput>
<DefineConstants Condition=" '$(ExtraDefine)' != '' ">$(DefineConstants);$(ExtraDefine)</DefineConstants>
</PropertyGroup>

Expand Down
5 changes: 2 additions & 3 deletions LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using Xunit.Extensions;

namespace LibGit2Sharp.Tests
{
Expand Down Expand Up @@ -103,7 +102,7 @@ public void CanCreateAnUnbornBranch()
public void CanCreateBranchUsingAbbreviatedSha()
{
string path = SandboxBareTestRepo();
using (var repo = new Repository(path, new RepositoryOptions{ Identity = Constants.Identity }))
using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity }))
{
EnableRefLog(repo);

Expand Down Expand Up @@ -1001,7 +1000,7 @@ public void OnlyOneBranchIsTheHead()
continue;
}

Assert.True(false, string.Format("Both '{0}' and '{1}' appear to be Head.", head.CanonicalName, branch.CanonicalName));
Assert.Fail(string.Format("Both '{0}' and '{1}' appear to be Head.", head.CanonicalName, branch.CanonicalName));
}

Assert.NotNull(head);
Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ public void CanEnumerateCommitsFromATagWhichPointsToABlob()
{
AssertEnumerationOfCommits(
repo => new CommitFilter { IncludeReachableFrom = repo.Tags["point_to_blob"] },
new string[] { });
Array.Empty<string>());
}

[Fact]
Expand All @@ -421,7 +421,7 @@ public void CanEnumerateCommitsFromATagWhichPointsToATree()

AssertEnumerationOfCommitsInRepo(repo,
r => new CommitFilter { IncludeReachableFrom = tag },
new string[] { });
Array.Empty<string>());
}
}

Expand Down
4 changes: 2 additions & 2 deletions LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LibGit2Sharp.Tests
{
public class DiffTreeToTreeFixture : BaseFixture
{
private static readonly string subBranchFilePath = String.Join("/", "1", "branch_file.txt");
private static readonly string subBranchFilePath = string.Join("/", "1", "branch_file.txt");

[Fact]
public void ComparingATreeAgainstItselfReturnsNoDifference()
Expand All @@ -27,7 +27,7 @@ public void ComparingATreeAgainstItselfReturnsNoDifference()
using (var patch = repo.Diff.Compare<Patch>(tree, tree))
{
Assert.Empty(patch);
Assert.Equal(String.Empty, patch);
Assert.Equal(string.Empty, patch);
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions LibGit2Sharp.Tests/FetchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void CanFetchIntoAnEmptyRepository(string url)
}

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);

// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
Expand All @@ -62,7 +62,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions
{
CredentialsProvider = Constants.PrivateRepoCredentials
}, null);
Expand Down Expand Up @@ -98,7 +98,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
}

// Perform the actual fetch
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions
{
TagFetchMode = TagFetchMode.All,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
Expand Down Expand Up @@ -179,7 +179,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int
r => r.TagFetchMode = tagFetchMode);

// Perform the actual fetch.
Commands.Fetch(repo, remoteName, new string[0], null, null);
Commands.Fetch(repo, remoteName, Array.Empty<string>(), null, null);

// Verify the number of fetched tags.
Assert.Equal(expectedTagCount, repo.Tags.Count());
Expand All @@ -197,7 +197,7 @@ public void CanFetchAllTagsAfterAnInitialClone()

using (var repo = new Repository(clonedRepoPath))
{
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
Commands.Fetch(repo, "origin", Array.Empty<string>(), new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
}
}

Expand All @@ -223,17 +223,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()

// No pruning when the configuration entry isn't defined
Assert.Null(clonedRepo.Config.Get<bool>("fetch.prune"));
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));

// No pruning when the configuration entry is set to false
clonedRepo.Config.Set<bool>("fetch.prune", false);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));

// Auto pruning when the configuration entry is set to true
clonedRepo.Config.Set<bool>("fetch.prune", true);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
}
}
Expand All @@ -248,10 +248,10 @@ public void CannotFetchWithForbiddenCustomHeaders()
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

const string knownHeader = "User-Agent: mygit-201";
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null));
}
}

Expand All @@ -265,10 +265,10 @@ public void CanFetchWithCustomHeaders()
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

const string knownHeader = "X-Hello: mygit-201";
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Commands.Fetch(repo, "origin", new string[0], options, null);
Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null);
}
}

Expand All @@ -282,10 +282,10 @@ public void CannotFetchWithMalformedCustomHeaders()
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

const string knownHeader = "Hello world";
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
using (var repo = new Repository(clonedRepoPath))
{
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null));
}
}

Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/FilterBranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public void CanRewriteTreesByInjectingTreeEntry()

AssertSucceedingButNotError();

Assert.Equal(new Commit[0],
Assert.Equal(Array.Empty<Commit>(),
repo.Commits
.QueryBy(new CommitFilter {IncludeReachableFrom = repo.Branches})
.Where(c => c["README"] != null
Expand Down
17 changes: 7 additions & 10 deletions LibGit2Sharp.Tests/FilterFixture.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Threading.Tasks;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using System.Threading.Tasks;

namespace LibGit2Sharp.Tests
{
Expand Down Expand Up @@ -174,7 +173,7 @@ public void CleanFilterWritesOutputToObjectTree()
}

[Fact]
public void CanHandleMultipleSmudgesConcurrently()
public async Task CanHandleMultipleSmudgesConcurrently()
{
const string decodedInput = "This is a substitution cipher";
const string encodedInput = "Guvf vf n fhofgvghgvba pvcure";
Expand All @@ -193,20 +192,18 @@ public void CanHandleMultipleSmudgesConcurrently()

for (int i = 0; i < count; i++)
{
tasks[i] = Task.Factory.StartNew(() =>
tasks[i] = Task.Run(() =>
{
string repoPath = InitNewRepository();
return CheckoutFileForSmudge(repoPath, branchName, encodedInput);
});
}

Task.WaitAll(tasks);
var files = await Task.WhenAll(tasks);

foreach(var task in tasks)
foreach (var file in files)
{
FileInfo expectedFile = task.Result;

string readAllText = File.ReadAllText(expectedFile.FullName);
string readAllText = File.ReadAllText(file.FullName);
Assert.Equal(decodedInput, readAllText);
}
}
Expand Down Expand Up @@ -399,7 +396,7 @@ private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, strin
return expectedPath;
}

private static FileInfo CommitFileOnBranch(Repository repo, string branchName, String content)
private static FileInfo CommitFileOnBranch(Repository repo, string branchName, string content)
{
var branch = repo.CreateBranch(branchName);
Commands.Checkout(repo, branch.FriendlyName);
Expand Down
14 changes: 7 additions & 7 deletions LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks Condition="'$(TargetFrameworks)'==''">net472;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks Condition="'$(TargetFrameworks)'==''">net472;net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand All @@ -11,12 +11,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.console" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" />
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.console" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageReference Include="xunit.skippablefact" Version="1.4.13" />
</ItemGroup>

Expand Down
Loading

0 comments on commit bfdb02a

Please sign in to comment.