From a7445ad08fc824d3e69241f94ba3a02be394ae36 Mon Sep 17 00:00:00 2001
From: yahavx <38952809+yahavx@users.noreply.github.com>
Date: Mon, 25 Jan 2021 00:54:30 +0200
Subject: [PATCH 001/147] Update Branch.cs
Fix documentation typo
---
LibGit2Sharp/Branch.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs
index d023e6153..807456688 100644
--- a/LibGit2Sharp/Branch.cs
+++ b/LibGit2Sharp/Branch.cs
@@ -162,7 +162,7 @@ public virtual string UpstreamBranchCanonicalName
/// If this is a local branch, this will return the configured
/// to fetch from and push to. If this is a
/// remote-tracking branch, this will return the name of the remote
- /// containing the tracked branch. If there no tracking information
+ /// containing the tracked branch. If there is no tracking information,
/// this will return null.
///
///
From b78b2900dfe3dc835e0e79f6e542672826bdbc9a Mon Sep 17 00:00:00 2001
From: Robin Ebert
Date: Tue, 25 May 2021 11:02:10 +0200
Subject: [PATCH 002/147] Adjust GitStatusOptions to match structure of native
libgit2
This fixes a marshaling bug that causes a segmentation fault
---
LibGit2Sharp/Core/GitStatusOptions.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/LibGit2Sharp/Core/GitStatusOptions.cs b/LibGit2Sharp/Core/GitStatusOptions.cs
index 3e9dbd5d9..d577cefe6 100644
--- a/LibGit2Sharp/Core/GitStatusOptions.cs
+++ b/LibGit2Sharp/Core/GitStatusOptions.cs
@@ -13,6 +13,8 @@ internal class GitStatusOptions : IDisposable
public GitStrArrayManaged PathSpec;
+ public IntPtr Baseline = IntPtr.Zero;
+
public void Dispose()
{
PathSpec.Dispose();
From 8a61eec544504f9cd79cf78d7bb1694e0737ec88 Mon Sep 17 00:00:00 2001
From: Robert
Date: Thu, 1 Jul 2021 14:49:29 +1000
Subject: [PATCH 003/147] Update `git_worktree_add_options` struct to include
ref pointer Native struct
https://github.com/libgit2/libgit2/blob/main/include/git2/worktree.h#L88
Fixes https://github.com/libgit2/libgit2sharp/issues/1885
---
LibGit2Sharp/Core/GitWorktree.cs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/LibGit2Sharp/Core/GitWorktree.cs b/LibGit2Sharp/Core/GitWorktree.cs
index 64f90ebb7..c71cb16c0 100644
--- a/LibGit2Sharp/Core/GitWorktree.cs
+++ b/LibGit2Sharp/Core/GitWorktree.cs
@@ -33,8 +33,10 @@ internal enum GitWorktreePruneOptionFlags : uint
internal class git_worktree_add_options
{
public uint version = 1;
-
+
public int locked;
+
+ public IntPtr @ref = IntPtr.Zero;
}
[StructLayout(LayoutKind.Sequential)]
From 05fb439afe928c6579dff21f97ffa2cc59f3f8c1 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 18:18:45 -0400
Subject: [PATCH 004/147] Update .NET SDK
---
global.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/global.json b/global.json
index 05d0ae3d2..5ecd5ee6e 100644
--- a/global.json
+++ b/global.json
@@ -1,5 +1,5 @@
{
"sdk": {
- "version": "3.1.201"
+ "version": "5.0.301"
}
}
From ae450c9317d5fe98fd94bf7b99a5c785c2820098 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 18:24:09 -0400
Subject: [PATCH 005/147] Update test TFMs
---
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 8 +++----
azure-pipelines/dotnet.yml | 23 ++++++--------------
2 files changed, 11 insertions(+), 20 deletions(-)
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 0525e98c8..71f28b6ac 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,13 +1,13 @@
- net472;netcoreapp2.1
+ net472;netcoreapp2.1;net5.0
-
-
+
+
@@ -23,7 +23,7 @@
-
+
diff --git a/azure-pipelines/dotnet.yml b/azure-pipelines/dotnet.yml
index 066d14412..3bc1eaf50 100644
--- a/azure-pipelines/dotnet.yml
+++ b/azure-pipelines/dotnet.yml
@@ -6,22 +6,6 @@ steps:
- script: dotnet pack --no-build -c $(BuildConfiguration) /v:m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/pack.binlog"
displayName: dotnet pack
-- task: DotNetCoreCLI@2
- displayName: dotnet test -f net46 (w/ coverage)
- inputs:
- command: test
- arguments: --no-build -c $(BuildConfiguration) -f net46 --filter "TestCategory!=FailsInCloudTest & TestCategory!=FailsWhileInstrumented" -v n /p:CollectCoverage=true
- testRunTitle: net46-$(Agent.JobName)
- condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))
-
-- task: DotNetCoreCLI@2
- displayName: dotnet test -f net46 (w/o coverage)
- inputs:
- command: test
- arguments: --no-build -c $(BuildConfiguration) -f net46 --filter "TestCategory!=FailsInCloudTest & TestCategory=FailsWhileInstrumented" -v n
- testRunTitle: net46-$(Agent.JobName)-nocoverage
- condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))
-
- task: DotNetCoreCLI@2
displayName: dotnet test -f net472 (w/ coverage)
inputs:
@@ -45,6 +29,13 @@ steps:
arguments: --no-build -c $(BuildConfiguration) -f netcoreapp2.1 --filter "TestCategory!=FailsInCloudTest" -v n /p:CollectCoverage=true
testRunTitle: netcoreapp2.1-$(Agent.JobName)
+- task: DotNetCoreCLI@2
+ displayName: dotnet test -f net5.0
+ inputs:
+ command: test
+ arguments: --no-build -c $(BuildConfiguration) -f net5.0 --filter "TestCategory!=FailsInCloudTest" -v n /p:CollectCoverage=true
+ testRunTitle: net5.0-$(Agent.JobName)
+
- task: PowerShell@2
inputs:
filePath: azure-pipelines/artifacts/_pipelines.ps1
From 168b62f3614238b29682cd986066ee13c83a72c6 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 18:29:01 -0400
Subject: [PATCH 006/147] Suppress Encoding.UTF7 warning
---
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 1 +
1 file changed, 1 insertion(+)
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 71f28b6ac..162fffac1 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -2,6 +2,7 @@
net472;netcoreapp2.1;net5.0
+ $(NoWarn);SYSLIB0001
From 5bfaca5564cf0954e90cffd677caf6a1342a35b4 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 18:33:39 -0400
Subject: [PATCH 007/147] Fix Assembly.CodeBase warning
---
LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
index 51496c2f5..5bd666a85 100644
--- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
+++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
@@ -7,7 +7,6 @@
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
-using LibGit2Sharp.Core;
using Xunit;
namespace LibGit2Sharp.Tests.TestHelpers
@@ -65,7 +64,11 @@ private static void SetUpTestEnvironment()
if (resourcesPath == null)
{
+#if NETFRAMEWORK
resourcesPath = Path.Combine(Directory.GetParent(new Uri(typeof(BaseFixture).GetTypeInfo().Assembly.CodeBase).LocalPath).FullName, "Resources");
+#else
+ resourcesPath = Path.Combine(Directory.GetParent(typeof(BaseFixture).GetTypeInfo().Assembly.Location).FullName, "Resources");
+#endif
}
ResourcesDirectory = new DirectoryInfo(resourcesPath);
From 17ad66b3875f2c36499bc4ff53bcc8bf4d6f30a9 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 18:40:18 -0400
Subject: [PATCH 008/147] Remove explicit reference to reference assemblies
package
---
Directory.Build.props | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index d98520a64..06e7f5642 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -7,8 +7,5 @@
$(MSBuildThisFileDirectory)bin\Packages\$(Configuration)\
$(DefineConstants);$(ExtraDefine)
-
-
-
-
+
From f1c9dd7a578224ccb0bf76a83afae490523453a7 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 18:40:47 -0400
Subject: [PATCH 009/147] Update Nerdbank.GitVersioning
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index fe5f98ea9..ebd48acac 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -34,7 +34,7 @@
-
+
From b62c6737a55de52e8fe5e5a8e91fb057eeed95aa Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 18:43:39 -0400
Subject: [PATCH 010/147] Update testing packages
---
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 162fffac1..c22341d0c 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -13,13 +13,13 @@
-
-
+
+
-
-
+
+
From b1b6492f869cf63fb2766615ae640a5d3f3a440d Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 18:45:02 -0400
Subject: [PATCH 011/147] Remove System.ValueTuple
---
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 1 -
1 file changed, 1 deletion(-)
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index c22341d0c..e78a672a3 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -15,7 +15,6 @@
-
From 7456cca6648b2b3e69f1e5f5c6d37f6bc1bb4886 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 19:00:55 -0400
Subject: [PATCH 012/147] Don't test UTF7 on .NET 5
---
LibGit2Sharp.Tests/BlobFixture.cs | 5 +++--
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 1 -
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/LibGit2Sharp.Tests/BlobFixture.cs b/LibGit2Sharp.Tests/BlobFixture.cs
index e6a5f3c57..7afbe255f 100644
--- a/LibGit2Sharp.Tests/BlobFixture.cs
+++ b/LibGit2Sharp.Tests/BlobFixture.cs
@@ -3,7 +3,6 @@
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -44,6 +43,7 @@ public void CanGetBlobAsFilteredText(string autocrlf, string expectedText)
}
}
+#if NETFRAMEWORK || NETCOREAPP2_1
[Theory]
[InlineData("ascii", 4, "31 32 33 34")]
[InlineData("utf-7", 4, "31 32 33 34")]
@@ -83,6 +83,7 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
Assert.Equal(expectedUtf7Chars, string.Join(" ", utf7Chars));
}
}
+#endif
[Fact]
public void CanGetBlobSize()
@@ -185,7 +186,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
var sb = new StringBuilder();
for (int j = 0; j < 2000; j++)
{
- sb.Append(((i + 1)*(j + 1)).ToString("X8"));
+ sb.Append(((i + 1) * (j + 1)).ToString("X8"));
}
File.AppendAllText(Path.Combine(repo.Info.WorkingDirectory, "small.txt"), sb.ToString());
}
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index e78a672a3..1810df2ee 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -2,7 +2,6 @@
net472;netcoreapp2.1;net5.0
- $(NoWarn);SYSLIB0001
From 37a094c678e16919608ff9c3d1b7c61202f0fccd Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 3 Jul 2021 19:29:22 -0400
Subject: [PATCH 013/147] Fix LeaksContainer
---
LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
index 5bd666a85..8d9b9ba0c 100644
--- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
+++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
@@ -20,7 +20,7 @@ public BaseFixture()
BuildFakeConfigs(this);
#if LEAKS_IDENTIFYING
- LeaksContainer.Clear();
+ Core.LeaksContainer.Clear();
#endif
}
@@ -276,11 +276,11 @@ public virtual void Dispose()
GC.Collect();
GC.WaitForPendingFinalizers();
- if (LeaksContainer.TypeNames.Any())
+ if (Core.LeaksContainer.TypeNames.Any())
{
Assert.False(true, string.Format("Some handles of the following types haven't been properly released: {0}.{1}"
+ "In order to get some help fixing those leaks, uncomment the define LEAKS_TRACKING in Libgit2Object.cs{1}"
- + "and run the tests locally.", string.Join(", ", LeaksContainer.TypeNames), Environment.NewLine));
+ + "and run the tests locally.", string.Join(", ", Core.LeaksContainer.TypeNames), Environment.NewLine));
}
#endif
}
From 844ecd852f28caf39b23ce4cd83f5cc105c6c808 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Thu, 12 Aug 2021 22:11:20 -0400
Subject: [PATCH 014/147] Update SDK version
---
global.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/global.json b/global.json
index 5ecd5ee6e..459551b1c 100644
--- a/global.json
+++ b/global.json
@@ -1,5 +1,5 @@
{
"sdk": {
- "version": "5.0.301"
+ "version": "5.0.400"
}
}
From d68bcaa72ad7b72bcd349da7a18d23c1c073003e Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Thu, 12 Aug 2021 22:11:35 -0400
Subject: [PATCH 015/147] Update to LibGit2Sharp.NativeBinaries 2.0.314
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index ebd48acac..b00432a27 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -32,7 +32,7 @@
-
+
From 85ad3892dc1687b3da9ea10d1c98609780296b8c Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sun, 22 Aug 2021 10:23:19 +0200
Subject: [PATCH 016/147] Update LibGit2 to version 1.1.1
---
LibGit2Sharp.Tests/CloneFixture.cs | 2 +-
LibGit2Sharp.Tests/FetchFixture.cs | 8 ++---
LibGit2Sharp.Tests/RepositoryFixture.cs | 2 +-
LibGit2Sharp/Core/NativeMethods.cs | 20 ++++++-------
LibGit2Sharp/Core/Proxy.cs | 39 +++++++++++++------------
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
LibGit2Sharp/ObjectDatabase.cs | 6 ++--
7 files changed, 40 insertions(+), 39 deletions(-)
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs
index bbe6a7f33..2408dad05 100644
--- a/LibGit2Sharp.Tests/CloneFixture.cs
+++ b/LibGit2Sharp.Tests/CloneFixture.cs
@@ -70,7 +70,7 @@ private void AssertLocalClone(string url, string path = null, bool isCloningAnEm
Assert.NotEqual(originalRepo.Info.Path, clonedRepo.Info.Path);
Assert.Equal(originalRepo.Head, clonedRepo.Head);
- Assert.Equal(originalRepo.Branches.Count(), clonedRepo.Branches.Count(b => b.IsRemote));
+ Assert.Equal(originalRepo.Branches.Count(), clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
Assert.Equal(isCloningAnEmptyRepository ? 0 : 1, clonedRepo.Branches.Count(b => !b.IsRemote));
Assert.Equal(originalRepo.Tags.Count(), clonedRepo.Tags.Count());
diff --git a/LibGit2Sharp.Tests/FetchFixture.cs b/LibGit2Sharp.Tests/FetchFixture.cs
index 170b64d61..01c71ebfe 100644
--- a/LibGit2Sharp.Tests/FetchFixture.cs
+++ b/LibGit2Sharp.Tests/FetchFixture.cs
@@ -215,7 +215,7 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()
using (var clonedRepo = new Repository(clonedRepoPath))
{
- Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));
+ Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
// Drop one of the branches in the remote repository
using (var sourceRepo = new Repository(source))
@@ -226,17 +226,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()
// No pruning when the configuration entry isn't defined
Assert.Null(clonedRepo.Config.Get("fetch.prune"));
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
- Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));
+ 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("fetch.prune", false);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
- Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));
+ 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("fetch.prune", true);
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
- Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote));
+ Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
}
}
diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs
index 5c551fabd..7165e6cb7 100644
--- a/LibGit2Sharp.Tests/RepositoryFixture.cs
+++ b/LibGit2Sharp.Tests/RepositoryFixture.cs
@@ -709,7 +709,7 @@ public void CanListRemoteReferencesWithCredentials()
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- [InlineData("git://github.com/libgit2/TestGitRepository.git")]
+ //[InlineData("git://github.com/libgit2/TestGitRepository.git")]
public void CanListRemoteReferences(string url)
{
IEnumerable references = Repository.ListRemoteReferences(url).ToList();
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 00b035457..f7c9dbf26 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -227,7 +227,7 @@ private sealed class NativeShutdownObject : CriticalFinalizerObject
internal static extern unsafe GitError* git_error_last();
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void git_error_set_str(
+ internal static extern int git_error_set_str(
GitErrorCategory error_class,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string errorString);
@@ -252,25 +252,25 @@ internal static extern unsafe int git_blame_file(
internal static extern unsafe void git_blame_free(git_blame* blame);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe int git_blob_create_fromdisk(
+ internal static extern unsafe int git_blob_create_from_disk(
ref GitOid id,
git_repository* repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath path);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe int git_blob_create_fromworkdir(
+ internal static extern unsafe int git_blob_create_from_workdir(
ref GitOid id,
git_repository* repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath relative_path);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe int git_blob_create_fromstream(
+ internal static extern unsafe int git_blob_create_from_stream(
out IntPtr stream,
git_repository* repositoryPtr,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string hintpath);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int git_blob_create_fromstream_commit(
+ internal static extern int git_blob_create_from_stream_commit(
ref GitOid oid,
IntPtr stream);
@@ -1616,7 +1616,7 @@ internal static extern unsafe int git_repository_open_ext(
internal static extern unsafe FilePath git_repository_path(git_repository* repository);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe void git_repository_set_config(
+ internal static extern unsafe int git_repository_set_config(
git_repository* repository,
git_config* config);
@@ -1628,7 +1628,7 @@ internal static extern unsafe int git_repository_set_ident(
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe void git_repository_set_index(
+ internal static extern unsafe int git_repository_set_index(
git_repository* repository,
git_index* index);
@@ -1710,13 +1710,13 @@ internal static extern unsafe int git_revparse_ext(
internal static extern unsafe int git_revwalk_push(git_revwalk* walker, ref GitOid id);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe void git_revwalk_reset(git_revwalk* walker);
+ internal static extern unsafe int git_revwalk_reset(git_revwalk* walker);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe void git_revwalk_sorting(git_revwalk* walk, CommitSortStrategies sort);
+ internal static extern unsafe int git_revwalk_sorting(git_revwalk* walk, CommitSortStrategies sort);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe void git_revwalk_simplify_first_parent(git_revwalk* walk);
+ internal static extern unsafe int git_revwalk_simplify_first_parent(git_revwalk* walk);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe void git_signature_free(git_signature* signature);
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 86d632576..ca9a69f6d 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -36,34 +36,34 @@ public static unsafe BlameHandle git_blame_file(
#region git_blob_
- public static unsafe IntPtr git_blob_create_fromstream(RepositoryHandle repo, string hintpath)
+ public static unsafe IntPtr git_blob_create_from_stream(RepositoryHandle repo, string hintpath)
{
IntPtr writestream_ptr;
- Ensure.ZeroResult(NativeMethods.git_blob_create_fromstream(out writestream_ptr, repo, hintpath));
+ Ensure.ZeroResult(NativeMethods.git_blob_create_from_stream(out writestream_ptr, repo, hintpath));
return writestream_ptr;
}
public static unsafe ObjectId git_blob_create_fromstream_commit(IntPtr writestream_ptr)
{
var oid = new GitOid();
- Ensure.ZeroResult(NativeMethods.git_blob_create_fromstream_commit(ref oid, writestream_ptr));
+ Ensure.ZeroResult(NativeMethods.git_blob_create_from_stream_commit(ref oid, writestream_ptr));
return oid;
}
- public static unsafe ObjectId git_blob_create_fromdisk(RepositoryHandle repo, FilePath path)
+ public static unsafe ObjectId git_blob_create_from_disk(RepositoryHandle repo, FilePath path)
{
var oid = new GitOid();
- int res = NativeMethods.git_blob_create_fromdisk(ref oid, repo, path);
+ int res = NativeMethods.git_blob_create_from_disk(ref oid, repo, path);
Ensure.ZeroResult(res);
return oid;
}
- public static unsafe ObjectId git_blob_create_fromfile(RepositoryHandle repo, FilePath path)
+ public static unsafe ObjectId git_blob_create_from_workdir(RepositoryHandle repo, FilePath path)
{
var oid = new GitOid();
- int res = NativeMethods.git_blob_create_fromworkdir(ref oid, repo, path);
+ int res = NativeMethods.git_blob_create_from_workdir(ref oid, repo, path);
Ensure.ZeroResult(res);
return oid;
@@ -855,21 +855,22 @@ public static unsafe int git_diff_num_deltas(DiffHandle diff)
#region git_error_
- public static void git_error_set_str(GitErrorCategory error_class, Exception exception)
+ public static int git_error_set_str(GitErrorCategory error_class, Exception exception)
{
if (exception is OutOfMemoryException)
{
NativeMethods.git_error_set_oom();
+ return 0;
}
else
{
- NativeMethods.git_error_set_str(error_class, ErrorMessageFromException(exception));
+ return NativeMethods.git_error_set_str(error_class, ErrorMessageFromException(exception));
}
}
- public static void git_error_set_str(GitErrorCategory error_class, String errorString)
+ public static int git_error_set_str(GitErrorCategory error_class, String errorString)
{
- NativeMethods.git_error_set_str(error_class, errorString);
+ return NativeMethods.git_error_set_str(error_class, errorString);
}
///
@@ -2589,9 +2590,9 @@ public static unsafe FilePath git_repository_path(RepositoryHandle repo)
return NativeMethods.git_repository_path(repo);
}
- public static unsafe void git_repository_set_config(RepositoryHandle repo, ConfigurationHandle config)
+ public static unsafe int git_repository_set_config(RepositoryHandle repo, ConfigurationHandle config)
{
- NativeMethods.git_repository_set_config(repo, config);
+ return NativeMethods.git_repository_set_config(repo, config);
}
public static unsafe void git_repository_set_ident(RepositoryHandle repo, string name, string email)
@@ -2600,9 +2601,9 @@ public static unsafe void git_repository_set_ident(RepositoryHandle repo, string
Ensure.ZeroResult(res);
}
- public static unsafe void git_repository_set_index(RepositoryHandle repo, IndexHandle index)
+ public static unsafe int git_repository_set_index(RepositoryHandle repo, IndexHandle index)
{
- NativeMethods.git_repository_set_index(repo, index);
+ return NativeMethods.git_repository_set_index(repo, index);
}
public static unsafe void git_repository_set_workdir(RepositoryHandle repo, FilePath workdir)
@@ -2783,14 +2784,14 @@ public static unsafe void git_revwalk_reset(RevWalkerHandle walker)
NativeMethods.git_revwalk_reset(walker);
}
- public static unsafe void git_revwalk_sorting(RevWalkerHandle walker, CommitSortStrategies options)
+ public static unsafe int git_revwalk_sorting(RevWalkerHandle walker, CommitSortStrategies options)
{
- NativeMethods.git_revwalk_sorting(walker, options);
+ return NativeMethods.git_revwalk_sorting(walker, options);
}
- public static unsafe void git_revwalk_simplify_first_parent(RevWalkerHandle walker)
+ public static unsafe int git_revwalk_simplify_first_parent(RevWalkerHandle walker)
{
- NativeMethods.git_revwalk_simplify_first_parent(walker);
+ return NativeMethods.git_revwalk_simplify_first_parent(walker);
}
#endregion
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index b00432a27..0c326b095 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -32,7 +32,7 @@
-
+
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs
index 3a4ebcdb6..52aceb321 100644
--- a/LibGit2Sharp/ObjectDatabase.cs
+++ b/LibGit2Sharp/ObjectDatabase.cs
@@ -104,8 +104,8 @@ public virtual Blob CreateBlob(string path)
}
ObjectId id = Path.IsPathRooted(path)
- ? Proxy.git_blob_create_fromdisk(repo.Handle, path)
- : Proxy.git_blob_create_fromfile(repo.Handle, path);
+ ? Proxy.git_blob_create_from_disk(repo.Handle, path)
+ : Proxy.git_blob_create_from_workdir(repo.Handle, path);
return repo.Lookup(id);
}
@@ -277,7 +277,7 @@ private unsafe Blob CreateBlob(Stream stream, string hintpath, long? numberOfByt
throw new ArgumentException("The stream cannot be read from.", "stream");
}
- IntPtr writestream_ptr = Proxy.git_blob_create_fromstream(repo.Handle, hintpath);
+ IntPtr writestream_ptr = Proxy.git_blob_create_from_stream(repo.Handle, hintpath);
GitWriteStream writestream = Marshal.PtrToStructure(writestream_ptr);
try
From 9941d39b5383691d4eb66534c37eb487bcc211ab Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sun, 22 Aug 2021 10:24:34 +0200
Subject: [PATCH 017/147] Revert commented test
---
LibGit2Sharp.Tests/RepositoryFixture.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs
index 7165e6cb7..5c551fabd 100644
--- a/LibGit2Sharp.Tests/RepositoryFixture.cs
+++ b/LibGit2Sharp.Tests/RepositoryFixture.cs
@@ -709,7 +709,7 @@ public void CanListRemoteReferencesWithCredentials()
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- //[InlineData("git://github.com/libgit2/TestGitRepository.git")]
+ [InlineData("git://github.com/libgit2/TestGitRepository.git")]
public void CanListRemoteReferences(string url)
{
IEnumerable references = Repository.ListRemoteReferences(url).ToList();
From 21d4f13ac7c739a5526cf088fbd8765d4ad12f57 Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sun, 5 Sep 2021 08:14:25 +0200
Subject: [PATCH 018/147] Update to libgit2 v1.2.0
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 0c326b095..d35369d94 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -32,7 +32,7 @@
-
+
From 297167eb2755c883bb14cf21ccffeffb5a8aa60e Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sun, 5 Sep 2021 09:01:29 +0200
Subject: [PATCH 019/147] Fix rebase options
---
LibGit2Sharp/Core/GitRebaseOptions.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/LibGit2Sharp/Core/GitRebaseOptions.cs b/LibGit2Sharp/Core/GitRebaseOptions.cs
index e1416e803..981bfe919 100644
--- a/LibGit2Sharp/Core/GitRebaseOptions.cs
+++ b/LibGit2Sharp/Core/GitRebaseOptions.cs
@@ -18,6 +18,8 @@ internal class GitRebaseOptions
public GitCheckoutOpts checkout_options = new GitCheckoutOpts { version = 1 };
+ private IntPtr padding; // TODO: add git_commit_create_cb
+
public NativeMethods.commit_signing_callback signing_callback;
}
}
From eb3dd1c72a0202bb0ddc669364b3c4e57e07412d Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sun, 5 Sep 2021 09:37:19 +0200
Subject: [PATCH 020/147] Fix git remote callbacks
---
LibGit2Sharp/Core/GitRemoteCallbacks.cs | 2 ++
1 file changed, 2 insertions(+)
diff --git a/LibGit2Sharp/Core/GitRemoteCallbacks.cs b/LibGit2Sharp/Core/GitRemoteCallbacks.cs
index 54cdb46ed..4900ad562 100644
--- a/LibGit2Sharp/Core/GitRemoteCallbacks.cs
+++ b/LibGit2Sharp/Core/GitRemoteCallbacks.cs
@@ -33,6 +33,8 @@ internal struct GitRemoteCallbacks
internal IntPtr transport;
+ private IntPtr padding; // TODO: add git_remote_ready_cb
+
internal IntPtr payload;
internal NativeMethods.url_resolve_callback resolve_url;
From 491d248472fd00f4fc5bef8da61cda14ba3b6735 Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sun, 5 Sep 2021 10:11:14 +0200
Subject: [PATCH 021/147] Fix memory corruption with odb backend
---
LibGit2Sharp/Core/GitOdbBackend.cs | 3 +++
1 file changed, 3 insertions(+)
diff --git a/LibGit2Sharp/Core/GitOdbBackend.cs b/LibGit2Sharp/Core/GitOdbBackend.cs
index 0d68a3433..3ff031048 100644
--- a/LibGit2Sharp/Core/GitOdbBackend.cs
+++ b/LibGit2Sharp/Core/GitOdbBackend.cs
@@ -33,6 +33,9 @@ static GitOdbBackend()
public exists_prefix_callback ExistsPrefix;
public IntPtr Refresh;
public foreach_callback Foreach;
+
+ private IntPtr Padding; // TODO: add writemidx
+
public IntPtr Writepack;
public IntPtr Freshen;
public free_callback Free;
From 29efc69f0ac78e2b44e64e7de3de6a845e7ec4a7 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 19 Sep 2021 14:22:48 -0400
Subject: [PATCH 022/147] Use native HTTPS support
---
LibGit2Sharp.Tests/CloneFixture.cs | 157 +++++-----
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 1 +
.../Core/ManagedHttpSmartSubtransport.cs | 270 ------------------
LibGit2Sharp/Core/NativeMethods.cs | 24 +-
LibGit2Sharp/GlobalSettings.cs | 143 +---------
5 files changed, 90 insertions(+), 505 deletions(-)
delete mode 100644 LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs
index 2408dad05..0fefabbf6 100644
--- a/LibGit2Sharp.Tests/CloneFixture.cs
+++ b/LibGit2Sharp.Tests/CloneFixture.cs
@@ -5,7 +5,6 @@
using LibGit2Sharp.Handlers;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -110,9 +109,9 @@ public void CanCloneBarely(string url)
var scd = BuildSelfCleaningDirectory();
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions
- {
- IsBare = true
- });
+ {
+ IsBare = true
+ });
using (var repo = new Repository(clonedRepoPath))
{
@@ -195,7 +194,7 @@ public void CanCloneWithCredentials()
}
}
- static Credentials CreateUsernamePasswordCredentials (string user, string pass, bool secure)
+ static Credentials CreateUsernamePasswordCredentials(string user, string pass, bool secure)
{
if (secure)
{
@@ -222,7 +221,7 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
{
- CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials (user, pass, secure)
+ CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials(user, pass, secure)
});
using (var repo = new Repository(clonedRepoPath))
@@ -237,65 +236,69 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
}
}
- //[SkippableTheory]
- //[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
- //[InlineData("git@github.com:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
- //public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
- //{
- // var scd = BuildSelfCleaningDirectory();
-
- // InconclusiveIf(
- // () =>
- // certType == typeof (CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
- // "SSH not supported");
-
- // bool wasCalled = false;
- // bool checksHappy = false;
-
- // var options = new CloneOptions {
- // CertificateCheck = (cert, valid, host) => {
- // wasCalled = true;
-
- // Assert.Equal(hostname, host);
- // Assert.Equal(certType, cert.GetType());
-
- // if (certType == typeof(CertificateX509)) {
- // Assert.True(valid);
- // var x509 = ((CertificateX509)cert).Certificate;
- // // we get a string with the different fields instead of a structure, so...
- // Assert.Contains("CN=github.com,", x509.Subject);
- // checksHappy = true;
- // return false;
- // }
-
- // if (certType == typeof(CertificateSsh)) {
- // var hostkey = (CertificateSsh)cert;
- // Assert.True(hostkey.HasMD5);
- // /*
- // * Once you've connected and thus your ssh has stored the hostkey,
- // * you can get the hostkey for a host with
- // *
- // * ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
- // *
- // * though GitHub's hostkey won't change anytime soon.
- // */
- // Assert.Equal("1627aca576282d36631b564debdfa648",
- // BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
- // checksHappy = true;
- // return false;
- // }
-
- // return false;
- // },
- // };
-
- // Assert.Throws(() =>
- // Repository.Clone(url, scd.DirectoryPath, options)
- // );
-
- // Assert.True(wasCalled);
- // Assert.True(checksHappy);
- //}
+ [SkippableTheory]
+ [InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
+ [InlineData("git@github.com:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
+ public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
+ {
+ var scd = BuildSelfCleaningDirectory();
+
+ InconclusiveIf(
+ () =>
+ certType == typeof(CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
+ "SSH not supported");
+
+ bool wasCalled = false;
+ bool checksHappy = false;
+
+ var options = new CloneOptions
+ {
+ CertificateCheck = (cert, valid, host) =>
+ {
+ wasCalled = true;
+
+ Assert.Equal(hostname, host);
+ Assert.Equal(certType, cert.GetType());
+
+ if (certType == typeof(CertificateX509))
+ {
+ Assert.True(valid);
+ var x509 = ((CertificateX509)cert).Certificate;
+ // we get a string with the different fields instead of a structure, so...
+ Assert.Contains("CN=github.com,", x509.Subject);
+ checksHappy = true;
+ return false;
+ }
+
+ if (certType == typeof(CertificateSsh))
+ {
+ var hostkey = (CertificateSsh)cert;
+ Assert.True(hostkey.HasMD5);
+ /*
+ * Once you've connected and thus your ssh has stored the hostkey,
+ * you can get the hostkey for a host with
+ *
+ * ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
+ *
+ * though GitHub's hostkey won't change anytime soon.
+ */
+ Assert.Equal("1627aca576282d36631b564debdfa648",
+ BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
+ checksHappy = true;
+ return false;
+ }
+
+ return false;
+ },
+ };
+
+ Assert.Throws(() =>
+ Repository.Clone(url, scd.DirectoryPath, options)
+ );
+
+ Assert.True(wasCalled);
+ Assert.True(checksHappy);
+ }
[Theory]
[InlineData("git://github.com/libgit2/TestGitRepository")]
@@ -441,7 +444,7 @@ public void CanRecursivelyCloneSubmodules()
string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
string workDirPath;
- using(Repository repo = new Repository(clonedRepoPath))
+ using (Repository repo = new Repository(clonedRepoPath))
{
workDirPath = repo.Info.WorkingDirectory.TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
}
@@ -452,14 +455,14 @@ public void CanRecursivelyCloneSubmodules()
Dictionary expectedCallbackInfo = new Dictionary();
expectedCallbackInfo.Add(workDirPath, new CloneCallbackInfo()
- {
- RecursionDepth = 0,
- RemoteUrl = uri.AbsolutePath,
- StartingWorkInRepositoryCalled = true,
- FinishedWorkInRepositoryCalled = true,
- CheckoutProgressCalled = true,
- RemoteRefUpdateCalled = true,
- });
+ {
+ RecursionDepth = 0,
+ RemoteUrl = uri.AbsolutePath,
+ StartingWorkInRepositoryCalled = true,
+ FinishedWorkInRepositoryCalled = true,
+ CheckoutProgressCalled = true,
+ RemoteRefUpdateCalled = true,
+ });
expectedCallbackInfo.Add(Path.Combine(workDirPath, relativeSubmodulePath), new CloneCallbackInfo()
{
@@ -486,7 +489,7 @@ public void CanRecursivelyCloneSubmodules()
}
// Verify the state of the submodule
- using(Repository repo = new Repository(clonedRepoPath))
+ using (Repository repo = new Repository(clonedRepoPath))
{
var sm = repo.Submodules[relativeSubmodulePath];
Assert.True(sm.RetrieveStatus().HasFlag(SubmoduleStatus.InWorkDir |
@@ -533,7 +536,7 @@ public void CanCancelRecursiveClone()
{
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
}
- catch(RecurseSubmodulesException ex)
+ catch (RecurseSubmodulesException ex)
{
Assert.NotNull(ex.InnerException);
Assert.Equal(typeof(UserCancelledException), ex.InnerException.GetType());
@@ -541,7 +544,7 @@ public void CanCancelRecursiveClone()
}
// Verify that the submodule was not initialized.
- using(Repository repo = new Repository(clonedRepoPath))
+ using (Repository repo = new Repository(clonedRepoPath))
{
var submoduleStatus = repo.Submodules[relativeSubmodulePath].RetrieveStatus();
Assert.Equal(SubmoduleStatus.InConfig | SubmoduleStatus.InHead | SubmoduleStatus.InIndex | SubmoduleStatus.WorkDirUninitialized,
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index 6026f267a..55260a6f5 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -15,6 +15,7 @@ public void CanGetMinimumCompiledInFeatures()
BuiltInFeatures features = GlobalSettings.Version.Features;
Assert.True(features.HasFlag(BuiltInFeatures.Threads));
+ Assert.True(features.HasFlag(BuiltInFeatures.Https));
}
[Fact]
diff --git a/LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs b/LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs
deleted file mode 100644
index 88eced880..000000000
--- a/LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs
+++ /dev/null
@@ -1,270 +0,0 @@
-using System;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Net.Http;
-using System.Security.Authentication;
-
-namespace LibGit2Sharp.Core
-{
- internal class ManagedHttpSmartSubtransport : RpcSmartSubtransport
- {
- protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)
- {
- string endpointUrl, contentType = null;
- bool isPost = false;
-
- switch (action)
- {
- case GitSmartSubtransportAction.UploadPackList:
- endpointUrl = string.Concat(url, "/info/refs?service=git-upload-pack");
- break;
-
- case GitSmartSubtransportAction.UploadPack:
- endpointUrl = string.Concat(url, "/git-upload-pack");
- contentType = "application/x-git-upload-pack-request";
- isPost = true;
- break;
-
- case GitSmartSubtransportAction.ReceivePackList:
- endpointUrl = string.Concat(url, "/info/refs?service=git-receive-pack");
- break;
-
- case GitSmartSubtransportAction.ReceivePack:
- endpointUrl = string.Concat(url, "/git-receive-pack");
- contentType = "application/x-git-receive-pack-request";
- isPost = true;
- break;
-
- default:
- throw new InvalidOperationException();
- }
-
- return new ManagedHttpSmartSubtransportStream(this, endpointUrl, isPost, contentType);
- }
-
- private class ManagedHttpSmartSubtransportStream : SmartSubtransportStream
- {
- private static int MAX_REDIRECTS = 7;
-
-#if NETCOREAPP
- private static readonly SocketsHttpHandler httpHandler;
-#else
- private static readonly HttpClientHandler httpHandler;
-#endif
-
- private static readonly CredentialCache credentialCache;
-
- private MemoryStream postBuffer = new MemoryStream();
- private HttpResponseMessage response;
- private Stream responseStream;
-
- static ManagedHttpSmartSubtransportStream()
- {
-#if NETCOREAPP
- httpHandler = new SocketsHttpHandler();
- httpHandler.PooledConnectionLifetime = TimeSpan.FromMinutes(5);
-#else
- httpHandler = new HttpClientHandler();
- httpHandler.SslProtocols |= SslProtocols.Tls12;
-#endif
-
- httpHandler.AllowAutoRedirect = false;
-
- credentialCache = new CredentialCache();
- httpHandler.Credentials = credentialCache;
- }
-
- public ManagedHttpSmartSubtransportStream(ManagedHttpSmartSubtransport parent, string endpointUrl, bool isPost, string contentType)
- : base(parent)
- {
- EndpointUrl = new Uri(endpointUrl);
- IsPost = isPost;
- ContentType = contentType;
- }
-
- private HttpClient CreateHttpClient(HttpMessageHandler handler)
- {
- return new HttpClient(handler, false)
- {
- DefaultRequestHeaders =
- {
- // This worked fine when it was on, but git.exe doesn't specify this header, so we don't either.
- ExpectContinue = false,
- },
- };
- }
-
- private Uri EndpointUrl { get; set; }
-
- private bool IsPost { get; set; }
-
- private string ContentType { get; set; }
-
- public override int Write(Stream dataStream, long length)
- {
- byte[] buffer = new byte[4096];
- long writeTotal = 0;
-
- while (length > 0)
- {
- int readLen = dataStream.Read(buffer, 0, (int)Math.Min(buffer.Length, length));
-
- if (readLen == 0)
- {
- break;
- }
-
- postBuffer.Write(buffer, 0, readLen);
- length -= readLen;
- writeTotal += readLen;
- }
-
- if (writeTotal < length)
- {
- throw new EndOfStreamException("Could not write buffer (short read)");
- }
-
- return 0;
- }
-
- private string GetUserAgent()
- {
- string userAgent = GlobalSettings.GetUserAgent();
-
- if (string.IsNullOrEmpty(userAgent))
- {
- userAgent = "LibGit2Sharp " + GlobalSettings.Version.InformationalVersion;
- }
-
- return userAgent;
- }
-
- private HttpRequestMessage CreateRequest(Uri endpointUrl, bool isPost)
- {
- var verb = isPost ? new HttpMethod("POST") : new HttpMethod("GET");
- var request = new HttpRequestMessage(verb, endpointUrl);
- request.Headers.Add("User-Agent", $"git/2.0 ({GetUserAgent()})");
- request.Headers.Remove("Expect");
-
- return request;
- }
-
- private HttpResponseMessage GetResponseWithRedirects()
- {
- var url = EndpointUrl;
- int retries;
-
- for (retries = 0; ; retries++)
- {
- using (var httpClient = CreateHttpClient(httpHandler))
- {
- var request = CreateRequest(url, IsPost);
-
- if (retries > MAX_REDIRECTS)
- {
- throw new Exception("too many redirects or authentication replays");
- }
-
- if (IsPost && postBuffer.Length > 0)
- {
- var bufferDup = new MemoryStream(postBuffer.GetBuffer(), 0, (int)postBuffer.Length);
-
- request.Content = new StreamContent(bufferDup);
- request.Content.Headers.Add("Content-Type", ContentType);
- }
-
- var response = httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead).GetAwaiter().GetResult();
-
- if (response.StatusCode == HttpStatusCode.OK)
- {
- return response;
- }
- else if (response.StatusCode == HttpStatusCode.Unauthorized)
- {
- int ret = SmartTransport.AcquireCredentials(out Credentials cred, null, typeof(UsernamePasswordCredentials));
-
- if (ret != 0)
- {
- throw new InvalidOperationException("authentication cancelled");
- }
-
- var scheme = response.Headers.WwwAuthenticate.First().Scheme;
-
- if (cred is DefaultCredentials)
- {
- lock (credentialCache)
- {
- credentialCache.Add(url, scheme, CredentialCache.DefaultNetworkCredentials);
- }
- }
- else if (cred is UsernamePasswordCredentials userpass)
- {
- lock (credentialCache)
- {
- credentialCache.Add(url, scheme, new NetworkCredential(userpass.Username, userpass.Password));
- }
- }
-
- continue;
- }
- else if (response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect)
- {
- url = new Uri(response.Headers.GetValues("Location").First());
- continue;
- }
-
- throw new Exception(string.Format("unexpected HTTP response: {0}", response.StatusCode));
- }
- }
-
- throw new Exception("too many redirects or authentication replays");
- }
-
- public override int Read(Stream dataStream, long length, out long readTotal)
- {
- byte[] buffer = new byte[4096];
- readTotal = 0;
-
- if (responseStream == null)
- {
- response = GetResponseWithRedirects();
- responseStream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult();
- }
-
- while (length > 0)
- {
- int readLen = responseStream.Read(buffer, 0, (int)Math.Min(buffer.Length, length));
-
- if (readLen == 0)
- {
- break;
- }
-
- dataStream.Write(buffer, 0, readLen);
- readTotal += readLen;
- length -= readLen;
- }
-
- return 0;
- }
-
- protected override void Free()
- {
- if (responseStream != null)
- {
- responseStream.Dispose();
- responseStream = null;
- }
-
- if (response != null)
- {
- response.Dispose();
- response = null;
- }
-
- base.Free();
- }
- }
- }
-}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index f7c9dbf26..04be0e683 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -26,9 +26,6 @@ internal static class NativeMethods
private static NativeShutdownObject shutdownObject;
#pragma warning restore 0414
- private static SmartSubtransportRegistration httpSubtransportRegistration;
- private static SmartSubtransportRegistration httpsSubtransportRegistration;
-
static NativeMethods()
{
if (Platform.IsRunningOnNetFramework() || Platform.IsRunningOnNetCore())
@@ -106,7 +103,7 @@ private static bool TryUseNativeLibrary()
new Type[] { typeof(string), typeof(Assembly), typeof(DllImportSearchPath?), typeof(IntPtr).MakeByRefType() })?.CreateDelegate(typeof(TryLoadLibraryByNameDelegate));
var tryLoadLibraryByPath = (TryLoadLibraryByPathDelegate)nativeLibraryType?.GetMethod("TryLoad",
new Type[] { typeof(string), typeof(IntPtr).MakeByRefType() })?.CreateDelegate(typeof(TryLoadLibraryByPathDelegate));
- MethodInfo setDllImportResolver = nativeLibraryType?.GetMethod("SetDllImportResolver", new Type[] { typeof(Assembly), dllImportResolverType});
+ MethodInfo setDllImportResolver = nativeLibraryType?.GetMethod("SetDllImportResolver", new Type[] { typeof(Assembly), dllImportResolverType });
if (dllImportResolverType == null ||
nativeLibraryType == null ||
@@ -196,11 +193,10 @@ private static void InitializeNativeLibrary()
shutdownObject = new NativeShutdownObject();
}
- // Configure the .NET HTTP(S) mechanism on the first initialization of the library in the current process.
+ // Configure the OpenSSL locking on the first initialization of the library in the current process.
if (initCounter == 1)
{
- httpSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport("http");
- httpsSubtransportRegistration = GlobalSettings.RegisterDefaultSmartSubtransport("https");
+ git_openssl_set_locking();
}
}
@@ -209,16 +205,6 @@ private sealed class NativeShutdownObject : CriticalFinalizerObject
{
~NativeShutdownObject()
{
- if (httpSubtransportRegistration != null)
- {
- GlobalSettings.UnregisterDefaultSmartSubtransport(httpSubtransportRegistration);
- }
-
- if (httpsSubtransportRegistration != null)
- {
- GlobalSettings.UnregisterDefaultSmartSubtransport(httpsSubtransportRegistration);
- }
-
git_libgit2_shutdown();
}
}
@@ -452,7 +438,7 @@ internal static extern unsafe int git_commit_create_from_ids(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string message,
ref GitOid tree,
UIntPtr parentCount,
- [MarshalAs(UnmanagedType.LPArray)] [In] IntPtr[] parents);
+ [MarshalAs(UnmanagedType.LPArray)][In] IntPtr[] parents);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_commit_create_buffer(
@@ -2111,7 +2097,7 @@ internal static extern unsafe int git_worktree_unlock(
git_worktree* worktree);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe int git_worktree_add (
+ internal static extern unsafe int git_worktree_add(
out git_worktree* reference,
git_repository* repo,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs
index 1e5d17a19..00b031ca0 100644
--- a/LibGit2Sharp/GlobalSettings.cs
+++ b/LibGit2Sharp/GlobalSettings.cs
@@ -22,14 +22,6 @@ public static class GlobalSettings
private static bool nativeLibraryPathLocked;
private static string nativeLibraryDefaultPath;
- internal class SmartSubtransportData
- {
- internal bool isCustom;
- internal SmartSubtransportRegistrationData defaultSubtransport;
- }
-
- private static readonly Dictionary smartSubtransportData = new Dictionary();
-
static GlobalSettings()
{
bool netFX = Platform.IsRunningOnNetFramework();
@@ -81,48 +73,6 @@ private static string GetExecutingAssemblyDirectory()
///
public static Version Version => version.Value;
- private static SmartSubtransportData GetOrCreateSmartSubtransportData(string scheme)
- {
- Ensure.ArgumentNotNull(scheme, "scheme");
-
- lock (smartSubtransportData)
- {
- if (!smartSubtransportData.ContainsKey(scheme))
- {
- smartSubtransportData[scheme] = new SmartSubtransportData();
- }
-
- return smartSubtransportData[scheme];
- }
- }
-
- internal static SmartSubtransportRegistration RegisterDefaultSmartSubtransport(string scheme)
- where T : SmartSubtransport, new()
- {
- Ensure.ArgumentNotNull(scheme, "scheme");
-
- lock (smartSubtransportData)
- {
- var data = GetOrCreateSmartSubtransportData(scheme);
-
- if (data.defaultSubtransport != null)
- {
- throw new Exception(string.Format("A default subtransport is already configured for {0}", scheme));
- }
-
- var registration = new SmartSubtransportRegistration(scheme);
-
- if (!data.isCustom)
- {
- RegisterSmartSubtransportInternal(registration);
- }
-
- data.defaultSubtransport = registration;
-
- return registration;
- }
- }
-
///
/// Registers a new as a custom
/// smart-protocol transport with libgit2. Any Git remote with
@@ -141,53 +91,21 @@ public static SmartSubtransportRegistration RegisterSmartSubtransport(stri
{
Ensure.ArgumentNotNull(scheme, "scheme");
- lock (smartSubtransportData)
- {
- var data = GetOrCreateSmartSubtransportData(scheme);
-
- if (data.isCustom)
- {
- throw new EntryExistsException(string.Format("A smart subtransport is already registered for {0}", scheme));
- }
-
- if (data.defaultSubtransport != null)
- {
- Proxy.git_transport_unregister(scheme);
- }
-
- var previousValue = data.isCustom;
- data.isCustom = true;
-
- var registration = new SmartSubtransportRegistration(scheme);
-
- try
- {
- RegisterSmartSubtransportInternal(registration);
- }
- catch
- {
- data.isCustom = previousValue;
- throw;
- }
-
- return registration;
- }
- }
+ var registration = new SmartSubtransportRegistration(scheme);
- private static void RegisterSmartSubtransportInternal(SmartSubtransportRegistration registration)
- where T : SmartSubtransport, new()
- {
try
{
Proxy.git_transport_register(registration.Scheme,
registration.FunctionPointer,
registration.RegistrationPointer);
}
- catch
+ catch (Exception)
{
registration.Free();
throw;
}
+
+ return registration;
}
///
@@ -201,59 +119,6 @@ public static void UnregisterSmartSubtransport(SmartSubtransportRegistration<
{
Ensure.ArgumentNotNull(registration, "registration");
- var scheme = registration.Scheme;
-
- lock (smartSubtransportData)
- {
- var data = GetOrCreateSmartSubtransportData(scheme);
-
- if (!data.isCustom)
- {
- throw new NotFoundException(string.Format("No smart subtransport has been registered for {0}", scheme));
- }
-
- UnregisterSmartSubtransportInternal(registration);
-
- data.isCustom = false;
-
- if (data.defaultSubtransport != null)
- {
- var defaultRegistration = data.defaultSubtransport;
-
- Proxy.git_transport_register(defaultRegistration.Scheme,
- defaultRegistration.FunctionPointer,
- defaultRegistration.RegistrationPointer);
- }
- }
- }
-
- internal static void UnregisterDefaultSmartSubtransport(SmartSubtransportRegistration registration)
- where T : SmartSubtransport, new()
- {
- Ensure.ArgumentNotNull(registration, "registration");
-
- var scheme = registration.Scheme;
-
- lock (smartSubtransportData)
- {
- if (!smartSubtransportData.ContainsKey(scheme))
- {
- throw new Exception(string.Format("No default smart subtransport has been registered for {0}", scheme));
- }
-
- if (registration != smartSubtransportData[scheme].defaultSubtransport)
- {
- throw new Exception(string.Format("The given smart subtransport is not the default for {0}", scheme));
- }
-
- smartSubtransportData.Remove(scheme);
- UnregisterSmartSubtransportInternal(registration);
- }
- }
-
- private static void UnregisterSmartSubtransportInternal(SmartSubtransportRegistration registration)
- where T : SmartSubtransport, new()
- {
Proxy.git_transport_unregister(registration.Scheme);
registration.Free();
}
From b78ae80464d2ed1e0f5b4b8edf1c78686362a832 Mon Sep 17 00:00:00 2001
From: Eoin Motherway
Date: Tue, 21 Sep 2021 08:50:00 +1000
Subject: [PATCH 023/147] Fix git_remote_connect not throwing on non-zero
result
---
LibGit2Sharp/Core/Proxy.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index ca9a69f6d..580c9872a 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -2172,6 +2172,7 @@ public static unsafe void git_remote_connect(RemoteHandle remote, GitDirection d
catch (Exception)
{
customHeaders.Dispose();
+ throw;
}
}
From 2535e4744d257666d176dded9607dba92e294229 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 14:43:44 -0400
Subject: [PATCH 024/147] Remove old CI files
---
.travis.yml | 7 --
appveyor.yml | 4 -
azure-pipelines.yml | 12 ---
azure-pipelines/Set-EnvVars.ps1 | 79 -------------------
azure-pipelines/artifacts/_all.ps1 | 50 ------------
azure-pipelines/artifacts/_pipelines.ps1 | 10 ---
azure-pipelines/artifacts/_stage_all.ps1 | 59 --------------
azure-pipelines/artifacts/build_logs.ps1 | 12 ---
azure-pipelines/artifacts/coverageResults.ps1 | 22 ------
azure-pipelines/artifacts/deployables.ps1 | 13 ---
.../artifacts/projectAssetsJson.ps1 | 9 ---
azure-pipelines/build.yml | 50 ------------
azure-pipelines/dotnet.yml | 49 ------------
azure-pipelines/install-dependencies.yml | 9 ---
azure-pipelines/publish-codecoverage.yml | 31 --------
azure-pipelines/publish-deployables.yml | 14 ----
.../variables/DotNetSdkVersion.ps1 | 2 -
17 files changed, 432 deletions(-)
delete mode 100644 .travis.yml
delete mode 100644 appveyor.yml
delete mode 100644 azure-pipelines.yml
delete mode 100644 azure-pipelines/Set-EnvVars.ps1
delete mode 100644 azure-pipelines/artifacts/_all.ps1
delete mode 100644 azure-pipelines/artifacts/_pipelines.ps1
delete mode 100644 azure-pipelines/artifacts/_stage_all.ps1
delete mode 100644 azure-pipelines/artifacts/build_logs.ps1
delete mode 100644 azure-pipelines/artifacts/coverageResults.ps1
delete mode 100644 azure-pipelines/artifacts/deployables.ps1
delete mode 100644 azure-pipelines/artifacts/projectAssetsJson.ps1
delete mode 100644 azure-pipelines/build.yml
delete mode 100644 azure-pipelines/dotnet.yml
delete mode 100644 azure-pipelines/install-dependencies.yml
delete mode 100644 azure-pipelines/publish-codecoverage.yml
delete mode 100644 azure-pipelines/publish-deployables.yml
delete mode 100644 azure-pipelines/variables/DotNetSdkVersion.ps1
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 18e8b5c24..000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-language: csharp
-mono: none
-
-# Disable Travis-CI
-branches:
- only:
- - NOTTHISONE
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index 6eeeedba4..000000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,4 +0,0 @@
-# Disable AppVeyor
-branches:
- only:
- - NOTTHISONE
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
deleted file mode 100644
index c25545a56..000000000
--- a/azure-pipelines.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-trigger:
-- master
-- maint/*
-
-variables:
- TreatWarningsAsErrors: true
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
- BuildConfiguration: Release
- NUGET_PACKAGES: $(Agent.TempDirectory)/.nuget/packages
-
-jobs:
-- template: azure-pipelines/build.yml
diff --git a/azure-pipelines/Set-EnvVars.ps1 b/azure-pipelines/Set-EnvVars.ps1
deleted file mode 100644
index 907659a7b..000000000
--- a/azure-pipelines/Set-EnvVars.ps1
+++ /dev/null
@@ -1,79 +0,0 @@
-<#
-.SYNOPSIS
- Set environment variables in the environment.
- Azure Pipeline and CMD environments are considered.
-.PARAMETER Variables
- A hashtable of variables to be set.
-.OUTPUTS
- A boolean indicating whether the environment variables can be expected to propagate to the caller's environment.
-#>
-[CmdletBinding(SupportsShouldProcess=$true)]
-Param(
- [Parameter(Mandatory=$true, Position=1)]
- $Variables,
- [string[]]$PrependPath
-)
-
-if ($Variables.Count -eq 0) {
- return $true
-}
-
-$cmdInstructions = !$env:TF_BUILD -and !$env:GITHUB_ACTIONS -and $env:PS1UnderCmd -eq '1'
-if ($cmdInstructions) {
- Write-Warning "Environment variables have been set that will be lost because you're running under cmd.exe"
- Write-Host "Environment variables that must be set manually:" -ForegroundColor Blue
-} else {
- Write-Host "Environment variables set:" -ForegroundColor Blue
- $envVars
- if ($PrependPath) {
- Write-Host "Paths prepended to PATH: $PrependPath"
- }
-}
-
-if ($env:TF_BUILD) {
- Write-Host "Azure Pipelines detected. Logging commands will be used to propagate environment variables and prepend path."
-}
-
-if ($env:GITHUB_ACTIONS) {
- Write-Host "GitHub Actions detected. Logging commands will be used to propagate environment variables and prepend path."
-}
-
-$Variables.GetEnumerator() |% {
- Set-Item -Path env:$($_.Key) -Value $_.Value
-
- # If we're running in a cloud CI, set these environment variables so they propagate.
- if ($env:TF_BUILD) {
- Write-Host "##vso[task.setvariable variable=$($_.Key);]$($_.Value)"
- }
- if ($env:GITHUB_ACTIONS) {
- Write-Host "::set-env name=$($_.Key)::$($_.Value)"
- }
-
- if ($cmdInstructions) {
- Write-Host "SET $($_.Key)=$($_.Value)"
- }
-}
-
-$pathDelimiter = ';'
-if ($IsMacOS -or $IsLinux) {
- $pathDelimiter = ':'
-}
-
-if ($PrependPath) {
- $PrependPath |% {
- $newPathValue = "$_$pathDelimiter$env:PATH"
- Set-Item -Path env:PATH -Value $newPathValue
- if ($cmdInstructions) {
- Write-Host "SET PATH=$newPathValue"
- }
-
- if ($env:TF_BUILD) {
- Write-Host "##vso[task.prependpath]$_"
- }
- if ($env:GITHUB_ACTIONS) {
- Write-Host "::add-path::$_"
- }
- }
-}
-
-return !$cmdInstructions
diff --git a/azure-pipelines/artifacts/_all.ps1 b/azure-pipelines/artifacts/_all.ps1
deleted file mode 100644
index 6f62be5c3..000000000
--- a/azure-pipelines/artifacts/_all.ps1
+++ /dev/null
@@ -1,50 +0,0 @@
-# This script returns all the artifacts that should be collected after a build.
-#
-# Each powershell artifact is expressed as an object with these properties:
-# Source - the full path to the source file
-# ArtifactName - the name of the artifact to upload to
-# ContainerFolder - the relative path within the artifact in which the file should appear
-#
-# Each artifact aggregating .ps1 script should return a hashtable:
-# Key = path to the directory from which relative paths within the artifact should be calculated
-# Value = an array of paths (absolute or relative to the BaseDirectory) to files to include in the artifact.
-# FileInfo objects are also allowed.
-
-$RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
-
-Function EnsureTrailingSlash($path) {
- if ($path.length -gt 0 -and !$path.EndsWith('\') -and !$path.EndsWith('/')) {
- $path = $path + [IO.Path]::DirectorySeparatorChar
- }
-
- $path.Replace('\', [IO.Path]::DirectorySeparatorChar)
-}
-
-Get-ChildItem "$PSScriptRoot\*.ps1" -Exclude "_*" -Recurse |% {
- $ArtifactName = $_.BaseName
-
- $fileGroups = & $_
- if (!$fileGroups -or $fileGroups.Count -eq 0) {
- Write-Warning "No files found for the `"$ArtifactName`" artifact."
- } else {
- $fileGroups.GetEnumerator() | % {
- $BaseDirectory = New-Object Uri ((EnsureTrailingSlash $_.Key), [UriKind]::Absolute)
- $_.Value | % {
- if ($_.GetType() -eq [IO.FileInfo] -or $_.GetType() -eq [IO.DirectoryInfo]) {
- $_ = $_.FullName
- }
-
- $artifact = New-Object -TypeName PSObject
- Add-Member -InputObject $artifact -MemberType NoteProperty -Name ArtifactName -Value $ArtifactName
-
- $SourceFullPath = New-Object Uri ($BaseDirectory, $_)
- Add-Member -InputObject $artifact -MemberType NoteProperty -Name Source -Value $SourceFullPath.LocalPath
-
- $RelativePath = [Uri]::UnescapeDataString($BaseDirectory.MakeRelative($SourceFullPath))
- Add-Member -InputObject $artifact -MemberType NoteProperty -Name ContainerFolder -Value (Split-Path $RelativePath)
-
- Write-Output $artifact
- }
- }
- }
-}
diff --git a/azure-pipelines/artifacts/_pipelines.ps1 b/azure-pipelines/artifacts/_pipelines.ps1
deleted file mode 100644
index 5bca7c6c1..000000000
--- a/azure-pipelines/artifacts/_pipelines.ps1
+++ /dev/null
@@ -1,10 +0,0 @@
-# This script translates all the artifacts described by _all.ps1
-# into commands that instruct Azure Pipelines to actually collect those artifacts.
-
-param (
- [string]$ArtifactNameSuffix
-)
-
-& "$PSScriptRoot/_stage_all.ps1" -ArtifactNameSuffix $ArtifactNameSuffix |% {
- Write-Host "##vso[artifact.upload containerfolder=$($_.Name);artifactname=$($_.Name);]$($_.Path)"
-}
diff --git a/azure-pipelines/artifacts/_stage_all.ps1 b/azure-pipelines/artifacts/_stage_all.ps1
deleted file mode 100644
index a05db5292..000000000
--- a/azure-pipelines/artifacts/_stage_all.ps1
+++ /dev/null
@@ -1,59 +0,0 @@
-# This script links all the artifacts described by _all.ps1
-# into a staging directory, reading for uploading to a cloud build artifact store.
-# It returns a sequence of objects with Name and Path properties.
-
-param (
- [string]$ArtifactNameSuffix
-)
-
-$RepoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot (Join-Path .. ..)))
-if ($env:BUILD_ARTIFACTSTAGINGDIRECTORY) {
- $ArtifactStagingFolder = $env:BUILD_ARTIFACTSTAGINGDIRECTORY
-} else {
- $ArtifactStagingFolder = Join-Path $RepoRoot (Join-Path obj _artifacts)
- if (Test-Path $ArtifactStagingFolder) {
- Remove-Item $ArtifactStagingFolder -Recurse -Force
- }
-}
-
-function Create-SymbolicLink {
- param (
- $Link,
- $Target
- )
-
- if ($Link -eq $Target) {
- return
- }
-
- if (Test-Path $Link) { Remove-Item $Link }
- $LinkContainer = Split-Path $Link -Parent
- if (!(Test-Path $LinkContainer)) { mkdir $LinkContainer }
- Write-Verbose "Linking $Link to $Target"
- if ($IsMacOS -or $IsLinux) {
- ln $Target $Link | Out-Null
- } else {
- cmd /c mklink $Link $Target | Out-Null
- }
-}
-
-# Stage all artifacts
-$Artifacts = & "$PSScriptRoot\_all.ps1"
-$Artifacts |% {
- $DestinationFolder = (Join-Path (Join-Path $ArtifactStagingFolder "$($_.ArtifactName)$ArtifactNameSuffix") $_.ContainerFolder).TrimEnd('\')
- $Name = "$(Split-Path $_.Source -Leaf)"
-
- #Write-Host "$($_.Source) -> $($_.ArtifactName)\$($_.ContainerFolder)" -ForegroundColor Yellow
-
- if (-not (Test-Path $DestinationFolder)) { New-Item -ItemType Directory -Path $DestinationFolder | Out-Null }
- if (Test-Path -PathType Leaf $_.Source) { # skip folders
- Create-SymbolicLink -Link (Join-Path $DestinationFolder $Name) -Target $_.Source
- }
-}
-
-$Artifacts |% { "$($_.ArtifactName)$ArtifactNameSuffix" } | Get-Unique |% {
- $artifact = New-Object -TypeName PSObject
- Add-Member -InputObject $artifact -MemberType NoteProperty -Name Name -Value $_
- Add-Member -InputObject $artifact -MemberType NoteProperty -Name Path -Value (Join-Path $ArtifactStagingFolder $_)
- Write-Output $artifact
-}
diff --git a/azure-pipelines/artifacts/build_logs.ps1 b/azure-pipelines/artifacts/build_logs.ps1
deleted file mode 100644
index b55ba48f3..000000000
--- a/azure-pipelines/artifacts/build_logs.ps1
+++ /dev/null
@@ -1,12 +0,0 @@
-if ($env:BUILD_ARTIFACTSTAGINGDIRECTORY) {
- $artifactsRoot = $env:BUILD_ARTIFACTSTAGINGDIRECTORY
-} else {
- $RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
- $artifactsRoot = "$RepoRoot\bin"
-}
-
-if (!(Test-Path $artifactsRoot/build_logs)) { return }
-
-@{
- "$artifactsRoot/build_logs" = (Get-ChildItem -Recurse "$artifactsRoot/build_logs")
-}
diff --git a/azure-pipelines/artifacts/coverageResults.ps1 b/azure-pipelines/artifacts/coverageResults.ps1
deleted file mode 100644
index 7d1e9a35f..000000000
--- a/azure-pipelines/artifacts/coverageResults.ps1
+++ /dev/null
@@ -1,22 +0,0 @@
-$RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
-
-# Prepare code coverage reports for merging on another machine
-if ($env:SYSTEM_DEFAULTWORKINGDIRECTORY) {
- Write-Host "Substituting $env:SYSTEM_DEFAULTWORKINGDIRECTORY with `"{reporoot}`""
- $reports = Get-ChildItem "$RepoRoot/bin/coverage.cobertura.xml" -Recurse
- $reports |% {
- $content = Get-Content -Path $_ |% { $_ -Replace [regex]::Escape($env:SYSTEM_DEFAULTWORKINGDIRECTORY), "{reporoot}" }
- Set-Content -Path $_ -Value $content -Encoding UTF8
- }
-} else {
- Write-Warning "coverageResults: Azure Pipelines not detected. Machine-neutral token replacement skipped."
-}
-
-if (!((Test-Path $RepoRoot\bin) -and (Test-Path $RepoRoot\obj))) { return }
-
-@{
- $RepoRoot = (
- @(Get-ChildItem "$RepoRoot\bin\coverage.cobertura.xml" -Recurse) +
- (Get-ChildItem "$RepoRoot\obj\*.cs" -Recurse)
- );
-}
diff --git a/azure-pipelines/artifacts/deployables.ps1 b/azure-pipelines/artifacts/deployables.ps1
deleted file mode 100644
index 94c48cdd9..000000000
--- a/azure-pipelines/artifacts/deployables.ps1
+++ /dev/null
@@ -1,13 +0,0 @@
-$RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
-$BuildConfiguration = $env:BUILDCONFIGURATION
-if (!$BuildConfiguration) {
- $BuildConfiguration = 'Debug'
-}
-
-$PackagesRoot = "$RepoRoot/bin/Packages/$BuildConfiguration"
-
-if (!(Test-Path $PackagesRoot)) { return }
-
-@{
- "$PackagesRoot" = (Get-ChildItem $PackagesRoot -Recurse)
-}
diff --git a/azure-pipelines/artifacts/projectAssetsJson.ps1 b/azure-pipelines/artifacts/projectAssetsJson.ps1
deleted file mode 100644
index d2e85ffbe..000000000
--- a/azure-pipelines/artifacts/projectAssetsJson.ps1
+++ /dev/null
@@ -1,9 +0,0 @@
-$ObjRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..\obj")
-
-if (!(Test-Path $ObjRoot)) { return }
-
-@{
- "$ObjRoot" = (
- (Get-ChildItem "$ObjRoot\project.assets.json" -Recurse)
- );
-}
diff --git a/azure-pipelines/build.yml b/azure-pipelines/build.yml
deleted file mode 100644
index a73ccda4c..000000000
--- a/azure-pipelines/build.yml
+++ /dev/null
@@ -1,50 +0,0 @@
-parameters:
- windowsPool: Hosted Windows 2019 with VS2019
-
-jobs:
-- job: Windows
- pool: ${{ parameters.windowsPool }}
- steps:
- - template: install-dependencies.yml
- - template: dotnet.yml
-
-- job: Linux
- pool:
- vmImage: Ubuntu 18.04
- steps:
- - template: install-dependencies.yml
- - template: dotnet.yml
-
-- job: macOS
- pool:
- vmImage: macOS-10.15
- steps:
- - template: install-dependencies.yml
- - template: dotnet.yml
-
-- job: WrapUp
- dependsOn:
- - Windows
- - Linux
- - macOS
- pool:
- vmImage: Ubuntu 18.04
- condition: succeededOrFailed()
- steps:
- - template: install-dependencies.yml
- parameters:
- initArgs: -NoRestore
- - template: publish-codecoverage.yml
- - template: publish-deployables.yml
-
-- job: leak_check
- pool:
- vmImage: Ubuntu 18.04
- steps:
- - template: install-dependencies.yml
- - task: DotNetCoreCLI@2
- displayName: dotnet test -f netcoreapp2.1
- inputs:
- command: test
- arguments: --no-restore -c $(BuildConfiguration) -f netcoreapp2.1 --filter "TestCategory!=FailsInCloudTest" -v m /p:ExtraDefine=LEAKS_IDENTIFYING
- testRunTitle: netcoreapp2.1-$(Agent.JobName)
diff --git a/azure-pipelines/dotnet.yml b/azure-pipelines/dotnet.yml
deleted file mode 100644
index 3bc1eaf50..000000000
--- a/azure-pipelines/dotnet.yml
+++ /dev/null
@@ -1,49 +0,0 @@
-steps:
-
-- script: dotnet build --no-restore -c $(BuildConfiguration) /v:m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/build.binlog"
- displayName: dotnet build
-
-- script: dotnet pack --no-build -c $(BuildConfiguration) /v:m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/pack.binlog"
- displayName: dotnet pack
-
-- task: DotNetCoreCLI@2
- displayName: dotnet test -f net472 (w/ coverage)
- inputs:
- command: test
- arguments: --no-build -c $(BuildConfiguration) -f net472 --filter "TestCategory!=FailsInCloudTest & TestCategory!=FailsWhileInstrumented" -v n /p:CollectCoverage=true
- testRunTitle: net472-$(Agent.JobName)
- condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))
-
-- task: DotNetCoreCLI@2
- displayName: dotnet test -f net472 (w/o coverage)
- inputs:
- command: test
- arguments: --no-build -c $(BuildConfiguration) -f net472 --filter "TestCategory!=FailsInCloudTest & TestCategory=FailsWhileInstrumented" -v n
- testRunTitle: net472-$(Agent.JobName)-nocoverage
- condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))
-
-- task: DotNetCoreCLI@2
- displayName: dotnet test -f netcoreapp2.1
- inputs:
- command: test
- arguments: --no-build -c $(BuildConfiguration) -f netcoreapp2.1 --filter "TestCategory!=FailsInCloudTest" -v n /p:CollectCoverage=true
- testRunTitle: netcoreapp2.1-$(Agent.JobName)
-
-- task: DotNetCoreCLI@2
- displayName: dotnet test -f net5.0
- inputs:
- command: test
- arguments: --no-build -c $(BuildConfiguration) -f net5.0 --filter "TestCategory!=FailsInCloudTest" -v n /p:CollectCoverage=true
- testRunTitle: net5.0-$(Agent.JobName)
-
-- task: PowerShell@2
- inputs:
- filePath: azure-pipelines/artifacts/_pipelines.ps1
- arguments: -ArtifactNameSuffix "-$(Agent.JobName)"
- displayName: Publish artifacts
- condition: succeededOrFailed()
-
-- bash: bash <(curl -s https://codecov.io/bash)
- displayName: Publish code coverage results to codecov.io
- timeoutInMinutes: 3
- continueOnError: true
diff --git a/azure-pipelines/install-dependencies.yml b/azure-pipelines/install-dependencies.yml
deleted file mode 100644
index 5b008c6e8..000000000
--- a/azure-pipelines/install-dependencies.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-parameters:
- initArgs:
-
-steps:
-
-- powershell: |
- .\init.ps1 -AccessToken '$(System.AccessToken)' ${{ parameters['initArgs'] }} -UpgradePrerequisites
- dotnet --info
- displayName: Install prerequisites
diff --git a/azure-pipelines/publish-codecoverage.yml b/azure-pipelines/publish-codecoverage.yml
deleted file mode 100644
index 59dba9d40..000000000
--- a/azure-pipelines/publish-codecoverage.yml
+++ /dev/null
@@ -1,31 +0,0 @@
-steps:
-- download: current
- artifact: coverageResults-Windows
- displayName: Download Windows code coverage results
- continueOnError: true
-- download: current
- artifact: coverageResults-Linux
- displayName: Download Linux code coverage results
- continueOnError: true
-- download: current
- artifact: coverageResults-macOS
- displayName: Download macOS code coverage results
- continueOnError: true
-- powershell: |
- dotnet tool install --tool-path obj dotnet-reportgenerator-globaltool --version 4.2.2
- Copy-Item -Recurse $(Pipeline.Workspace)/coverageResults-Windows/obj/* $(System.DefaultWorkingDirectory)/obj
- Write-Host "Substituting {reporoot} with $(System.DefaultWorkingDirectory)"
- $reports = Get-ChildItem -Recurse "$(Pipeline.Workspace)/coverage.cobertura.xml"
- $reports |% {
- $content = Get-Content -Path $_ |% { $_.Replace("{reporoot}", "$(System.DefaultWorkingDirectory)") }
- Set-Content -Path $_ -Value $content -Encoding UTF8
- }
- $Inputs = [string]::join(';', ($reports |% { Resolve-Path -relative $_ }))
- obj/reportgenerator -reports:"$Inputs" -targetdir:coveragereport -reporttypes:Cobertura
- displayName: Merge coverage
-- task: PublishCodeCoverageResults@1
- displayName: Publish code coverage results to Azure DevOps
- inputs:
- codeCoverageTool: cobertura
- summaryFileLocation: 'coveragereport/Cobertura.xml'
- failIfCoverageEmpty: true
diff --git a/azure-pipelines/publish-deployables.yml b/azure-pipelines/publish-deployables.yml
deleted file mode 100644
index a89f389fd..000000000
--- a/azure-pipelines/publish-deployables.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-steps:
-- download: current
- displayName: Download deployables
- artifact: deployables-Windows
-
-- task: NuGetCommand@2
- displayName: Push packages to CI feed
- inputs:
- command: push
- packagesToPush: $(Pipeline.Workspace)/deployables-Windows/*.nupkg
- nuGetFeedType: internal
- publishVstsFeed: $(ci_feed)
- allowPackageConflicts: true
- condition: and(succeeded(), ne(variables['ci_feed'], ''), ne(variables['Build.Reason'], 'PullRequest'))
diff --git a/azure-pipelines/variables/DotNetSdkVersion.ps1 b/azure-pipelines/variables/DotNetSdkVersion.ps1
deleted file mode 100644
index b213fbc27..000000000
--- a/azure-pipelines/variables/DotNetSdkVersion.ps1
+++ /dev/null
@@ -1,2 +0,0 @@
-$globalJson = Get-Content -Path "$PSScriptRoot\..\..\global.json" | ConvertFrom-Json
-$globalJson.sdk.version
From e04f4a084cbc3bd2497a7cc8494ab6f5dfeaa0dd Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 14:45:38 -0400
Subject: [PATCH 025/147] Remove init scripts and locked SDK
---
global.json | 5 --
init.cmd | 4 -
init.ps1 | 66 ---------------
tools/Install-DotNetSdk.ps1 | 160 ------------------------------------
4 files changed, 235 deletions(-)
delete mode 100644 global.json
delete mode 100644 init.cmd
delete mode 100644 init.ps1
delete mode 100644 tools/Install-DotNetSdk.ps1
diff --git a/global.json b/global.json
deleted file mode 100644
index 459551b1c..000000000
--- a/global.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "sdk": {
- "version": "5.0.400"
- }
-}
diff --git a/init.cmd b/init.cmd
deleted file mode 100644
index 970285c2f..000000000
--- a/init.cmd
+++ /dev/null
@@ -1,4 +0,0 @@
-@echo off
-SETLOCAL
-set PS1UnderCmd=1
-powershell.exe -NoProfile -NoLogo -ExecutionPolicy bypass -Command "try { & '%~dpn0.ps1' %*; exit $LASTEXITCODE } catch { write-host $_; exit 1 }"
diff --git a/init.ps1 b/init.ps1
deleted file mode 100644
index 907d85a5c..000000000
--- a/init.ps1
+++ /dev/null
@@ -1,66 +0,0 @@
-<#
-.SYNOPSIS
-Installs dependencies required to build and test the projects in this repository.
-.DESCRIPTION
-This MAY not require elevation, as the SDK and runtimes are installed to a per-user location,
-unless the `-InstallLocality` switch is specified directing to a per-repo or per-machine location.
-See detailed help on that switch for more information.
-.PARAMETER InstallLocality
-A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
-Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
-Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
-Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
-When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used.
-Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`.
-Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it.
-.PARAMETER NoPrerequisites
-Skips the installation of prerequisite software (e.g. SDKs, tools).
-.PARAMETER UpgradePrerequisites
-Takes time to install prerequisites even if they are already present in case they need to be upgraded.
-No effect if -NoPrerequisites is specified.
-.PARAMETER NoRestore
-Skips the package restore step.
-.PARAMETER AccessToken
-An optional access token for authenticating to Azure Artifacts authenticated feeds.
-#>
-[CmdletBinding(SupportsShouldProcess=$true)]
-Param (
- [ValidateSet('repo','user','machine')]
- [string]$InstallLocality='user',
- [Parameter()]
- [switch]$NoPrerequisites,
- [Parameter()]
- [switch]$UpgradePrerequisites,
- [Parameter()]
- [switch]$NoRestore,
- [Parameter()]
- [string]$AccessToken
-)
-
-if (!$NoPrerequisites) {
- & "$PSScriptRoot\tools\Install-DotNetSdk.ps1" -InstallLocality $InstallLocality
-}
-
-# Workaround nuget credential provider bug that causes very unreliable package restores on Azure Pipelines
-$env:NUGET_PLUGIN_HANDSHAKE_TIMEOUT_IN_SECONDS=20
-$env:NUGET_PLUGIN_REQUEST_TIMEOUT_IN_SECONDS=20
-
-Push-Location $PSScriptRoot
-try {
- $HeaderColor = 'Green'
-
- if (!$NoRestore -and $PSCmdlet.ShouldProcess("NuGet packages", "Restore")) {
- Write-Host "Restoring NuGet packages" -ForegroundColor $HeaderColor
- dotnet restore
- if ($lastexitcode -ne 0) {
- throw "Failure while restoring packages."
- }
- }
-}
-catch {
- Write-Error $error[0]
- exit $lastexitcode
-}
-finally {
- Pop-Location
-}
diff --git a/tools/Install-DotNetSdk.ps1 b/tools/Install-DotNetSdk.ps1
deleted file mode 100644
index 10ed02b8b..000000000
--- a/tools/Install-DotNetSdk.ps1
+++ /dev/null
@@ -1,160 +0,0 @@
-<#
-.SYNOPSIS
-Installs the .NET SDK specified in the global.json file at the root of this repository,
-along with supporting .NET Core runtimes used for testing.
-.DESCRIPTION
-This MAY not require elevation, as the SDK and runtimes are installed locally to this repo location,
-unless `-InstallLocality machine` is specified.
-.PARAMETER InstallLocality
-A value indicating whether dependencies should be installed locally to the repo or at a per-user location.
-Per-user allows sharing the installed dependencies across repositories and allows use of a shared expanded package cache.
-Visual Studio will only notice and use these SDKs/runtimes if VS is launched from the environment that runs this script.
-Per-repo allows for high isolation, allowing for a more precise recreation of the environment within an Azure Pipelines build.
-When using 'repo', environment variables are set to cause the locally installed dotnet SDK to be used.
-Per-repo can lead to file locking issues when dotnet.exe is left running as a build server and can be mitigated by running `dotnet build-server shutdown`.
-Per-machine requires elevation and will download and install all SDKs and runtimes to machine-wide locations so all applications can find it.
-#>
-[CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium')]
-Param (
- [ValidateSet('repo','user','machine')]
- [string]$InstallLocality='user'
-)
-
-$DotNetInstallScriptRoot = "$PSScriptRoot/../obj/tools"
-if (!(Test-Path $DotNetInstallScriptRoot)) { New-Item -ItemType Directory -Path $DotNetInstallScriptRoot | Out-Null }
-$DotNetInstallScriptRoot = Resolve-Path $DotNetInstallScriptRoot
-
-# Look up actual required .NET Core SDK version from global.json
-$sdkVersion = & "$PSScriptRoot/../azure-pipelines/variables/DotNetSdkVersion.ps1"
-
-# Search for all .NET Core runtime versions referenced from MSBuild projects and arrange to install them.
-$runtimeVersions = @()
-Get-ChildItem "$PSScriptRoot\..\*.*proj" -Recurse |% {
- $projXml = [xml](Get-Content -Path $_)
- $targetFrameworks = $projXml.Project.PropertyGroup.TargetFramework
- if (!$targetFrameworks) {
- $targetFrameworks = $projXml.Project.PropertyGroup.TargetFrameworks
- if ($targetFrameworks) {
- $targetFrameworks = $targetFrameworks -Split ';'
- }
- }
- $targetFrameworks |? { $_ -match 'netcoreapp(\d+\.\d+)' } |% {
- $runtimeVersions += $Matches[1]
- }
-}
-
-Function Get-FileFromWeb([Uri]$Uri, $OutDir) {
- $OutFile = Join-Path $OutDir $Uri.Segments[-1]
- if (!(Test-Path $OutFile)) {
- Write-Verbose "Downloading $Uri..."
- try {
- (New-Object System.Net.WebClient).DownloadFile($Uri, $OutFile)
- } finally {
- # This try/finally causes the script to abort
- }
- }
-
- $OutFile
-}
-
-Function Get-InstallerExe($Version, [switch]$Runtime) {
- $sdkOrRuntime = 'Sdk'
- if ($Runtime) { $sdkOrRuntime = 'Runtime' }
-
- # Get the latest/actual version for the specified one
- if (([Version]$Version).Build -eq -1) {
- $versionInfo = -Split (Invoke-WebRequest -Uri "https://dotnetcli.blob.core.windows.net/dotnet/$sdkOrRuntime/$Version/latest.version" -UseBasicParsing)
- $Version = $versionInfo[-1]
- }
-
- Get-FileFromWeb -Uri "https://dotnetcli.blob.core.windows.net/dotnet/$sdkOrRuntime/$Version/dotnet-$($sdkOrRuntime.ToLowerInvariant())-$Version-win-x64.exe" -OutDir "$DotNetInstallScriptRoot"
-}
-
-Function Install-DotNet($Version, [switch]$Runtime) {
- if ($Runtime) { $sdkSubstring = '' } else { $sdkSubstring = 'SDK ' }
- Write-Host "Downloading .NET Core $sdkSubstring$Version..."
- $Installer = Get-InstallerExe -Version $Version -Runtime:$Runtime
- Write-Host "Installing .NET Core $sdkSubstring$Version..."
- cmd /c start /wait $Installer /install /quiet
- if ($LASTEXITCODE -ne 0) {
- throw "Failure to install .NET Core SDK"
- }
-}
-
-if ($InstallLocality -eq 'machine') {
- if ($IsMacOS -or $IsLinux) {
- Write-Error "Installing the .NET Core SDK or runtime at a machine-wide location is only supported by this script on Windows."
- exit 1
- }
-
- if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
- Install-DotNet -Version $sdkVersion
- }
-
- $runtimeVersions |% {
- if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
- Install-DotNet -Version $_ -Runtime
- }
- }
-
- return
-}
-
-$switches = @(
- '-Architecture','x64'
-)
-$envVars = @{
- # For locally installed dotnet, skip first time experience which takes a long time
- 'DOTNET_SKIP_FIRST_TIME_EXPERIENCE' = 'true';
-}
-
-if ($InstallLocality -eq 'repo') {
- $DotNetInstallDir = "$DotNetInstallScriptRoot/.dotnet"
-} elseif ($env:AGENT_TOOLSDIRECTORY) {
- $DotNetInstallDir = "$env:AGENT_TOOLSDIRECTORY/dotnet"
-} else {
- $DotNetInstallDir = Join-Path $HOME .dotnet
-}
-
-Write-Host "Installing .NET Core SDK and runtimes to $DotNetInstallDir" -ForegroundColor Blue
-
-if ($DotNetInstallDir) {
- $switches += '-InstallDir',$DotNetInstallDir
- $envVars['DOTNET_MULTILEVEL_LOOKUP'] = '0'
- $envVars['DOTNET_ROOT'] = $DotNetInstallDir
-}
-
-if ($IsMacOS -or $IsLinux) {
- $DownloadUri = "https://dot.net/v1/dotnet-install.sh"
- $DotNetInstallScriptPath = "$DotNetInstallScriptRoot/dotnet-install.sh"
-} else {
- $DownloadUri = "https://dot.net/v1/dotnet-install.ps1"
- $DotNetInstallScriptPath = "$DotNetInstallScriptRoot/dotnet-install.ps1"
-}
-
-if (-not (Test-Path $DotNetInstallScriptPath)) {
- Invoke-WebRequest -Uri $DownloadUri -OutFile $DotNetInstallScriptPath -UseBasicParsing
- if ($IsMacOS -or $IsLinux) {
- chmod +x $DotNetInstallScriptPath
- }
-}
-
-if ($PSCmdlet.ShouldProcess(".NET Core SDK $sdkVersion", "Install")) {
- Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches"
-} else {
- Invoke-Expression -Command "$DotNetInstallScriptPath -Version $sdkVersion $switches -DryRun"
-}
-
-$switches += '-Runtime','dotnet'
-
-$runtimeVersions | Get-Unique |% {
- if ($PSCmdlet.ShouldProcess(".NET Core runtime $_", "Install")) {
- Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches"
- } else {
- Invoke-Expression -Command "$DotNetInstallScriptPath -Channel $_ $switches -DryRun"
- }
-}
-
-if ($PSCmdlet.ShouldProcess("Set DOTNET environment variables to discover these installed runtimes?")) {
- & "$PSScriptRoot/../azure-pipelines/Set-EnvVars.ps1" -Variables $envVars -PrependPath $DotNetInstallDir | Out-Null
-}
From c91027e7fdae704e10bcd6327a64c516b6d0b93e Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 14:51:15 -0400
Subject: [PATCH 026/147] Remove R# and NCrunch files
---
.../LibGit2Sharp.Tests.v2.ncrunchproject | 31 -------------------
LibGit2Sharp.sln.DotSettings | 17 ----------
LibGit2Sharp.v2.ncrunchsolution | 13 --------
LibGit2Sharp/LibGit2Sharp.v2.ncrunchproject | 25 ---------------
4 files changed, 86 deletions(-)
delete mode 100644 LibGit2Sharp.Tests/LibGit2Sharp.Tests.v2.ncrunchproject
delete mode 100644 LibGit2Sharp.sln.DotSettings
delete mode 100644 LibGit2Sharp.v2.ncrunchsolution
delete mode 100644 LibGit2Sharp/LibGit2Sharp.v2.ncrunchproject
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.v2.ncrunchproject b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.v2.ncrunchproject
deleted file mode 100644
index e24470157..000000000
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.v2.ncrunchproject
+++ /dev/null
@@ -1,31 +0,0 @@
-
- 1000
- false
- true
- false
- true
- false
- false
- false
- false
- false
- true
- true
- false
- true
- true
- true
- 60000
-
-
-
- AutoDetect
- STA
- x86
-
-
- LibGit2Sharp.Tests.ShadowCopyFixture.CanProbeForNativeBinariesFromAShadowCopiedAssembly
-
-
- Resources\**;Resources\**.*
-
\ No newline at end of file
diff --git a/LibGit2Sharp.sln.DotSettings b/LibGit2Sharp.sln.DotSettings
deleted file mode 100644
index 8bc2282a8..000000000
--- a/LibGit2Sharp.sln.DotSettings
+++ /dev/null
@@ -1,17 +0,0 @@
-
- <?xml version="1.0" encoding="utf-16"?><Profile name="LibGit2Sharp"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode></Profile>
- TOGETHER
- ALWAYS_ADD
- ALWAYS_ADD
- ALWAYS_ADD
- ALWAYS_ADD
- ALWAYS_ADD
- True
- False
- True
- True
- <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
- True
- True
- True
-
diff --git a/LibGit2Sharp.v2.ncrunchsolution b/LibGit2Sharp.v2.ncrunchsolution
deleted file mode 100644
index 9420cc077..000000000
--- a/LibGit2Sharp.v2.ncrunchsolution
+++ /dev/null
@@ -1,13 +0,0 @@
-
- 1
- false
- true
- true
- UseDynamicAnalysis
- UseStaticAnalysis
- UseStaticAnalysis
- UseStaticAnalysis
- UseStaticAnalysis
-
-
-
\ No newline at end of file
diff --git a/LibGit2Sharp/LibGit2Sharp.v2.ncrunchproject b/LibGit2Sharp/LibGit2Sharp.v2.ncrunchproject
deleted file mode 100644
index cc3cf2122..000000000
--- a/LibGit2Sharp/LibGit2Sharp.v2.ncrunchproject
+++ /dev/null
@@ -1,25 +0,0 @@
-
- 1000
- false
- false
- false
- true
- false
- false
- false
- false
- false
- true
- true
- false
- true
- true
- true
- 60000
-
-
-
- AutoDetect
- STA
- x86
-
\ No newline at end of file
From e688d42699495c22b361c0d7c34d9110f5e65605 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 14:59:41 -0400
Subject: [PATCH 027/147] Remove Coverlet
---
Directory.Build.targets | 8 --------
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 1 -
2 files changed, 9 deletions(-)
delete mode 100644 Directory.Build.targets
diff --git a/Directory.Build.targets b/Directory.Build.targets
deleted file mode 100644
index 1ddcba6f4..000000000
--- a/Directory.Build.targets
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
- cobertura
- [xunit.*]*
-
- $(OutputPath)/
-
-
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 1810df2ee..7ef0c4f2a 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -11,7 +11,6 @@
-
From 8c7d9e54a24cd75bbc68067d0aec006593cc990b Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 15:37:17 -0400
Subject: [PATCH 028/147] Add GitHub Actions workflow
---
.github/workflows/ci.yml | 50 ++++++++++++++++++++
Directory.Build.props | 4 +-
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 5 +-
LibGit2Sharp/LibGit2Sharp.csproj | 1 +
4 files changed, 56 insertions(+), 4 deletions(-)
create mode 100644 .github/workflows/ci.yml
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 000000000..d6010aea9
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,50 @@
+name: CI
+on:
+ push:
+ branches: [master, release-*]
+ tags:
+ - '[0-9]+.[0-9]+.[0-9]+'
+ - '[0-9]+.[0-9]+.[0-9]+-*'
+ pull_request:
+ workflow_dispatch:
+env:
+ DOTNET_NOLOGO: true
+jobs:
+ build:
+ name: ${{ matrix.name }}
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ include:
+ - os: windows-2019
+ name: Windows
+ - os: ubuntu-20.04
+ name: Linux
+ - os: macos-10.15
+ name: macOS
+ fail-fast: false
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2.3.4
+ with:
+ fetch-depth: 0
+ - name: Setup .NET SDK
+ uses: actions/setup-dotnet@v1.8.1
+ with:
+ dotnet-version: 5.0.x
+ - name: Setup .NET Core 3.1 runtime
+ uses: actions/setup-dotnet@v1.8.1
+ with:
+ dotnet-version: 3.1.x
+ - name: Build
+ run: dotnet build LibGit2Sharp.sln --configuration Release
+ - name: Upload packages
+ if: matrix.name == 'Windows'
+ uses: actions/upload-artifact@v2.2.4
+ with:
+ name: NuGet packages
+ path: bin/Packages/
+ retention-days: 7
+ - name: Run tests
+ run: dotnet test LibGit2Sharp.sln --configuration Release --no-build --logger "GitHubActions"
+
diff --git a/Directory.Build.props b/Directory.Build.props
index 06e7f5642..30d3f82cb 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -4,8 +4,8 @@
true
$(MSBuildThisFileDirectory)bin\$(MSBuildProjectName)\$(Configuration)\
$(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\
- $(MSBuildThisFileDirectory)bin\Packages\$(Configuration)\
+ $(MSBuildThisFileDirectory)bin\Packages\
$(DefineConstants);$(ExtraDefine)
-
+
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 7ef0c4f2a..24e558461 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,7 +1,7 @@
- net472;netcoreapp2.1;net5.0
+ net472;netcoreapp3.1;net5.0
@@ -11,7 +11,8 @@
-
+
+
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index d35369d94..470ef0dff 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -18,6 +18,7 @@
..\libgit2sharp.snk
square-logo.png
App_Readme/LICENSE.md
+ true
From b4165b1b34e07ffa815a695c3661dc10c52b7bcb Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 15:52:32 -0400
Subject: [PATCH 029/147] Split tests by TFM
---
.github/workflows/ci.yml | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d6010aea9..d64b87e2c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -45,6 +45,11 @@ jobs:
name: NuGet packages
path: bin/Packages/
retention-days: 7
- - name: Run tests
- run: dotnet test LibGit2Sharp.sln --configuration Release --no-build --logger "GitHubActions"
+ - name: Run net472 tests
+ if: matrix.name == 'Windows'
+ run: dotnet test LibGit2Sharp.sln --configuration Release --no-build --framework net472 --logger "GitHubActions"
+ - name: Run netcoreapp3.1 tests
+ run: dotnet test LibGit2Sharp.sln --configuration Release --no-build --framework netcoreapp3.1 --logger "GitHubActions"
+ - name: Run net5.0 tests
+ run: dotnet test LibGit2Sharp.sln --configuration Release --no-build --framework net5.0 --logger "GitHubActions"
From d7085fc5c424627db5d4eeb1ff27b61d8cdcd1a8 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 16:47:50 -0400
Subject: [PATCH 030/147] Run tests with LEAKS_IDENTIFYING
---
.github/workflows/ci.yml | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d64b87e2c..d61e3350c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -47,9 +47,8 @@ jobs:
retention-days: 7
- name: Run net472 tests
if: matrix.name == 'Windows'
- run: dotnet test LibGit2Sharp.sln --configuration Release --no-build --framework net472 --logger "GitHubActions"
+ run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net472 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
- name: Run netcoreapp3.1 tests
- run: dotnet test LibGit2Sharp.sln --configuration Release --no-build --framework netcoreapp3.1 --logger "GitHubActions"
+ run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework netcoreapp3.1 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
- name: Run net5.0 tests
- run: dotnet test LibGit2Sharp.sln --configuration Release --no-build --framework net5.0 --logger "GitHubActions"
-
+ run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net5.0 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
From 1f917f59b5d08fbc6fbbe8b9a7402a92451f26f1 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 17:17:35 -0400
Subject: [PATCH 031/147] Set ContinuousIntegrationBuild to true for CI
---
Directory.Build.props | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Directory.Build.props b/Directory.Build.props
index 30d3f82cb..72eda8864 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -8,4 +8,8 @@
$(DefineConstants);$(ExtraDefine)
+
+ true
+
+
From 04114067606d7b9c229215a599a32814bd535b62 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 17:21:21 -0400
Subject: [PATCH 032/147] Switch to embedded PDBs
---
LibGit2Sharp/LibGit2Sharp.csproj | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 470ef0dff..0885f546f 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -11,9 +11,7 @@
LibGit2Sharp contributors
true
true
- $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
- true
- snupkg
+ embedded
true
..\libgit2sharp.snk
square-logo.png
From d9777fced3c10bff85b571c0dcecf6e4bfc7fcaa Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 17:36:18 -0400
Subject: [PATCH 033/147] Tweak package description
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 0885f546f..6907eb5ad 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -3,7 +3,7 @@
netstandard2.0;netcoreapp2.1
true
- LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .Net and Mono.
+ LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET
LibGit2Sharp contributors
Copyright © LibGit2Sharp contributors
libgit2 git
From a557593acdec5805ecaeb25aea690b70eee27305 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 18:41:55 -0400
Subject: [PATCH 034/147] Update README
---
README.md | 71 +++++++++++++++----------------------------------------
1 file changed, 19 insertions(+), 52 deletions(-)
diff --git a/README.md b/README.md
index c67e6ec8e..702d35832 100644
--- a/README.md
+++ b/README.md
@@ -1,78 +1,45 @@
# LibGit2Sharp
-[![master azurepipelines][master-azurepipelines-badge]][master-azurepipelines]
-[![master win][master-win-badge]][master-win]
-[![master nix][master-nix-badge]][master-nix]
-[![coverity][coverity-badge]][coverity-project]
+
-[master-azurepipelines-badge]: https://dev.azure.com/libgit2sharp/libgit2sharp/_apis/build/status/libgit2sharp?branchName=master
-[master-azurepipelines]: https://dev.azure.com/libgit2sharp/libgit2sharp/_build/latest?definitionId=1
-[master-win-badge]: https://ci.appveyor.com/api/projects/status/8qxcoqdo9kp7x2w9/branch/master?svg=true
-[master-win]: https://ci.appveyor.com/project/libgit2/libgit2sharp/branch/master
-[master-nix-badge]: https://travis-ci.org/libgit2/libgit2sharp.svg?branch=master
-[master-nix]: https://travis-ci.org/libgit2/libgit2sharp/branches
-
-[coverity-project]: https://scan.coverity.com/projects/2088
-[coverity-badge]: https://scan.coverity.com/projects/2088/badge.svg
-
-**LibGit2Sharp brings all the might and speed of [libgit2][libgit2], a native Git implementation, to the managed world of .NET and Mono.**
-
- [libgit2]: http://libgit2.github.com/
-
-## Prerequisites
-
- - **Windows:** .NET 4.6.1+
- - **Linux/Mac OS X:** Mono 5.4+
+**LibGit2Sharp brings all the might and speed of [libgit2](http://libgit2.github.com/), a native Git implementation, to the managed world of .NET**
## Online resources
- - [NuGet package][nuget] (Requires NuGet 2.7+)
- - [Source code][source]
-
- [nuget]: http://nuget.org/List/Packages/LibGit2Sharp
- [source]: https://github.com/libgit2/libgit2sharp/
+- [NuGet package](http://nuget.org/List/Packages/LibGit2Sharp)
+- [Source code](https://github.com/libgit2/libgit2sharp/)
## Troubleshooting and support
- - Usage or programming related question? Post it on [StackOverflow][so] using the tag *libgit2sharp*
- - Found a bug or missing a feature? Feed the [issue tracker][tracker]
- - Announcements and related miscellanea through Twitter ([@libgit2sharp][twitter])
-
- [so]: http://stackoverflow.com/questions/tagged/libgit2sharp
- [tracker]: https://github.com/libgit2/libgit2sharp/issues
- [twitter]: http://twitter.com/libgit2sharp
+- Usage or programming related question? Post it on [StackOverflow](http://stackoverflow.com/questions/tagged/libgit2sharp) using the tag *libgit2sharp*
+- Found a bug or missing a feature? Feed the [issue tracker](https://github.com/libgit2/libgit2sharp/issues)
+- Announcements and related miscellanea through Twitter ([@libgit2sharp](http://twitter.com/libgit2sharp))
## Quick contributing guide
- - Fork and clone locally
- - Create a topic specific branch. Add some nice feature. Do not forget the tests ;-)
- - Send a Pull Request to spread the fun!
-
-More thorough information available in the [wiki][wiki].
+- Fork and clone locally
+- Create a topic specific branch. Add some nice feature. Do not forget the tests ;-)
+- Send a Pull Request to spread the fun!
- [wiki]: https://github.com/libgit2/libgit2sharp/wiki
+More thorough information is available in the [wiki](https://github.com/libgit2/libgit2sharp/wiki).
## Optimizing unit testing
-LibGit2Sharp strives to have comprehensive and robust unit test suite to ensure the quality of the software and to assist new contributors and users who can use the tests as sample to jump start development. There are over one thousand unit-tests for LibGit2Sharp, this number will only grow as functionality is added.
-You can do a few things to optimize running unit-tests on Windows:
+LibGit2Sharp strives to have a comprehensive and robust unit test suite to ensure the quality of the software and to assist new contributors and users, who can use the tests as examples to jump start development. There are over one thousand unit tests for LibGit2Sharp, and this number will only grow as functionality is added.
+
+You can do a few things to optimize running unit tests on Windows:
1. Set the `LibGit2TestPath` environment variable to a path in your development environment.
- * If the unit-test framework cannot find the specified folder at runtime, it will fall back to the default location.
+ * If the unit test framework cannot find the specified folder at runtime, it will fall back to the default location.
2. Configure your anti-virus software to ignore the `LibGit2TestPath` path.
3. Install a RAM disk like [IMDisk](http://www.ltr-data.se/opencode.html/#ImDisk) and set `LibGit2TestPath` to use it.
- * Use `imdisk.exe -a -s 512M -m X: -p "/fs:fat /q /v:ramdisk /y"` to create a RAM disk. This command requires elevated privileges and can be placed into a scheduled task or run manually before you begin unit-testing.
+ * Use `imdisk.exe -a -s 512M -m X: -p "/fs:fat /q /v:ramdisk /y"` to create a RAM disk. This command requires elevated privileges and can be placed into a scheduled task or run manually before you begin unit-testing.
## Authors
- - **Code:** The LibGit2Sharp [contributors][committers]
- - **Logo:** [Jason "blackant" Long][blackant]
-
- [committers]: https://github.com/libgit2/libgit2sharp/contributors
- [blackant]: https://github.com/jasonlong
+- **Code:** The LibGit2Sharp [contributors](https://github.com/libgit2/libgit2sharp/contributors)
+- **Logo:** [Jason "blackant" Long](https://github.com/jasonlong)
## License
-The MIT license (Refer to the [LICENSE.md][license] file)
-
- [license]: https://github.com/libgit2/libgit2sharp/blob/master/LICENSE.md
+The MIT license (Refer to the [LICENSE.md](https://github.com/libgit2/libgit2sharp/blob/master/LICENSE.md) file)
From fe27c0f33ccfacabd2237ef4b5ac612c10a9f55b Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 18:57:56 -0400
Subject: [PATCH 035/147] Update TFM define
---
LibGit2Sharp.Tests/BlobFixture.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp.Tests/BlobFixture.cs b/LibGit2Sharp.Tests/BlobFixture.cs
index 7afbe255f..f39429b74 100644
--- a/LibGit2Sharp.Tests/BlobFixture.cs
+++ b/LibGit2Sharp.Tests/BlobFixture.cs
@@ -43,7 +43,7 @@ public void CanGetBlobAsFilteredText(string autocrlf, string expectedText)
}
}
-#if NETFRAMEWORK || NETCOREAPP2_1
+#if NETFRAMEWORK || NETCOREAPP3_1 //UTF-7 is disabled in .NET 5
[Theory]
[InlineData("ascii", 4, "31 32 33 34")]
[InlineData("utf-7", 4, "31 32 33 34")]
From a0c46f23207f9dfc7c0b3574b22f3b5eaa605ba8 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 19:09:24 -0400
Subject: [PATCH 036/147] Remove outdated dictionary file
---
LibGit2Sharp/CustomDictionary.xml | 29 -----------------------------
LibGit2Sharp/LibGit2Sharp.csproj | 1 -
2 files changed, 30 deletions(-)
delete mode 100644 LibGit2Sharp/CustomDictionary.xml
diff --git a/LibGit2Sharp/CustomDictionary.xml b/LibGit2Sharp/CustomDictionary.xml
deleted file mode 100644
index fe603c22b..000000000
--- a/LibGit2Sharp/CustomDictionary.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
- git
- sha
- unstage
- unstaged
- compat
- oid
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 6907eb5ad..2d03a42ee 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -20,7 +20,6 @@
-
From ff9f5f02702ce548cc2f734eea8dbf5d8f345315 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 19:16:47 -0400
Subject: [PATCH 037/147] Clean up nuget.config
---
.editorconfig | 2 +-
nuget.config | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 5021a5b28..2e54d0f2d 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -14,5 +14,5 @@ insert_final_newline = true
trim_trailing_whitespace = false
insert_final_newline = false
-[*.{props,targets,csproj}]
+[*.{props,targets,csproj,config}]
indent_size = 2
\ No newline at end of file
diff --git a/nuget.config b/nuget.config
index 19d85b78f..35696f810 100644
--- a/nuget.config
+++ b/nuget.config
@@ -1,6 +1,6 @@
-
+
From 767724b3f8b1df131bf0b7d7f0377ebace44ee5e Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 19:20:35 -0400
Subject: [PATCH 038/147] Remove unneeded AssemblyInfo file
---
LibGit2Sharp/Properties/AssemblyInfo.cs | 18 ------------------
1 file changed, 18 deletions(-)
delete mode 100644 LibGit2Sharp/Properties/AssemblyInfo.cs
diff --git a/LibGit2Sharp/Properties/AssemblyInfo.cs b/LibGit2Sharp/Properties/AssemblyInfo.cs
deleted file mode 100644
index ffa977d1d..000000000
--- a/LibGit2Sharp/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-
-[assembly: CLSCompliant(true)]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-
-[assembly: Guid("c6f71967-5be1-49f5-b48e-861bff498ea3")]
From 47e674db765bb88c9a779bb4a7488345d429f878 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Oct 2021 19:21:09 -0400
Subject: [PATCH 039/147] Clean up items referenced only for packing
---
LibGit2Sharp/LibGit2Sharp.csproj | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 2d03a42ee..58c759fa5 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -20,10 +20,10 @@
-
-
-
-
+
+
+
+
From 85f1f1b7af3380bd640c67e699c77b8af2004923 Mon Sep 17 00:00:00 2001
From: OronDF343
Date: Sun, 17 Oct 2021 12:24:17 +0300
Subject: [PATCH 040/147] Fix incorrect information in exceptions
The parameters displayed in "Unknown fast forward strategy" and "Unknown merge analysis" were swapped. This change fixes that.
---
LibGit2Sharp/Repository.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 721133cc6..41aaecfbf 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -1500,13 +1500,13 @@ private MergeResult Merge(AnnotatedCommitHandle[] annotatedCommits, Signature me
break;
default:
throw new NotImplementedException(
- string.Format(CultureInfo.InvariantCulture, "Unknown fast forward strategy: {0}", mergeAnalysis));
+ string.Format(CultureInfo.InvariantCulture, "Unknown fast forward strategy: {0}", fastForwardStrategy));
}
if (mergeResult == null)
{
throw new NotImplementedException(
- string.Format(CultureInfo.InvariantCulture, "Unknown merge analysis: {0}", options.FastForwardStrategy));
+ string.Format(CultureInfo.InvariantCulture, "Unknown merge analysis: {0}", mergeAnalysis));
}
return mergeResult;
From 967bb6bd3c190f2b9be93a0e90a56df19b1285ac Mon Sep 17 00:00:00 2001
From: Artur
Date: Wed, 20 Oct 2021 09:03:29 +0200
Subject: [PATCH 041/147] use .net 6.0 SDK
---
.github/workflows/ci.yml | 12 +++++++++---
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 2 +-
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d61e3350c..d290e30d4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -28,14 +28,18 @@ jobs:
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- - name: Setup .NET SDK
+ - name: Setup .NET Core 3.1 SDK
+ uses: actions/setup-dotnet@v1.8.1
+ with:
+ dotnet-version: 3.1.x
+ - name: Setup .NET 5.0 SDK
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: 5.0.x
- - name: Setup .NET Core 3.1 runtime
+ - name: Setup .NET 6.0 SDK
uses: actions/setup-dotnet@v1.8.1
with:
- dotnet-version: 3.1.x
+ dotnet-version: 6.0.x
- name: Build
run: dotnet build LibGit2Sharp.sln --configuration Release
- name: Upload packages
@@ -52,3 +56,5 @@ jobs:
run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework netcoreapp3.1 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
- name: Run net5.0 tests
run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net5.0 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
+ - name: Run net6.0 tests
+ run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net6.0 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 24e558461..771b75696 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,7 +1,7 @@
- net472;netcoreapp3.1;net5.0
+ net472;netcoreapp3.1;net5.0;net6.0
From 98363991e0c702fd9d0e8345e44fc10b1909b12e Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 8 Nov 2021 13:52:19 -0500
Subject: [PATCH 042/147] Tweaks
---
.github/workflows/ci.yml | 10 +++++-----
LibGit2Sharp.Tests/BlobFixture.cs | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index d290e30d4..3d1d66f5f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -28,18 +28,18 @@ jobs:
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- - name: Setup .NET Core 3.1 SDK
+ - name: Install .NET SDK
uses: actions/setup-dotnet@v1.8.1
with:
- dotnet-version: 3.1.x
- - name: Setup .NET 5.0 SDK
+ dotnet-version: 6.0.x
+ - name: Install .NET 5 runtime
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: 5.0.x
- - name: Setup .NET 6.0 SDK
+ - name: Install .NET Core 3.1 runtime
uses: actions/setup-dotnet@v1.8.1
with:
- dotnet-version: 6.0.x
+ dotnet-version: 3.1.x
- name: Build
run: dotnet build LibGit2Sharp.sln --configuration Release
- name: Upload packages
diff --git a/LibGit2Sharp.Tests/BlobFixture.cs b/LibGit2Sharp.Tests/BlobFixture.cs
index f39429b74..98b30dcfc 100644
--- a/LibGit2Sharp.Tests/BlobFixture.cs
+++ b/LibGit2Sharp.Tests/BlobFixture.cs
@@ -43,7 +43,7 @@ public void CanGetBlobAsFilteredText(string autocrlf, string expectedText)
}
}
-#if NETFRAMEWORK || NETCOREAPP3_1 //UTF-7 is disabled in .NET 5
+#if NETFRAMEWORK || NETCOREAPP3_1 //UTF-7 is disabled in .NET 5+
[Theory]
[InlineData("ascii", 4, "31 32 33 34")]
[InlineData("utf-7", 4, "31 32 33 34")]
From 66dae0f806f3b7b652235c55dd3e5ac459855886 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 8 Nov 2021 19:27:26 -0500
Subject: [PATCH 043/147] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 702d35832..8ed3fb4d2 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# LibGit2Sharp
-
+[](https://github.com/libgit2/libgit2sharp/actions/workflows/ci.yml)
**LibGit2Sharp brings all the might and speed of [libgit2](http://libgit2.github.com/), a native Git implementation, to the managed world of .NET**
From 35abcc787a6148aa54521a2e5050ea52419d1231 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Oct 2021 17:45:12 -0400
Subject: [PATCH 044/147] Switch to netcoreapp3.1
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 58c759fa5..95f95a8bb 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -1,7 +1,7 @@
- netstandard2.0;netcoreapp2.1
+ netstandard2.0;netcoreapp3.1
true
LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET
LibGit2Sharp contributors
From 2bde4cbf1f2d40bd5dcf674d1ed22fcd60a82c55 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Oct 2021 17:49:57 -0400
Subject: [PATCH 045/147] Use RuntimeInformation.ProcessArchitecture
---
LibGit2Sharp/Core/Platform.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/Core/Platform.cs b/LibGit2Sharp/Core/Platform.cs
index e8d536475..42b752612 100644
--- a/LibGit2Sharp/Core/Platform.cs
+++ b/LibGit2Sharp/Core/Platform.cs
@@ -12,7 +12,7 @@ internal enum OperatingSystemType
internal static class Platform
{
- public static string ProcessorArchitecture => IntPtr.Size == 8 ? "x64" : "x86";
+ public static string ProcessorArchitecture => RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
public static OperatingSystemType OperatingSystem
{
From b6d3e2f3a9ba79fb42aba9456e6aa8fbdc63a6a8 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Oct 2021 17:51:51 -0400
Subject: [PATCH 046/147] Don't append arch to NativeLibraryPath
---
LibGit2Sharp/GlobalSettings.cs | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs
index 00b031ca0..d24637df0 100644
--- a/LibGit2Sharp/GlobalSettings.cs
+++ b/LibGit2Sharp/GlobalSettings.cs
@@ -32,7 +32,7 @@ static GlobalSettings()
if (netFX)
{
// For .NET Framework apps the dependencies are deployed to lib/win32/{architecture} directory
- nativeLibraryDefaultPath = Path.Combine(GetExecutingAssemblyDirectory(), "lib", "win32");
+ nativeLibraryDefaultPath = Path.Combine(GetExecutingAssemblyDirectory(), "lib", "win32", Platform.ProcessorArchitecture);
}
else
{
@@ -159,8 +159,6 @@ public static LogConfiguration LogConfiguration
///
/// Sets a path for loading native binaries on .NET Framework or .NET Core.
/// When specified, native library will first be searched under the given path.
- /// On .NET Framework a subdirectory corresponding to the architecture ("x86" or "x64") is appended,
- /// otherwise the native library is expected to be found in the directory as specified.
///
/// If the library is not found it will be searched in standard search paths:
/// ,
@@ -170,10 +168,6 @@ public static LogConfiguration LogConfiguration
/// This must be set before any other calls to the library,
/// and is not available on other platforms than .NET Framework and .NET Core.
///
- ///
- /// If not specified on .NET Framework it defaults to lib/win32 subdirectory
- /// of the directory where this assembly is loaded from.
- ///
///
public static string NativeLibraryPath
{
@@ -213,8 +207,7 @@ public static string NativeLibraryPath
internal static string GetAndLockNativeLibraryPath()
{
nativeLibraryPathLocked = true;
- string result = nativeLibraryPath ?? nativeLibraryDefaultPath;
- return Platform.IsRunningOnNetFramework() ? Path.Combine(result, Platform.ProcessorArchitecture) : result;
+ return nativeLibraryPath ?? nativeLibraryDefaultPath;
}
///
From 709a2c80248e055ba13e95a65ec0fa7bbe16336b Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Oct 2021 17:56:20 -0400
Subject: [PATCH 047/147] Use NativeLibrary directly when possible
---
LibGit2Sharp/Core/NativeMethods.cs | 73 +++++++-----------------------
1 file changed, 17 insertions(+), 56 deletions(-)
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 04be0e683..cb5fb45c3 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -30,7 +30,7 @@ static NativeMethods()
{
if (Platform.IsRunningOnNetFramework() || Platform.IsRunningOnNetCore())
{
- // Use .NET Core 3.0+ NativeLibrary when available.
+ // Use NativeLibrary when available.
if (!TryUseNativeLibrary())
{
// NativeLibrary is not available, fall back.
@@ -40,6 +40,7 @@ static NativeMethods()
// If this call succeeds further DllImports will find the library loaded and not attempt to load it again.
// If it fails the next DllImport will load the library from safe directories.
string nativeLibraryPath = GetGlobalSettingsNativeLibraryPath();
+
if (nativeLibraryPath != null)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -61,65 +62,21 @@ static NativeMethods()
private static string GetGlobalSettingsNativeLibraryPath()
{
string nativeLibraryDir = GlobalSettings.GetAndLockNativeLibraryPath();
+
if (nativeLibraryDir == null)
{
return null;
}
- return Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension());
- }
-
- private delegate bool TryLoadLibraryByNameDelegate(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle);
- private delegate bool TryLoadLibraryByPathDelegate(string libraryPath, out IntPtr handle);
-
- static TryLoadLibraryByNameDelegate _tryLoadLibraryByName;
- static TryLoadLibraryByPathDelegate _tryLoadLibraryByPath;
-
- static bool TryLoadLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle)
- {
- if (_tryLoadLibraryByName == null)
- {
- throw new NotSupportedException();
- }
- return _tryLoadLibraryByName(libraryName, assembly, searchPath, out handle);
- }
- static bool TryLoadLibrary(string libraryPath, out IntPtr handle)
- {
- if (_tryLoadLibraryByPath == null)
- {
- throw new NotSupportedException();
- }
- return _tryLoadLibraryByPath(libraryPath, out handle);
+ return Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension());
}
+#if NETSTANDARD
+ private static bool TryUseNativeLibrary() => false;
+#else
private static bool TryUseNativeLibrary()
{
- // NativeLibrary is available in .NET Core 3.0+.
- // We use reflection to use NativeLibrary so this library can target 'netstandard2.0'.
-
- Type dllImportResolverType = Type.GetType("System.Runtime.InteropServices.DllImportResolver, System.Runtime.InteropServices", throwOnError: false);
- Type nativeLibraryType = Type.GetType("System.Runtime.InteropServices.NativeLibrary, System.Runtime.InteropServices", throwOnError: false);
- var tryLoadLibraryByName = (TryLoadLibraryByNameDelegate)nativeLibraryType?.GetMethod("TryLoad",
- new Type[] { typeof(string), typeof(Assembly), typeof(DllImportSearchPath?), typeof(IntPtr).MakeByRefType() })?.CreateDelegate(typeof(TryLoadLibraryByNameDelegate));
- var tryLoadLibraryByPath = (TryLoadLibraryByPathDelegate)nativeLibraryType?.GetMethod("TryLoad",
- new Type[] { typeof(string), typeof(IntPtr).MakeByRefType() })?.CreateDelegate(typeof(TryLoadLibraryByPathDelegate));
- MethodInfo setDllImportResolver = nativeLibraryType?.GetMethod("SetDllImportResolver", new Type[] { typeof(Assembly), dllImportResolverType });
-
- if (dllImportResolverType == null ||
- nativeLibraryType == null ||
- tryLoadLibraryByName == null ||
- tryLoadLibraryByPath == null ||
- setDllImportResolver == null)
- {
- return false;
- }
-
- _tryLoadLibraryByPath = tryLoadLibraryByPath;
- _tryLoadLibraryByName = tryLoadLibraryByName;
-
- // NativeMethods.SetDllImportResolver(typeof(NativeMethods).Assembly, ResolveDll);
- object resolveDelegate = typeof(NativeMethods).GetMethod(nameof(ResolveDll), BindingFlags.NonPublic | BindingFlags.Static).CreateDelegate(dllImportResolverType);
- setDllImportResolver.Invoke(null, new object[] { typeof(NativeMethods).Assembly, resolveDelegate });
+ NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, ResolveDll);
return true;
}
@@ -127,23 +84,24 @@ private static bool TryUseNativeLibrary()
private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
IntPtr handle = IntPtr.Zero;
+
if (libraryName == libgit2)
{
// Use GlobalSettings.NativeLibraryPath when set.
string nativeLibraryPath = GetGlobalSettingsNativeLibraryPath();
- if (nativeLibraryPath != null &&
- TryLoadLibrary(nativeLibraryPath, out handle))
+
+ if (nativeLibraryPath != null && NativeLibrary.TryLoad(nativeLibraryPath, out handle))
{
return handle;
}
// Use Default DllImport resolution.
- if (TryLoadLibrary(libraryName, assembly, searchPath, out handle))
+ if (NativeLibrary.TryLoad(libraryName, assembly, searchPath, out handle))
{
return handle;
}
- // We cary a number of .so files for Linux which are linked against various
+ // We carry a number of .so files for Linux which are linked against various
// libc/OpenSSL libraries. Try them out.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
@@ -158,7 +116,8 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
foreach (var runtimeFolder in Directory.GetDirectories(runtimesDirectory, $"*-{processorArchitecture}"))
{
string libPath = Path.Combine(runtimeFolder, "native", $"lib{libraryName}.so");
- if (TryLoadLibrary(libPath, out handle))
+
+ if (NativeLibrary.TryLoad(libPath, out handle))
{
return handle;
}
@@ -166,8 +125,10 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
}
}
}
+
return handle;
}
+#endif
public const int RTLD_NOW = 0x002;
From 3e78e83b0123f920e0a0448d684b67c61fcebd85 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Oct 2021 17:59:37 -0400
Subject: [PATCH 048/147] Clean up unneeded pragmas
---
LibGit2Sharp/Core/NativeMethods.cs | 6 ------
1 file changed, 6 deletions(-)
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index cb5fb45c3..809a77309 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -9,9 +9,6 @@
// Restrict the set of directories where the native library is loaded from to safe directories.
[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.ApplicationDirectory | DllImportSearchPath.SafeDirectories)]
-#pragma warning disable IDE1006 // Naming Styles
-
-// ReSharper disable InconsistentNaming
namespace LibGit2Sharp.Core
{
internal static class NativeMethods
@@ -22,9 +19,7 @@ internal static class NativeMethods
// An object tied to the lifecycle of the NativeMethods static class.
// This will handle initialization and shutdown of the underlying
// native library.
-#pragma warning disable 0414
private static NativeShutdownObject shutdownObject;
-#pragma warning restore 0414
static NativeMethods()
{
@@ -2071,4 +2066,3 @@ internal static extern unsafe int git_worktree_prune(
git_worktree_prune_options options);
}
}
-// ReSharper restore InconsistentNaming
From 9a9a297ee49df921ba7e3268de3ff2279f0f79bd Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Oct 2021 18:41:46 -0400
Subject: [PATCH 049/147] Update tests
---
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 8 +++++---
NativeLibraryLoadTestApp/TestApp.cs | 4 ++--
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index 55260a6f5..8f1aa9d0b 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -1,5 +1,6 @@
using System;
using System.IO;
+using System.Reflection;
using System.Text.RegularExpressions;
using LibGit2Sharp.Core;
using LibGit2Sharp.Tests.TestHelpers;
@@ -64,12 +65,13 @@ public void LoadFromSpecifiedPath(string architecture)
var testDir = Path.GetDirectoryName(typeof(GlobalSettingsFixture).Assembly.Location);
var testAppExe = Path.Combine(testDir, $"NativeLibraryLoadTestApp.{architecture}.exe");
var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- var platformDir = Path.Combine(tempDir, "plat");
+ var platformDir = Path.Combine(tempDir, "plat", architecture);
+ var libraryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lib", "win32", architecture);
try
{
- Directory.CreateDirectory(Path.Combine(platformDir, architecture));
- File.Copy(Path.Combine(GlobalSettings.NativeLibraryPath, architecture, nativeDllFileName), Path.Combine(platformDir, architecture, nativeDllFileName));
+ Directory.CreateDirectory(platformDir);
+ File.Copy(Path.Combine(libraryPath, nativeDllFileName), Path.Combine(platformDir, nativeDllFileName));
var (output, exitCode) = ProcessHelper.RunProcess(testAppExe, arguments: $@"{NativeDllName.Name} ""{platformDir}""", workingDirectory: tempDir);
diff --git a/NativeLibraryLoadTestApp/TestApp.cs b/NativeLibraryLoadTestApp/TestApp.cs
index 234169a75..6a9f3ab60 100644
--- a/NativeLibraryLoadTestApp/TestApp.cs
+++ b/NativeLibraryLoadTestApp/TestApp.cs
@@ -11,7 +11,7 @@ public class TestApp
private static extern IntPtr GetModuleHandle(string path);
[DllImport("kernel32")]
- private static extern int GetModuleFileName(IntPtr handle, [Out]StringBuilder path, int size);
+ private static extern int GetModuleFileName(IntPtr handle, [Out] StringBuilder path, int size);
static int Main(string[] args)
{
@@ -23,7 +23,7 @@ static int Main(string[] args)
var moduleName = args[0];
var loadFromDirectory = args[1];
- var expectedPath = Path.Combine(loadFromDirectory, (IntPtr.Size == 4) ? "x86" : "x64", moduleName + ".dll");
+ var expectedPath = Path.Combine(loadFromDirectory, moduleName + ".dll");
GlobalSettings.NativeLibraryPath = loadFromDirectory;
var isValid = Repository.IsValid(Path.GetTempPath());
From 2a68da8c33ce0498563d4c60c9fd81d026a5f443 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 8 Nov 2021 22:44:25 -0500
Subject: [PATCH 050/147] Update LibGit2Sharp.NativeBinaries to
2.0.315-alpha.0.7
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 95f95a8bb..7d221c3e1 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -30,7 +30,7 @@
-
+
From 0e7ec84e1a339e0215b71f85244dd06a06d82d61 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Wed, 10 Nov 2021 20:43:58 -0500
Subject: [PATCH 051/147] Update LibGit2Sharp.NativeBinaries to
2.0.315-alpha.0.9
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 7d221c3e1..57c81cdfb 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -30,7 +30,7 @@
-
+
From bd7f5da03cde06bc54a32a6cf718761c8e0d1c52 Mon Sep 17 00:00:00 2001
From: Artur
Date: Thu, 11 Nov 2021 11:19:10 +0100
Subject: [PATCH 052/147] added jobs for running tests in docker for several
distros
---
.github/workflows/ci.yml | 36 ++++++++++++++++++++
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 2 +-
2 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3d1d66f5f..c9cdc9127 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -58,3 +58,39 @@ jobs:
run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net5.0 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
- name: Run net6.0 tests
run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net6.0 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
+ native_test:
+ name: Test on [${{ matrix.arch }}] net${{ matrix.sdk }} SDK - ${{ matrix.distro }}
+ runs-on: ubuntu-20.04
+ strategy:
+ matrix:
+ arch: [ amd64 ]
+ # arch: [ amd64, arm64 ]
+ sdk: [ '6.0', '5.0', '3.1' ]
+ distro: [ alpine.3.12, alpine.3.13, alpine.3.14, centos.7, centos.8, debian.9, debian.10, debian.11, fedora.33, ubuntu.18.04, ubuntu.20.04 ]
+ exclude:
+ - arch: arm64
+ distro: alpine.3.12
+ - arch: arm64
+ distro: alpine.3.13
+ sdk: '3.1'
+ - arch: arm64
+ distro: alpine.3.14
+ sdk: '3.1'
+ - arch: arm64
+ distro: centos.7
+ fail-fast: false
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2.3.4
+ with:
+ fetch-depth: 0
+
+ - name: Setup QEMU
+ run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
+
+ - name: Test with docker
+ run: |
+ [[ ${{ matrix.sdk }} = '3.1' ]] && target="netcoreapp${{ matrix.sdk }}" || target="net${{ matrix.sdk }}"
+
+ test_command="dotnet test LibGit2Sharp.sln --configuration Release -p:TargetFrameworks=$target -p:ExtraDefine=LEAKS_IDENTIFYING -p:GeneratePackageOnBuild=false"
+ docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$test_command"
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 771b75696..6ddcfbd05 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,7 +1,7 @@
- net472;netcoreapp3.1;net5.0;net6.0
+ net472;netcoreapp3.1;net5.0;net6.0
From b90a6a9c267b16678cb1257f2a354b991410817f Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 13 Nov 2021 22:48:48 -0500
Subject: [PATCH 053/147] Revise workflows to better integrate them
---
.github/workflows/ci.yml | 97 ++++++++++++++++++++++------------------
1 file changed, 53 insertions(+), 44 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index c9cdc9127..1f7351f39 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -11,17 +11,36 @@ env:
DOTNET_NOLOGO: true
jobs:
build:
- name: ${{ matrix.name }}
+ name: Build
+ runs-on: ubuntu-20.04
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2.3.4
+ with:
+ fetch-depth: 0
+ - name: Install .NET SDK
+ uses: actions/setup-dotnet@v1.8.1
+ with:
+ dotnet-version: 6.0.x
+ - name: Build
+ run: dotnet build LibGit2Sharp.sln --configuration Release
+ - name: Upload packages
+ uses: actions/upload-artifact@v2.2.4
+ with:
+ name: NuGet packages
+ path: bin/Packages/
+ retention-days: 7
+ test:
+ name: Test / ${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.tfm }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
- include:
- - os: windows-2019
- name: Windows
- - os: ubuntu-20.04
- name: Linux
+ arch: [ amd64 ]
+ os: [windows-2019, macos-10.15]
+ tfm: [ net472, netcoreapp3.1, net5.0, net6.0 ]
+ exclude:
- os: macos-10.15
- name: macOS
+ tfm: net472
fail-fast: false
steps:
- name: Checkout
@@ -33,64 +52,54 @@ jobs:
with:
dotnet-version: 6.0.x
- name: Install .NET 5 runtime
+ if: matrix.tfm == 'net5.0'
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: 5.0.x
- name: Install .NET Core 3.1 runtime
+ if: matrix.tfm == 'netcoreapp3.1'
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: 3.1.x
- - name: Build
- run: dotnet build LibGit2Sharp.sln --configuration Release
- - name: Upload packages
- if: matrix.name == 'Windows'
- uses: actions/upload-artifact@v2.2.4
- with:
- name: NuGet packages
- path: bin/Packages/
- retention-days: 7
- - name: Run net472 tests
- if: matrix.name == 'Windows'
- run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net472 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
- - name: Run netcoreapp3.1 tests
- run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework netcoreapp3.1 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
- - name: Run net5.0 tests
- run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net5.0 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
- - name: Run net6.0 tests
- run: dotnet test LibGit2Sharp.sln --configuration Release --no-restore --framework net6.0 --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
- native_test:
- name: Test on [${{ matrix.arch }}] net${{ matrix.sdk }} SDK - ${{ matrix.distro }}
+ - name: Run ${{ matrix.tfm }} tests
+ run: dotnet test LibGit2Sharp.sln --configuration Release --framework ${{ matrix.tfm }} --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
+ test-linux:
+ name: Test / ${{ matrix.distro }} / ${{ matrix.arch }} / ${{ matrix.tfm }}
runs-on: ubuntu-20.04
strategy:
matrix:
arch: [ amd64 ]
# arch: [ amd64, arm64 ]
- sdk: [ '6.0', '5.0', '3.1' ]
distro: [ alpine.3.12, alpine.3.13, alpine.3.14, centos.7, centos.8, debian.9, debian.10, debian.11, fedora.33, ubuntu.18.04, ubuntu.20.04 ]
+ sdk: [ '6.0', '5.0', '3.1' ]
exclude:
- - arch: arm64
- distro: alpine.3.12
- - arch: arm64
- distro: alpine.3.13
- sdk: '3.1'
- - arch: arm64
- distro: alpine.3.14
- sdk: '3.1'
- - arch: arm64
- distro: centos.7
+ - arch: arm64
+ distro: alpine.3.12
+ - arch: arm64
+ distro: alpine.3.13
+ sdk: '3.1'
+ - arch: arm64
+ distro: alpine.3.14
+ sdk: '3.1'
+ - arch: arm64
+ distro: centos.7
+ include:
+ - sdk: '6.0'
+ tfm: net6.0
+ - sdk: '5.0'
+ tfm: net5.0
+ - sdk: '3.1'
+ tfm: netcoreapp3.1
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
-
- name: Setup QEMU
+ if: matrix.arch == 'arm64'
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
-
- - name: Test with docker
+ - name: Run ${{ matrix.tfm }} tests
run: |
- [[ ${{ matrix.sdk }} = '3.1' ]] && target="netcoreapp${{ matrix.sdk }}" || target="net${{ matrix.sdk }}"
-
- test_command="dotnet test LibGit2Sharp.sln --configuration Release -p:TargetFrameworks=$target -p:ExtraDefine=LEAKS_IDENTIFYING -p:GeneratePackageOnBuild=false"
+ test_command="dotnet test LibGit2Sharp.sln --configuration Release -p:TargetFrameworks=${{ matrix.tfm }} --logger "GitHubActions" -p:ExtraDefine=LEAKS_IDENTIFYING"
docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$test_command"
From 15fbe8e9cb92662c3fef1464cefd5de34ed573e6 Mon Sep 17 00:00:00 2001
From: Louis Zanella
Date: Thu, 23 Jul 2020 16:58:42 -0400
Subject: [PATCH 054/147] Checkout branch looks to remote tracking branches as
fallback
---
LibGit2Sharp.Tests/CheckoutFixture.cs | 46 +++++++++++++++++++++++++++
LibGit2Sharp/Commands/Checkout.cs | 40 ++++++++++++++++++++---
2 files changed, 81 insertions(+), 5 deletions(-)
diff --git a/LibGit2Sharp.Tests/CheckoutFixture.cs b/LibGit2Sharp.Tests/CheckoutFixture.cs
index f0c2c36ed..8962cbc1d 100644
--- a/LibGit2Sharp.Tests/CheckoutFixture.cs
+++ b/LibGit2Sharp.Tests/CheckoutFixture.cs
@@ -1028,6 +1028,52 @@ public void CanCheckoutPathFromCurrentBranch(string fileName)
}
}
+ [Theory]
+ [InlineData("br2", "origin")]
+ [InlineData("unique/branch", "another/remote")]
+ public void CheckoutBranchTriesRemoteTrackingBranchAsFallbackAndSucceedsIfOnlyOne(string branchName, string expectedRemoteName)
+ {
+ string path = SandboxStandardTestRepo();
+ using (var repo = new Repository(path))
+ {
+ ResetAndCleanWorkingDirectory(repo);
+
+ // Define another remote
+ var otherRemote = "another/remote";
+ repo.Network.Remotes.Add(otherRemote, "https://github.com/libgit2/TestGitRepository");
+
+ // Define an extra remote tracking branch that does not conflict
+ repo.Refs.Add($"refs/remotes/{otherRemote}/unique/branch", repo.Head.Tip.Sha);
+
+ Branch branch = Commands.Checkout(repo, branchName);
+
+ Assert.NotNull(branch);
+ Assert.True(branch.IsTracking);
+ Assert.Equal($"refs/remotes/{expectedRemoteName}/{branchName}", branch.TrackedBranch.CanonicalName);
+ }
+ }
+
+ [Fact]
+ public void CheckoutBranchTriesRemoteTrackingBranchAsFallbackAndThrowsIfMoreThanOne()
+ {
+ string path = SandboxStandardTestRepo();
+ using (var repo = new Repository(path))
+ {
+ ResetAndCleanWorkingDirectory(repo);
+
+ // Define another remote
+ var otherRemote = "another/remote";
+ repo.Network.Remotes.Add(otherRemote, "https://github.com/libgit2/TestGitRepository");
+
+ // Define remote tracking branches that conflict
+ var branchName = "conflicting/branch";
+ repo.Refs.Add($"refs/remotes/origin/{branchName}", repo.Head.Tip.Sha);
+ repo.Refs.Add($"refs/remotes/{otherRemote}/{branchName}", repo.Head.Tip.Sha);
+
+ Assert.Throws(() => Commands.Checkout(repo, branchName));
+ }
+ }
+
///
/// Helper method to populate a simple repository with
/// a single file and two branches.
diff --git a/LibGit2Sharp/Commands/Checkout.cs b/LibGit2Sharp/Commands/Checkout.cs
index bcbd29616..17f3c3f9f 100644
--- a/LibGit2Sharp/Commands/Checkout.cs
+++ b/LibGit2Sharp/Commands/Checkout.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -37,18 +38,47 @@ public static Branch Checkout(IRepository repository, string committishOrBranchS
Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");
Ensure.ArgumentNotNull(options, "options");
- Reference reference;
- GitObject obj;
+ Reference reference = null;
+ GitObject obj = null;
+ Branch branch = null;
+
+ try
+ {
+ repository.RevParse(committishOrBranchSpec, out reference, out obj);
+ }
+ catch (NotFoundException)
+ {
+ // If committishOrBranchSpec is not a local branch but matches a tracking branch
+ // in exactly one remote, use it. This is the "git checkout" command's default behavior.
+ // https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt-emgitcheckoutemltbranchgt
+ var remoteBranches = repository.Network.Remotes
+ .SelectMany(r => repository.Branches.Where(b =>
+ b.IsRemote &&
+ b.CanonicalName == $"refs/remotes/{r.Name}/{committishOrBranchSpec}"))
+ .ToList();
+
+ if (remoteBranches.Count == 1)
+ {
+ branch = repository.CreateBranch(committishOrBranchSpec, remoteBranches[0].Tip);
+ repository.Branches.Update(branch, b => b.TrackedBranch = remoteBranches[0].CanonicalName);
+ return Checkout(repository, branch, options);
+ }
+
+ if (remoteBranches.Count > 1)
+ throw new AmbiguousSpecificationException(
+ $"'{committishOrBranchSpec}' matched multiple ({remoteBranches.Count}) remote tracking branches");
+
+ throw;
+ }
- repository.RevParse(committishOrBranchSpec, out reference, out obj);
if (reference != null && reference.IsLocalBranch)
{
- Branch branch = repository.Branches[reference.CanonicalName];
+ branch = repository.Branches[reference.CanonicalName];
return Checkout(repository, branch, options);
}
Commit commit = obj.Peel(true);
- Checkout(repository, commit.Tree, options, committishOrBranchSpec);
+ Checkout(repository, commit.Tree, options, committishOrBranchSpec);
return repository.Head;
}
From 44a1f22ffac7a22ce78579de9240b574fde4085e Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sat, 11 Sep 2021 20:14:57 +0200
Subject: [PATCH 055/147] Set / get supported extensions
---
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 19 +++++++++++
LibGit2Sharp/Core/NativeMethods.cs | 8 +++++
LibGit2Sharp/Core/Proxy.cs | 35 +++++++++++++++++++++
LibGit2Sharp/GlobalSettings.cs | 24 ++++++++++++++
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
5 files changed, 87 insertions(+), 1 deletion(-)
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index 8f1aa9d0b..7a701ab8c 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -83,5 +83,24 @@ public void LoadFromSpecifiedPath(string architecture)
DirectoryHelper.DeleteDirectory(tempDir);
}
}
+
+ [Fact]
+ public void SetExtensions()
+ {
+ var extensions = GlobalSettings.GetExtensions();
+
+ // Assert that "noop" is supported by default
+ Assert.Equal(new[] { "noop" }, extensions);
+
+ // Disable "noop" extensions
+ GlobalSettings.SetExtensions(new[] { "!noop" });
+ extensions = GlobalSettings.GetExtensions();
+ Assert.Empty(extensions);
+
+ // Enable two new extensions (it will reset the configuration and "noop" will be enabled)
+ GlobalSettings.SetExtensions(new[] { "partialclone", "newext" });
+ extensions = GlobalSettings.GetExtensions();
+ Assert.Equal(new[] { "noop", "partialclone", "newext" }, extensions);
+ }
}
}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 809a77309..a32325c56 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -754,6 +754,14 @@ internal static extern int git_libgit2_opts(int option,
// git_libgit2_opts(GIT_OPT_GET_USER_AGENT, git_buf *buf)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern int git_libgit2_opts(int option, GitBuf buf);
+
+ // git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, const char **extensions, size_t len)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int git_libgit2_opts(int option, string[] extensions, int len);
+
+ // git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern int git_libgit2_opts(int option, out GitStrArray extensions);
#endregion
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index ca9a69f6d..659138b1f 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -3381,6 +3381,18 @@ private enum LibGit2Option
GetWindowsSharemode, // GIT_OPT_GET_WINDOWS_SHAREMODE
SetWindowsSharemode, // GIT_OPT_SET_WINDOWS_SHAREMODE
EnableStrictHashVerification, // GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION
+ SetAllocator, // GIT_OPT_SET_ALLOCATOR,
+ EnableUnsavedIndexSafety, // GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY,
+ GetPackMaxObject, // GIT_OPT_GET_PACK_MAX_OBJECTS,
+ SetPackMaxObjects, // GIT_OPT_SET_PACK_MAX_OBJECTS,
+ DisabledPackKeepFileChecks, // GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS,
+ EnableHttpExpectContinue, // GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE,
+ GetMWindowFileLimit, // GIT_OPT_GET_MWINDOW_FILE_LIMIT,
+ SetMWindowFileLimit, // GIT_OPT_SET_MWINDOW_FILE_LIMIT,
+ SetOdbPackedPriority, // GIT_OPT_SET_ODB_PACKED_PRIORITY,
+ SetOdbLoosePriority, // GIT_OPT_SET_ODB_LOOSE_PRIORITY,
+ GetExtensions, // GIT_OPT_GET_EXTENSIONS,
+ SetExtensions, // GIT_OPT_SET_EXTENSIONS
}
///
@@ -3489,6 +3501,29 @@ public static string git_libgit2_opts_get_user_agent()
return userAgent;
}
+ public static void git_libgit2_opts_set_extensions(string[] extensions)
+ {
+ var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetExtensions, extensions, extensions.Length);
+ Ensure.ZeroResult(res);
+ }
+
+ public static string[] git_libgit2_opts_get_extensions()
+ {
+ var array = new GitStrArrayNative();
+
+ try
+ {
+ var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetExtensions, out array.Array);
+ Ensure.ZeroResult(res);
+
+ return array.ReadStrings();
+ }
+ finally
+ {
+ array.Dispose();
+ }
+ }
+
#endregion
#region git_worktree_
diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs
index d24637df0..cb3304c2c 100644
--- a/LibGit2Sharp/GlobalSettings.cs
+++ b/LibGit2Sharp/GlobalSettings.cs
@@ -383,6 +383,30 @@ public static void SetUserAgent(string userAgent)
Proxy.git_libgit2_opts_set_user_agent(userAgent);
}
+ ///
+ /// Set that the given git extensions are supported by the caller.
+ ///
+ ///
+ /// Extensions supported by libgit2 may be negated by prefixing them with a `!`. For example: setting extensions to { "!noop", "newext" } indicates that the caller does not want
+ /// to support repositories with the `noop` extension but does want to support repositories with the `newext` extension.
+ ///
+ /// Supported extensions
+ public static void SetExtensions(string[] extensions)
+ {
+ Proxy.git_libgit2_opts_set_extensions(extensions);
+ }
+
+ ///
+ /// Returns the list of git extensions that are supported.
+ ///
+ ///
+ /// This is the list of built-in extensions supported by libgit2 and custom extensions that have been added with `SetExtensions`. Extensions that have been negated will not be returned.
+ ///
+ public static string[] GetExtensions()
+ {
+ return Proxy.git_libgit2_opts_get_extensions();
+ }
+
///
/// Gets the user-agent string used by libgit2.
///
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 57c81cdfb..1bbc3073b 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -1,4 +1,4 @@
-
+
netstandard2.0;netcoreapp3.1
From 5b92d55f84db8630cc666b94beccf1f54228e62b Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sun, 12 Sep 2021 10:01:05 +0200
Subject: [PATCH 056/147] Add params keyword
---
LibGit2Sharp/GlobalSettings.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs
index cb3304c2c..f8db7401a 100644
--- a/LibGit2Sharp/GlobalSettings.cs
+++ b/LibGit2Sharp/GlobalSettings.cs
@@ -391,7 +391,7 @@ public static void SetUserAgent(string userAgent)
/// to support repositories with the `noop` extension but does want to support repositories with the `newext` extension.
///
/// Supported extensions
- public static void SetExtensions(string[] extensions)
+ public static void SetExtensions(params string[] extensions)
{
Proxy.git_libgit2_opts_set_extensions(extensions);
}
From 7f21164d569986fdf1fb198c7162b67cc9e7c491 Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Mon, 22 Nov 2021 11:14:26 +0100
Subject: [PATCH 057/147] Use GitStrArray
---
LibGit2Sharp/Core/NativeMethods.cs | 2 +-
LibGit2Sharp/Core/Proxy.cs | 7 +++++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index a32325c56..69f58fed3 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -757,7 +757,7 @@ internal static extern int git_libgit2_opts(int option,
// git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, const char **extensions, size_t len)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int git_libgit2_opts(int option, string[] extensions, int len);
+ internal static extern int git_libgit2_opts(int option, GitStrArray extensions);
// git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 659138b1f..921fd7bbc 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -3503,8 +3503,11 @@ public static string git_libgit2_opts_get_user_agent()
public static void git_libgit2_opts_set_extensions(string[] extensions)
{
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetExtensions, extensions, extensions.Length);
- Ensure.ZeroResult(res);
+ using(var array = GitStrArrayManaged.BuildFrom(extensions))
+ {
+ var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetExtensions, array.Array);
+ Ensure.ZeroResult(res);
+ }
}
public static string[] git_libgit2_opts_get_extensions()
From 5a515d77b05660fbca56e6f74e6c446aae2b7d8c Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Mon, 22 Nov 2021 11:24:47 +0100
Subject: [PATCH 058/147] Attempt to fix memory corruption
---
LibGit2Sharp/Core/NativeMethods.cs | 2 +-
LibGit2Sharp/Core/Proxy.cs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 69f58fed3..8c24cff3a 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -757,7 +757,7 @@ internal static extern int git_libgit2_opts(int option,
// git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, const char **extensions, size_t len)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int git_libgit2_opts(int option, GitStrArray extensions);
+ internal static extern int git_libgit2_opts(int option, IntPtr extensions, UIntPtr len);
// git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 921fd7bbc..425bec52a 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -3505,7 +3505,7 @@ public static void git_libgit2_opts_set_extensions(string[] extensions)
{
using(var array = GitStrArrayManaged.BuildFrom(extensions))
{
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetExtensions, array.Array);
+ var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetExtensions, array.Array.Strings, array.Array.Count);
Ensure.ZeroResult(res);
}
}
From 0a2e640f766b947ddc1b617523bcd862c25cb5d3 Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Mon, 22 Nov 2021 11:34:51 +0100
Subject: [PATCH 059/147] Cosmetic
---
LibGit2Sharp/Core/Proxy.cs | 2 +-
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 425bec52a..78c8bc914 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -3503,7 +3503,7 @@ public static string git_libgit2_opts_get_user_agent()
public static void git_libgit2_opts_set_extensions(string[] extensions)
{
- using(var array = GitStrArrayManaged.BuildFrom(extensions))
+ using (var array = GitStrArrayManaged.BuildFrom(extensions))
{
var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetExtensions, array.Array.Strings, array.Array.Count);
Ensure.ZeroResult(res);
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 1bbc3073b..57c81cdfb 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -1,4 +1,4 @@
-
+
netstandard2.0;netcoreapp3.1
From b05a00f13f416b265903b86a9f38b6cca2e50b54 Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Sun, 3 Oct 2021 19:23:22 +0200
Subject: [PATCH 060/147] Simplify dealing with missing git objects
---
LibGit2Sharp.Tests/BlobFixture.cs | 34 ++++++++++++++++++++
LibGit2Sharp.Tests/TreeFixture.cs | 42 +++++++++++++++++++++++++
LibGit2Sharp/Blob.cs | 19 ++++++++---
LibGit2Sharp/Core/GitObjectLazyGroup.cs | 4 +--
LibGit2Sharp/Core/ObjectSafeWrapper.cs | 12 ++++---
LibGit2Sharp/Core/Proxy.cs | 6 ++--
LibGit2Sharp/GitObject.cs | 18 +++++++----
LibGit2Sharp/Tree.cs | 18 ++++++-----
8 files changed, 126 insertions(+), 27 deletions(-)
diff --git a/LibGit2Sharp.Tests/BlobFixture.cs b/LibGit2Sharp.Tests/BlobFixture.cs
index 98b30dcfc..ea35e59ef 100644
--- a/LibGit2Sharp.Tests/BlobFixture.cs
+++ b/LibGit2Sharp.Tests/BlobFixture.cs
@@ -15,6 +15,7 @@ public void CanGetBlobAsText()
using (var repo = new Repository(path))
{
var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
+ Assert.False(blob.IsMissing);
var text = blob.GetContentText();
@@ -36,6 +37,7 @@ public void CanGetBlobAsFilteredText(string autocrlf, string expectedText)
repo.Config.Set("core.autocrlf", autocrlf);
var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
+ Assert.False(blob.IsMissing);
var text = blob.GetContentText(new FilteringOptions("foo.txt"));
@@ -67,6 +69,7 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
var commit = repo.Commit("bom", Constants.Signature, Constants.Signature);
var blob = (Blob)commit.Tree[bomFile].Target;
+ Assert.False(blob.IsMissing);
Assert.Equal(expectedContentBytes, blob.Size);
using (var stream = blob.GetContentStream())
{
@@ -92,6 +95,7 @@ public void CanGetBlobSize()
using (var repo = new Repository(path))
{
var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
+ Assert.False(blob.IsMissing);
Assert.Equal(10, blob.Size);
}
}
@@ -104,6 +108,7 @@ public void CanLookUpBlob()
{
var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
Assert.NotNull(blob);
+ Assert.False(blob.IsMissing);
}
}
@@ -114,6 +119,7 @@ public void CanReadBlobStream()
using (var repo = new Repository(path))
{
var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
+ Assert.False(blob.IsMissing);
var contentStream = blob.GetContentStream();
Assert.Equal(blob.Size, contentStream.Length);
@@ -140,6 +146,7 @@ public void CanReadBlobFilteredStream(string autocrlf, string expectedContent)
repo.Config.Set("core.autocrlf", autocrlf);
var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
+ Assert.False(blob.IsMissing);
var contentStream = blob.GetContentStream(new FilteringOptions("foo.txt"));
Assert.Equal(expectedContent.Length, contentStream.Length);
@@ -164,6 +171,7 @@ public void CanReadBlobFilteredStreamOfUnmodifiedBinary()
using (var stream = new MemoryStream(binaryContent))
{
Blob blob = repo.ObjectDatabase.CreateBlob(stream);
+ Assert.False(blob.IsMissing);
using (var filtered = blob.GetContentStream(new FilteringOptions("foo.txt")))
{
@@ -196,6 +204,7 @@ public void CanStageAFileGeneratedFromABlobContentStream()
Assert.Equal("baae1fb3760a73481ced1fa03dc15614142c19ef", entry.Id.Sha);
var blob = repo.Lookup(entry.Id.Sha);
+ Assert.False(blob.IsMissing);
using (Stream stream = blob.GetContentStream())
using (Stream file = File.OpenWrite(Path.Combine(repo.Info.WorkingDirectory, "small.fromblob.txt")))
@@ -217,10 +226,35 @@ public void CanTellIfTheBlobContentLooksLikeBinary()
using (var repo = new Repository(path))
{
var blob = repo.Lookup("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
+ Assert.False(blob.IsMissing);
Assert.False(blob.IsBinary);
}
}
+ [Fact]
+ public void CanTellIfABlobIsMissing()
+ {
+ string repoPath = SandboxBareTestRepo();
+
+ // Manually delete the objects directory to simulate a partial clone
+ Directory.Delete(Path.Combine(repoPath, "objects", "a8"), true);
+
+ using (var repo = new Repository(repoPath))
+ {
+ // Look up for the tree that reference the blob which is now missing
+ var tree = repo.Lookup("fd093bff70906175335656e6ce6ae05783708765");
+ var blob = (Blob) tree["README"].Target;
+
+ Assert.Equal("a8233120f6ad708f843d861ce2b7228ec4e3dec6", blob.Sha);
+ Assert.NotNull(blob);
+ Assert.True(blob.IsMissing);
+ Assert.Throws(() => blob.Size);
+ Assert.Throws(() => blob.IsBinary);
+ Assert.Throws(() => blob.GetContentText());
+ Assert.Throws(() => blob.GetContentText(new FilteringOptions("foo.txt")));
+ }
+ }
+
private static void SkipIfNotSupported(string autocrlf)
{
InconclusiveIf(() => autocrlf == "true" && Constants.IsRunningOnUnix, "Non-Windows does not support core.autocrlf = true");
diff --git a/LibGit2Sharp.Tests/TreeFixture.cs b/LibGit2Sharp.Tests/TreeFixture.cs
index 31ca85c2d..a3a8d89eb 100644
--- a/LibGit2Sharp.Tests/TreeFixture.cs
+++ b/LibGit2Sharp.Tests/TreeFixture.cs
@@ -17,6 +17,7 @@ public void CanCompareTwoTreeEntries()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
TreeEntry treeEntry1 = tree["README"];
TreeEntry treeEntry2 = tree["README"];
Assert.Equal(treeEntry2, treeEntry1);
@@ -31,6 +32,7 @@ public void CanConvertEntryToBlob()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
TreeEntry treeEntry = tree["README"];
var blob = treeEntry.Target as Blob;
@@ -45,6 +47,7 @@ public void CanConvertEntryToTree()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
TreeEntry treeEntry = tree["1"];
var subtree = treeEntry.Target as Tree;
@@ -59,6 +62,7 @@ public void CanEnumerateBlobs()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
IEnumerable blobs = tree
.Where(e => e.TargetType == TreeEntryTargetType.Blob)
@@ -76,6 +80,7 @@ public void CanEnumerateSubTrees()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
IEnumerable subTrees = tree
.Where(e => e.TargetType == TreeEntryTargetType.Tree)
@@ -93,6 +98,7 @@ public void CanEnumerateTreeEntries()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
Assert.Equal(tree.Count, tree.Count());
Assert.Equal(new[] { "1", "README", "branch_file.txt", "new.txt" }, tree.Select(te => te.Name).ToArray());
@@ -106,6 +112,7 @@ public void CanGetEntryByName()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
TreeEntry treeEntry = tree["README"];
Assert.Equal("a8233120f6ad708f843d861ce2b7228ec4e3dec6", treeEntry.Target.Sha);
Assert.Equal("README", treeEntry.Name);
@@ -119,6 +126,7 @@ public void GettingAnUknownTreeEntryReturnsNull()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
TreeEntry treeEntry = tree["I-do-not-exist"];
Assert.Null(treeEntry);
}
@@ -131,6 +139,7 @@ public void CanGetEntryCountFromTree()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
Assert.Equal(4, tree.Count);
}
}
@@ -142,6 +151,7 @@ public void CanReadEntryAttributes()
using (var repo = new Repository(path))
{
var tree = repo.Lookup(sha);
+ Assert.False(tree.IsMissing);
Assert.Equal(Mode.NonExecutableFile, tree["README"].Mode);
}
}
@@ -154,6 +164,7 @@ public void CanReadTheTreeData()
{
var tree = repo.Lookup(sha);
Assert.NotNull(tree);
+ Assert.False(tree.IsMissing);
}
}
@@ -165,6 +176,7 @@ public void TreeDataIsPresent()
{
GitObject tree = repo.Lookup(sha);
Assert.NotNull(tree);
+ Assert.False(tree.IsMissing);
}
}
@@ -175,6 +187,7 @@ public void TreeUsesPosixStylePaths()
{
/* From a commit tree */
var commitTree = repo.Lookup("4c062a6").Tree;
+ Assert.False(commitTree.IsMissing);
Assert.NotNull(commitTree["1/branch_file.txt"]);
Assert.Null(commitTree["1\\branch_file.txt"]);
}
@@ -188,6 +201,7 @@ public void CanRetrieveTreeEntryPath()
{
/* From a commit tree */
var commitTree = repo.Lookup("4c062a6").Tree;
+ Assert.False(commitTree.IsMissing);
TreeEntry treeTreeEntry = commitTree["1"];
Assert.Equal("1", treeTreeEntry.Path);
@@ -201,6 +215,7 @@ public void CanRetrieveTreeEntryPath()
// tree but exposes a complete path through its Path property
var subTree = treeTreeEntry.Target as Tree;
Assert.NotNull(subTree);
+ Assert.False(subTree.IsMissing);
TreeEntry anInstance = subTree["branch_file.txt"];
Assert.NotEqual("branch_file.txt", anInstance.Path);
@@ -239,6 +254,7 @@ public void CanParseSymlinkTreeEntries()
.Add("A symlink", linkContent, Mode.SymbolicLink);
Tree t = repo.ObjectDatabase.CreateTree(td);
+ Assert.False(t.IsMissing);
var te = t["A symlink"];
@@ -248,5 +264,31 @@ public void CanParseSymlinkTreeEntries()
Assert.Equal(linkContent, te.Target);
}
}
+
+ [Fact]
+ public void CanTellIfATreeIsMissing()
+ {
+ var path = SandboxBareTestRepo();
+
+ // Manually delete the objects directory to simulate a partial clone
+ Directory.Delete(Path.Combine(path, "objects", "fd"), true);
+
+ using (var repo = new Repository(path))
+ {
+ // Look up for the commit that reference the tree which is now missing
+ var commit = repo.Lookup("4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
+
+ Assert.True(commit.Tree.IsMissing);
+ Assert.Equal("fd093bff70906175335656e6ce6ae05783708765", commit.Tree.Sha);
+ Assert.Throws(() => commit.Tree.Count);
+ Assert.Throws(() => commit.Tree.Count());
+ Assert.Throws(() => commit.Tree["README"]);
+ Assert.Throws(() => commit.Tree.ToArray());
+ Assert.Throws(() =>
+ {
+ foreach (var _ in commit.Tree) { }
+ });
+ }
+ }
}
}
diff --git a/LibGit2Sharp/Blob.cs b/LibGit2Sharp/Blob.cs
index 9b14cb50f..d3cccf6ac 100644
--- a/LibGit2Sharp/Blob.cs
+++ b/LibGit2Sharp/Blob.cs
@@ -8,6 +8,9 @@ namespace LibGit2Sharp
///
/// Stores the binary content of a tracked file.
///
+ ///
+ /// Since the introduction of partially cloned repositories, blobs might be missing on your local repository (see https://git-scm.com/docs/partial-clone)
+ ///
public class Blob : GitObject
{
private readonly ILazy lazySize;
@@ -22,8 +25,8 @@ protected Blob()
internal Blob(Repository repo, ObjectId id)
: base(repo, id)
{
- lazySize = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_rawsize);
- lazyIsBinary = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_is_binary);
+ lazySize = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_rawsize, throwIfMissing: true);
+ lazyIsBinary = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_blob_is_binary, throwIfMissing: true);
}
///
@@ -33,16 +36,19 @@ internal Blob(Repository repo, ObjectId id)
/// can be used.
///
///
- public virtual long Size { get { return lazySize.Value; } }
+ /// Throws if blob is missing
+ public virtual long Size => lazySize.Value;
///
/// Determine if the blob content is most certainly binary or not.
///
- public virtual bool IsBinary { get { return lazyIsBinary.Value; } }
+ /// Throws if blob is missing
+ public virtual bool IsBinary => lazyIsBinary.Value;
///
/// Gets the blob content in a .
///
+ /// Throws if blob is missing
public virtual Stream GetContentStream()
{
return Proxy.git_blob_rawcontent_stream(repo.Handle, Id, Size);
@@ -53,6 +59,7 @@ public virtual Stream GetContentStream()
/// checked out to the working directory.
/// Parameter controlling content filtering behavior
///
+ /// Throws if blob is missing
public virtual Stream GetContentStream(FilteringOptions filteringOptions)
{
Ensure.ArgumentNotNull(filteringOptions, "filteringOptions");
@@ -64,6 +71,7 @@ public virtual Stream GetContentStream(FilteringOptions filteringOptions)
/// Gets the blob content, decoded with UTF8 encoding if the encoding cannot be detected from the byte order mark
///
/// Blob content as text.
+ /// Throws if blob is missing
public virtual string GetContentText()
{
return ReadToEnd(GetContentStream(), null);
@@ -75,6 +83,7 @@ public virtual string GetContentText()
///
/// The encoding of the text to use, if it cannot be detected
/// Blob content as text.
+ /// Throws if blob is missing
public virtual string GetContentText(Encoding encoding)
{
Ensure.ArgumentNotNull(encoding, "encoding");
@@ -87,6 +96,7 @@ public virtual string GetContentText(Encoding encoding)
///
/// Parameter controlling content filtering behavior
/// Blob content as text.
+ /// Throws if blob is missing
public virtual string GetContentText(FilteringOptions filteringOptions)
{
return GetContentText(filteringOptions, null);
@@ -101,6 +111,7 @@ public virtual string GetContentText(FilteringOptions filteringOptions)
/// Parameter controlling content filtering behavior
/// The encoding of the text. (default: detected or UTF8)
/// Blob content as text.
+ /// Throws if blob is missing
public virtual string GetContentText(FilteringOptions filteringOptions, Encoding encoding)
{
Ensure.ArgumentNotNull(filteringOptions, "filteringOptions");
diff --git a/LibGit2Sharp/Core/GitObjectLazyGroup.cs b/LibGit2Sharp/Core/GitObjectLazyGroup.cs
index 4e0ba384e..11c83a81e 100644
--- a/LibGit2Sharp/Core/GitObjectLazyGroup.cs
+++ b/LibGit2Sharp/Core/GitObjectLazyGroup.cs
@@ -21,11 +21,11 @@ protected override void EvaluateInternal(Action evaluator)
}
}
- public static ILazy Singleton(Repository repo, ObjectId id, Func resultSelector)
+ public static ILazy Singleton(Repository repo, ObjectId id, Func resultSelector, bool throwIfMissing = false)
{
return Singleton(() =>
{
- using (var osw = new ObjectSafeWrapper(id, repo.Handle))
+ using (var osw = new ObjectSafeWrapper(id, repo.Handle, throwIfMissing: throwIfMissing))
{
return resultSelector(osw.ObjectPtr);
}
diff --git a/LibGit2Sharp/Core/ObjectSafeWrapper.cs b/LibGit2Sharp/Core/ObjectSafeWrapper.cs
index 8bb7e9633..f2ab4a9e1 100644
--- a/LibGit2Sharp/Core/ObjectSafeWrapper.cs
+++ b/LibGit2Sharp/Core/ObjectSafeWrapper.cs
@@ -7,7 +7,7 @@ internal class ObjectSafeWrapper : IDisposable
{
private readonly ObjectHandle objectPtr;
- public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allowNullObjectId = false)
+ public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allowNullObjectId = false, bool throwIfMissing = false)
{
Ensure.ArgumentNotNull(handle, "handle");
@@ -20,13 +20,15 @@ public unsafe ObjectSafeWrapper(ObjectId id, RepositoryHandle handle, bool allow
Ensure.ArgumentNotNull(id, "id");
objectPtr = Proxy.git_object_lookup(handle, id, GitObjectType.Any);
}
- }
- public ObjectHandle ObjectPtr
- {
- get { return objectPtr; }
+ if (objectPtr == null && throwIfMissing)
+ {
+ throw new NotFoundException($"No valid git object identified by '{id}' exists in the repository.");
+ }
}
+ public ObjectHandle ObjectPtr => objectPtr;
+
public void Dispose()
{
Dispose(true);
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index ca9a69f6d..1e63bef33 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -72,7 +72,7 @@ public static unsafe ObjectId git_blob_create_from_workdir(RepositoryHandle repo
public static unsafe UnmanagedMemoryStream git_blob_filtered_content_stream(RepositoryHandle repo, ObjectId id, string path, bool check_for_binary_data)
{
var buf = new GitBuf();
- var handle = new ObjectSafeWrapper(id, repo).ObjectPtr;
+ var handle = new ObjectSafeWrapper(id, repo, throwIfMissing: true).ObjectPtr;
return new RawContentStream(handle, h =>
{
@@ -85,7 +85,7 @@ public static unsafe UnmanagedMemoryStream git_blob_filtered_content_stream(Repo
public static unsafe UnmanagedMemoryStream git_blob_rawcontent_stream(RepositoryHandle repo, ObjectId id, Int64 size)
{
- var handle = new ObjectSafeWrapper(id, repo).ObjectPtr;
+ var handle = new ObjectSafeWrapper(id, repo, throwIfMissing: true).ObjectPtr;
return new RawContentStream(handle, h => NativeMethods.git_blob_rawcontent(h), h => size);
}
@@ -3263,7 +3263,7 @@ public static unsafe TreeEntryHandle git_tree_entry_byindex(ObjectHandle tree, l
public static unsafe TreeEntryHandle git_tree_entry_bypath(RepositoryHandle repo, ObjectId id, string treeentry_path)
{
- using (var obj = new ObjectSafeWrapper(id, repo))
+ using (var obj = new ObjectSafeWrapper(id, repo, throwIfMissing: true))
{
git_tree_entry* treeEntryPtr;
int res = NativeMethods.git_tree_entry_bypath(out treeEntryPtr, obj.ObjectPtr, treeentry_path);
diff --git a/LibGit2Sharp/GitObject.cs b/LibGit2Sharp/GitObject.cs
index 218f8f141..539fe6f8b 100644
--- a/LibGit2Sharp/GitObject.cs
+++ b/LibGit2Sharp/GitObject.cs
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Globalization;
using LibGit2Sharp.Core;
-using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp
{
@@ -33,6 +31,8 @@ public abstract class GitObject : IEquatable, IBelongToARepository
private static readonly LambdaEqualityHelper equalityHelper =
new LambdaEqualityHelper(x => x.Id);
+ private readonly ILazy lazyIsMissing;
+
///
/// The containing the object.
///
@@ -53,6 +53,7 @@ protected GitObject(Repository repo, ObjectId id)
{
this.repo = repo;
Id = id;
+ lazyIsMissing = GitObjectLazyGroup.Singleton(repo, id, handle => handle == null, throwIfMissing: false);
}
///
@@ -60,13 +61,18 @@ protected GitObject(Repository repo, ObjectId id)
///
public virtual ObjectId Id { get; private set; }
+ ///
+ /// Determine if the object is missing
+ ///
+ ///
+ /// This is common when dealing with partially cloned repositories as blobs or trees could be missing
+ ///
+ public virtual bool IsMissing => lazyIsMissing.Value;
+
///
/// Gets the 40 character sha1 of this object.
///
- public virtual string Sha
- {
- get { return Id.Sha; }
- }
+ public virtual string Sha => Id.Sha;
internal static GitObject BuildFrom(Repository repo, ObjectId id, GitObjectType type, string path)
{
diff --git a/LibGit2Sharp/Tree.cs b/LibGit2Sharp/Tree.cs
index ca7055183..f8494ad8b 100644
--- a/LibGit2Sharp/Tree.cs
+++ b/LibGit2Sharp/Tree.cs
@@ -13,6 +13,9 @@ namespace LibGit2Sharp
///
/// A container which references a list of other s and s.
///
+ ///
+ /// Since the introduction of partially cloned repositories, trees might be missing on your local repository (see https://git-scm.com/docs/partial-clone)
+ ///
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Tree : GitObject, IEnumerable
{
@@ -31,19 +34,21 @@ internal Tree(Repository repo, ObjectId id, string path)
{
this.path = path ?? "";
- lazyCount = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_tree_entrycount);
+ lazyCount = GitObjectLazyGroup.Singleton(repo, id, Proxy.git_tree_entrycount, throwIfMissing: true);
}
///
/// Gets the number of immediately under this .
///
- public virtual int Count { get { return lazyCount.Value; } }
+ /// Throws if tree is missing
+ public virtual int Count => lazyCount.Value;
///
/// Gets the pointed at by the in this instance.
///
/// The relative path to the from this instance.
/// null if nothing has been found, the otherwise.
+ /// Throws if tree is missing
public virtual TreeEntry this[string relativePath]
{
get { return RetrieveFromPath(relativePath); }
@@ -69,10 +74,7 @@ private unsafe TreeEntry RetrieveFromPath(string relativePath)
}
}
- internal string Path
- {
- get { return path; }
- }
+ internal string Path => path;
#region IEnumerable Members
@@ -103,9 +105,10 @@ internal static string CombinePath(string a, string b)
/// Returns an enumerator that iterates through the collection.
///
/// An object that can be used to iterate through the collection.
+ /// Throws if tree is missing
public virtual IEnumerator GetEnumerator()
{
- using (var obj = new ObjectSafeWrapper(Id, repo.Handle))
+ using (var obj = new ObjectSafeWrapper(Id, repo.Handle, throwIfMissing: true))
{
for (uint i = 0; i < Count; i++) {
yield return byIndex(obj, i, Id, repo, path);
@@ -117,6 +120,7 @@ public virtual IEnumerator GetEnumerator()
/// Returns an enumerator that iterates through the collection.
///
/// An object that can be used to iterate through the collection.
+ /// Throws if tree is missing
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
From 3c4473c4176e5d1b4eb763ded95fa9e3450206a8 Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Mon, 22 Nov 2021 14:17:45 +0100
Subject: [PATCH 061/147] Update test
---
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index 7a701ab8c..bd9a53d1b 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -93,14 +93,19 @@ public void SetExtensions()
Assert.Equal(new[] { "noop" }, extensions);
// Disable "noop" extensions
- GlobalSettings.SetExtensions(new[] { "!noop" });
+ GlobalSettings.SetExtensions("!noop");
extensions = GlobalSettings.GetExtensions();
Assert.Empty(extensions);
// Enable two new extensions (it will reset the configuration and "noop" will be enabled)
- GlobalSettings.SetExtensions(new[] { "partialclone", "newext" });
+ GlobalSettings.SetExtensions("partialclone", "newext");
extensions = GlobalSettings.GetExtensions();
Assert.Equal(new[] { "noop", "partialclone", "newext" }, extensions);
+
+ // You can have multiple times the same extension
+ GlobalSettings.SetExtensions("noop", "test", "test" );
+ extensions = GlobalSettings.GetExtensions();
+ Assert.Equal(new[] { "noop", "noop", "test", "test" }, extensions);
}
}
}
From 316da3ba9daf21e2aa8af16e9f5693b256220382 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Wed, 29 Dec 2021 18:56:11 -0500
Subject: [PATCH 062/147] Formatting tweaks
---
LibGit2Sharp/Commands/Checkout.cs | 6 ++++--
LibGit2Sharp/Commands/Remove.cs | 5 ++---
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/LibGit2Sharp/Commands/Checkout.cs b/LibGit2Sharp/Commands/Checkout.cs
index 17f3c3f9f..46d456be1 100644
--- a/LibGit2Sharp/Commands/Checkout.cs
+++ b/LibGit2Sharp/Commands/Checkout.cs
@@ -61,12 +61,14 @@ public static Branch Checkout(IRepository repository, string committishOrBranchS
{
branch = repository.CreateBranch(committishOrBranchSpec, remoteBranches[0].Tip);
repository.Branches.Update(branch, b => b.TrackedBranch = remoteBranches[0].CanonicalName);
+
return Checkout(repository, branch, options);
}
if (remoteBranches.Count > 1)
- throw new AmbiguousSpecificationException(
- $"'{committishOrBranchSpec}' matched multiple ({remoteBranches.Count}) remote tracking branches");
+ {
+ throw new AmbiguousSpecificationException($"'{committishOrBranchSpec}' matched multiple ({remoteBranches.Count}) remote tracking branches");
+ }
throw;
}
diff --git a/LibGit2Sharp/Commands/Remove.cs b/LibGit2Sharp/Commands/Remove.cs
index 939c427d1..f96339c12 100644
--- a/LibGit2Sharp/Commands/Remove.cs
+++ b/LibGit2Sharp/Commands/Remove.cs
@@ -1,7 +1,6 @@
-using System.Linq;
+using System.Collections.Generic;
using System.IO;
-using System.Collections.Generic;
-using LibGit2Sharp;
+using System.Linq;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
From 1502b9332525a8047f1340c67cd0e85e1485083c Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Mon, 3 Jan 2022 16:15:59 +0100
Subject: [PATCH 063/147] Throw NotFoundException if trees are missing when
computing diff
---
LibGit2Sharp/Core/Proxy.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 6c6d04670..8991430bd 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -797,8 +797,8 @@ public static unsafe DiffHandle git_diff_tree_to_tree(
ObjectId newTree,
GitDiffOptions options)
{
- using (var osw1 = new ObjectSafeWrapper(oldTree, repo, true))
- using (var osw2 = new ObjectSafeWrapper(newTree, repo, true))
+ using (var osw1 = new ObjectSafeWrapper(oldTree, repo, true, throwIfMissing: true))
+ using (var osw2 = new ObjectSafeWrapper(newTree, repo, true, throwIfMissing: true))
{
git_diff* diff;
int res = NativeMethods.git_diff_tree_to_tree(out diff, repo, osw1.ObjectPtr, osw2.ObjectPtr, options);
From 93d8e453c7f8698cdbdd126da981e64c51689c96 Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Mon, 3 Jan 2022 18:10:54 +0100
Subject: [PATCH 064/147] Add test
---
LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs | 35 +++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
index d03b26e4e..e2760757b 100644
--- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
+++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
@@ -1256,5 +1256,40 @@ public void UsingPatienceAlgorithmCompareOptionProducesPatienceDiff()
Assert.Equal(diffPatience, changes);
}
}
+
+ [Fact]
+ public void DiffThrowsANotFoundExceptionIfATreeIsMissing()
+ {
+ string repoPath = SandboxBareTestRepo();
+
+ // Manually delete the objects directory to simulate a partial clone
+ File.Delete(Path.Combine(repoPath, "objects", "58", "1f9824ecaf824221bd36edf5430f2739a7c4f5"));
+
+ using (var repo = new Repository(repoPath))
+ {
+ // The commit is there but its tree is missing
+ var commit = repo.Lookup("4c062a6361ae6959e06292c1fa5e2822d9c96345");
+ Assert.NotNull(commit);
+ Assert.Equal("581f9824ecaf824221bd36edf5430f2739a7c4f5", commit.Tree.Sha);
+ Assert.True(commit.Tree.IsMissing);
+
+ var tree = repo.Lookup("581f9824ecaf824221bd36edf5430f2739a7c4f5");
+ Assert.Null(tree);
+
+ var otherCommit = repo.Lookup("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ Assert.NotNull(otherCommit);
+ Assert.False(otherCommit.Tree.IsMissing);
+
+ Assert.Throws(() =>
+ {
+ using (repo.Diff.Compare(commit.Tree, otherCommit.Tree)) {}
+ });
+
+ Assert.Throws(() =>
+ {
+ using (repo.Diff.Compare(otherCommit.Tree, commit.Tree)) {}
+ });
+ }
+ }
}
}
From 9780ddf9450ef6c740bce21a20d8e0765116fcbe Mon Sep 17 00:00:00 2001
From: Julien Richard
Date: Mon, 3 Jan 2022 19:40:27 +0100
Subject: [PATCH 065/147] Fix comment
---
LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
index e2760757b..0fe7adee1 100644
--- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
+++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
@@ -1262,7 +1262,7 @@ public void DiffThrowsANotFoundExceptionIfATreeIsMissing()
{
string repoPath = SandboxBareTestRepo();
- // Manually delete the objects directory to simulate a partial clone
+ // Manually delete the tree object to simulate a partial clone
File.Delete(Path.Combine(repoPath, "objects", "58", "1f9824ecaf824221bd36edf5430f2739a7c4f5"));
using (var repo = new Repository(repoPath))
From 6490ff1e57872c7f38de58fec4849fb88ee38b07 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 1 Apr 2022 16:43:20 -0400
Subject: [PATCH 066/147] Remove git protocol from test data
---
LibGit2Sharp.Tests/CloneFixture.cs | 10 +++-------
LibGit2Sharp.Tests/FetchFixture.cs | 10 ++++------
LibGit2Sharp.Tests/NetworkFixture.cs | 13 +++++--------
LibGit2Sharp.Tests/RepositoryFixture.cs | 2 --
4 files changed, 12 insertions(+), 23 deletions(-)
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs
index 0fefabbf6..295fc383e 100644
--- a/LibGit2Sharp.Tests/CloneFixture.cs
+++ b/LibGit2Sharp.Tests/CloneFixture.cs
@@ -13,8 +13,6 @@ public class CloneFixture : BaseFixture
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- [InlineData("git://github.com/libgit2/TestGitRepository")]
- //[InlineData("git@github.com:libgit2/TestGitRepository")]
public void CanClone(string url)
{
var scd = BuildSelfCleaningDirectory();
@@ -102,8 +100,6 @@ public void CanCloneALocalRepositoryFromANewlyCreatedTemporaryPath()
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- [InlineData("git://github.com/libgit2/TestGitRepository")]
- //[InlineData("git@github.com:libgit2/TestGitRepository")]
public void CanCloneBarely(string url)
{
var scd = BuildSelfCleaningDirectory();
@@ -126,7 +122,7 @@ public void CanCloneBarely(string url)
}
[Theory]
- [InlineData("git://github.com/libgit2/TestGitRepository")]
+ [InlineData("https://github.com/libgit2/TestGitRepository")]
public void WontCheckoutIfAskedNotTo(string url)
{
var scd = BuildSelfCleaningDirectory();
@@ -143,7 +139,7 @@ public void WontCheckoutIfAskedNotTo(string url)
}
[Theory]
- [InlineData("git://github.com/libgit2/TestGitRepository")]
+ [InlineData("https://github.com/libgit2/TestGitRepository")]
public void CallsProgressCallbacks(string url)
{
bool transferWasCalled = false;
@@ -301,7 +297,7 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
}
[Theory]
- [InlineData("git://github.com/libgit2/TestGitRepository")]
+ [InlineData("https://github.com/libgit2/TestGitRepository")]
public void CloningWithoutWorkdirPathThrows(string url)
{
Assert.Throws(() => Repository.Clone(url, null));
diff --git a/LibGit2Sharp.Tests/FetchFixture.cs b/LibGit2Sharp.Tests/FetchFixture.cs
index 01c71ebfe..c0c6f0478 100644
--- a/LibGit2Sharp.Tests/FetchFixture.cs
+++ b/LibGit2Sharp.Tests/FetchFixture.cs
@@ -4,7 +4,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -15,7 +14,6 @@ public class FetchFixture : BaseFixture
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- [InlineData("git://github.com/libgit2/TestGitRepository.git")]
public void CanFetchIntoAnEmptyRepository(string url)
{
string path = InitNewRepository();
@@ -74,7 +72,6 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- [InlineData("git://github.com/libgit2/TestGitRepository.git")]
public void CanFetchAllTagsIntoAnEmptyRepository(string url)
{
string path = InitNewRepository();
@@ -101,7 +98,8 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
}
// Perform the actual fetch
- Commands.Fetch(repo, remoteName, new string[0], new FetchOptions {
+ Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
+ {
TagFetchMode = TagFetchMode.All,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
}, null);
@@ -117,7 +115,6 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository", "test-branch", "master")]
[InlineData("https://github.com/libgit2/TestGitRepository", "master", "master")]
- [InlineData("git://github.com/libgit2/TestGitRepository.git", "master", "first-merge")]
public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string localBranchName, string remoteBranchName)
{
string path = InitNewRepository();
@@ -147,7 +144,8 @@ public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string local
}
// Perform the actual fetch
- Commands.Fetch(repo, remoteName, new string[] { refSpec }, new FetchOptions {
+ Commands.Fetch(repo, remoteName, new string[] { refSpec }, new FetchOptions
+ {
TagFetchMode = TagFetchMode.None,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
}, null);
diff --git a/LibGit2Sharp.Tests/NetworkFixture.cs b/LibGit2Sharp.Tests/NetworkFixture.cs
index 3ac73a2e8..3a3517432 100644
--- a/LibGit2Sharp.Tests/NetworkFixture.cs
+++ b/LibGit2Sharp.Tests/NetworkFixture.cs
@@ -3,7 +3,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -12,7 +11,6 @@ public class NetworkFixture : BaseFixture
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- [InlineData("git://github.com/libgit2/TestGitRepository.git")]
public void CanListRemoteReferences(string url)
{
string remoteName = "testRemote";
@@ -49,7 +47,6 @@ public void CanListRemoteReferences(string url)
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- [InlineData("git://github.com/libgit2/TestGitRepository.git")]
public void CanListRemoteReferencesFromUrl(string url)
{
string repoPath = InitNewRepository();
@@ -94,9 +91,9 @@ public void CanListRemoteReferenceObjects()
Remote remote = repo.Network.Remotes[remoteName];
IEnumerable references = repo.Network.ListReferences(remote).ToList();
- var actualRefs = new List>();
+ var actualRefs = new List>();
- foreach(Reference reference in references)
+ foreach (Reference reference in references)
{
Assert.NotNull(reference.CanonicalName);
@@ -166,7 +163,7 @@ public void CanPull(FastForwardStrategy fastForwardStrategy)
MergeResult mergeResult = Commands.Pull(repo, Constants.Signature, pullOptions);
- if(fastForwardStrategy == FastForwardStrategy.Default || fastForwardStrategy == FastForwardStrategy.FastForwardOnly)
+ if (fastForwardStrategy == FastForwardStrategy.Default || fastForwardStrategy == FastForwardStrategy.FastForwardOnly)
{
Assert.Equal(MergeStatus.FastForward, mergeResult.Status);
Assert.Equal(mergeResult.Commit, repo.Branches["refs/remotes/origin/master"].Tip);
@@ -226,7 +223,7 @@ public void PullWithoutMergeBranchThrows()
{
Commands.Pull(repo, Constants.Signature, new PullOptions());
}
- catch(MergeFetchHeadNotFoundException ex)
+ catch (MergeFetchHeadNotFoundException ex)
{
didPullThrow = true;
thrownException = ex;
@@ -293,7 +290,7 @@ public void CanPruneRefs()
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);
// but we do when asked by the user
- Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true}, null);
+ Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true }, null);
Assert.Null(repo.Refs["refs/remotes/pruner/master"]);
}
}
diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs
index 5c551fabd..bf27b6091 100644
--- a/LibGit2Sharp.Tests/RepositoryFixture.cs
+++ b/LibGit2Sharp.Tests/RepositoryFixture.cs
@@ -4,7 +4,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -709,7 +708,6 @@ public void CanListRemoteReferencesWithCredentials()
[Theory]
[InlineData("http://github.com/libgit2/TestGitRepository")]
[InlineData("https://github.com/libgit2/TestGitRepository")]
- [InlineData("git://github.com/libgit2/TestGitRepository.git")]
public void CanListRemoteReferences(string url)
{
IEnumerable references = Repository.ListRemoteReferences(url).ToList();
From 4731263c2e1e83b75eb5b278318cc58d32290b6a Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 1 Apr 2022 16:59:12 -0400
Subject: [PATCH 067/147] Comment out Bitbucket tests
---
LibGit2Sharp.Tests/CloneFixture.cs | 46 ++++----
.../desktop/SmartSubtransportFixture.cs | 106 +++++++++---------
2 files changed, 75 insertions(+), 77 deletions(-)
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs
index 295fc383e..1b26c1226 100644
--- a/LibGit2Sharp.Tests/CloneFixture.cs
+++ b/LibGit2Sharp.Tests/CloneFixture.cs
@@ -208,29 +208,29 @@ static Credentials CreateUsernamePasswordCredentials(string user, string pass, b
};
}
- [Theory]
- [InlineData("https://libgit2@bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3", true)]
- [InlineData("https://libgit2@bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3", false)]
- public void CanCloneFromBBWithCredentials(string url, string user, string pass, bool secure)
- {
- var scd = BuildSelfCleaningDirectory();
-
- string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
- {
- CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials(user, pass, secure)
- });
-
- using (var repo = new Repository(clonedRepoPath))
- {
- string dir = repo.Info.Path;
- Assert.True(Path.IsPathRooted(dir));
- Assert.True(Directory.Exists(dir));
-
- Assert.NotNull(repo.Info.WorkingDirectory);
- Assert.Equal(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar), repo.Info.Path);
- Assert.False(repo.Info.IsBare);
- }
- }
+ //[Theory]
+ //[InlineData("https://libgit2@bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3", true)]
+ //[InlineData("https://libgit2@bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3", false)]
+ //public void CanCloneFromBBWithCredentials(string url, string user, string pass, bool secure)
+ //{
+ // var scd = BuildSelfCleaningDirectory();
+
+ // string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
+ // {
+ // CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials(user, pass, secure)
+ // });
+
+ // using (var repo = new Repository(clonedRepoPath))
+ // {
+ // string dir = repo.Info.Path;
+ // Assert.True(Path.IsPathRooted(dir));
+ // Assert.True(Directory.Exists(dir));
+
+ // Assert.NotNull(repo.Info.WorkingDirectory);
+ // Assert.Equal(Path.Combine(scd.RootedDirectoryPath, ".git" + Path.DirectorySeparatorChar), repo.Info.Path);
+ // Assert.False(repo.Info.IsBare);
+ // }
+ //}
[SkippableTheory]
[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
diff --git a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
index e72c0d7c1..ff4d0fcd6 100644
--- a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
+++ b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
@@ -4,9 +4,7 @@
using System.Net;
using System.Net.Security;
using LibGit2Sharp.Tests.TestHelpers;
-using LibGit2Sharp.Core;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -79,58 +77,58 @@ public void CustomSmartSubtransportTest(string scheme, string url)
}
}
- [Theory]
- [InlineData("https", "https://bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3")]
- public void CanUseCredentials(string scheme, string url, string user, string pass)
- {
- string remoteName = "testRemote";
-
- var scd = BuildSelfCleaningDirectory();
- Repository.Init(scd.RootedDirectoryPath);
-
- SmartSubtransportRegistration registration = null;
-
- try
- {
- // Disable server certificate validation for testing.
- // Do *NOT* enable this in production.
- ServicePointManager.ServerCertificateValidationCallback = certificateValidationCallback;
-
- registration = GlobalSettings.RegisterSmartSubtransport(scheme);
- Assert.NotNull(registration);
-
- using (var repo = new Repository(scd.DirectoryPath))
- {
- repo.Network.Remotes.Add(remoteName, url);
-
- // Set up structures for the expected results
- // and verifying the RemoteUpdateTips callback.
- TestRemoteInfo expectedResults = TestRemoteInfo.TestRemoteInstance;
- ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);
-
- // Add expected branch objects
- foreach (KeyValuePair kvp in expectedResults.BranchTips)
- {
- expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
- }
-
- // Perform the actual fetch
- Commands.Fetch(repo, remoteName, new string[0], new FetchOptions {
- OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto,
- CredentialsProvider = (_user, _valid, _hostname) => new UsernamePasswordCredentials() { Username = user, Password = pass },
- }, null);
-
- // Verify the expected
- expectedFetchState.CheckUpdatedReferences(repo);
- }
- }
- finally
- {
- GlobalSettings.UnregisterSmartSubtransport(registration);
-
- ServicePointManager.ServerCertificateValidationCallback -= certificateValidationCallback;
- }
- }
+ //[Theory]
+ //[InlineData("https", "https://bitbucket.org/libgit2/testgitrepository.git", "libgit3", "libgit3")]
+ //public void CanUseCredentials(string scheme, string url, string user, string pass)
+ //{
+ // string remoteName = "testRemote";
+
+ // var scd = BuildSelfCleaningDirectory();
+ // Repository.Init(scd.RootedDirectoryPath);
+
+ // SmartSubtransportRegistration registration = null;
+
+ // try
+ // {
+ // // Disable server certificate validation for testing.
+ // // Do *NOT* enable this in production.
+ // ServicePointManager.ServerCertificateValidationCallback = certificateValidationCallback;
+
+ // registration = GlobalSettings.RegisterSmartSubtransport(scheme);
+ // Assert.NotNull(registration);
+
+ // using (var repo = new Repository(scd.DirectoryPath))
+ // {
+ // repo.Network.Remotes.Add(remoteName, url);
+
+ // // Set up structures for the expected results
+ // // and verifying the RemoteUpdateTips callback.
+ // TestRemoteInfo expectedResults = TestRemoteInfo.TestRemoteInstance;
+ // ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);
+
+ // // Add expected branch objects
+ // foreach (KeyValuePair kvp in expectedResults.BranchTips)
+ // {
+ // expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
+ // }
+
+ // // Perform the actual fetch
+ // Commands.Fetch(repo, remoteName, new string[0], new FetchOptions {
+ // OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto,
+ // CredentialsProvider = (_user, _valid, _hostname) => new UsernamePasswordCredentials() { Username = user, Password = pass },
+ // }, null);
+
+ // // Verify the expected
+ // expectedFetchState.CheckUpdatedReferences(repo);
+ // }
+ // }
+ // finally
+ // {
+ // GlobalSettings.UnregisterSmartSubtransport(registration);
+
+ // ServicePointManager.ServerCertificateValidationCallback -= certificateValidationCallback;
+ // }
+ //}
[Fact]
public void CannotReregisterScheme()
From 5e78b8211b4bac24e9c94186bb46caff8687ef9f Mon Sep 17 00:00:00 2001
From: Filip Rindler
Date: Fri, 1 Apr 2022 18:21:22 +0100
Subject: [PATCH 068/147] Fixed calling into native libgit2 on osx-arm64
(git_libgit2_opts variadic parameters)
---
LibGit2Sharp/Core/NativeMethods.cs | 36 +++++++++++++++++
LibGit2Sharp/Core/Proxy.cs | 62 +++++++++++++++++++++++++-----
2 files changed, 88 insertions(+), 10 deletions(-)
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 8c24cff3a..f5d45f3cf 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -764,6 +764,42 @@ internal static extern int git_libgit2_opts(int option,
internal static extern int git_libgit2_opts(int option, out GitStrArray extensions);
#endregion
+ #region git_libgit2_opts_osxarm64
+
+ // For RID osx-arm64 the calling convention is different: we need to pad out to 8 arguments before varargs
+ // (see discussion at https://github.com/dotnet/runtime/issues/48796)
+
+ // git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, int level, git_buf *buf)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, uint level, GitBuf buf);
+
+ // git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, int level, const char *path)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, uint level,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string path);
+
+ // git_libgit2_opts(GIT_OPT_ENABLE_*, int enabled)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int enabled);
+
+ // git_libgit2_opts(GIT_OPT_SET_USER_AGENT, const char *path)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string path);
+
+ // git_libgit2_opts(GIT_OPT_GET_USER_AGENT, git_buf *buf)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, GitBuf buf);
+
+ // git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, const char **extensions, size_t len)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, IntPtr extensions, UIntPtr len);
+
+ // git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, out GitStrArray extensions);
+ #endregion
+
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_graph_ahead_behind(out UIntPtr ahead, out UIntPtr behind, git_repository* repo, ref GitOid one, ref GitOid two);
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 8991430bd..cd32050c4 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -14,6 +14,9 @@ namespace LibGit2Sharp.Core
{
internal class Proxy
{
+ internal static readonly bool isOSXArm64 = RuntimeInformation.ProcessArchitecture == Architecture.Arm64
+ && RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
+
#region git_blame_
public static unsafe BlameHandle git_blame_file(
@@ -3408,7 +3411,11 @@ public static string git_libgit2_opts_get_search_path(ConfigurationLevel level)
using (var buf = new GitBuf())
{
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetSearchPath, (uint)level, buf);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.GetSearchPath, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, (uint)level, buf);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetSearchPath, (uint)level, buf);
Ensure.ZeroResult(res);
path = LaxUtf8Marshaler.FromNative(buf.ptr) ?? string.Empty;
@@ -3419,7 +3426,10 @@ public static string git_libgit2_opts_get_search_path(ConfigurationLevel level)
public static void git_libgit2_opts_enable_strict_hash_verification(bool enabled)
{
- NativeMethods.git_libgit2_opts((int)LibGit2Option.EnableStrictHashVerification, enabled ? 1 : 0);
+ if (isOSXArm64)
+ NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.EnableStrictHashVerification, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, enabled ? 1 : 0);
+ else
+ NativeMethods.git_libgit2_opts((int)LibGit2Option.EnableStrictHashVerification, enabled ? 1 : 0);
}
///
@@ -3432,7 +3442,11 @@ public static void git_libgit2_opts_enable_strict_hash_verification(bool enabled
///
public static void git_libgit2_opts_set_search_path(ConfigurationLevel level, string path)
{
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetSearchPath, (uint)level, path);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.SetSearchPath, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, (uint)level, path);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetSearchPath, (uint)level, path);
Ensure.ZeroResult(res);
}
@@ -3443,7 +3457,11 @@ public static void git_libgit2_opts_set_search_path(ConfigurationLevel level, st
public static void git_libgit2_opts_set_enable_caching(bool enabled)
{
// libgit2 expects non-zero value for true
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.EnableCaching, enabled ? 1 : 0);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.EnableCaching, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, enabled ? 1 : 0);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.EnableCaching, enabled ? 1 : 0);
Ensure.ZeroResult(res);
}
@@ -3454,7 +3472,11 @@ public static void git_libgit2_opts_set_enable_caching(bool enabled)
public static void git_libgit2_opts_set_enable_ofsdelta(bool enabled)
{
// libgit2 expects non-zero value for true
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.EnableOfsDelta, enabled ? 1 : 0);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.EnableOfsDelta, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, enabled ? 1 : 0);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.EnableOfsDelta, enabled ? 1 : 0);
Ensure.ZeroResult(res);
}
@@ -3465,7 +3487,11 @@ public static void git_libgit2_opts_set_enable_ofsdelta(bool enabled)
public static void git_libgit2_opts_set_enable_strictobjectcreation(bool enabled)
{
// libgit2 expects non-zero value for true
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.EnableStrictObjectCreation, enabled ? 1 : 0);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.EnableStrictObjectCreation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, enabled ? 1 : 0);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.EnableStrictObjectCreation, enabled ? 1 : 0);
Ensure.ZeroResult(res);
}
@@ -3476,7 +3502,11 @@ public static void git_libgit2_opts_set_enable_strictobjectcreation(bool enabled
/// The user-agent string to use
public static void git_libgit2_opts_set_user_agent(string userAgent)
{
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetUserAgent, userAgent);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.SetUserAgent, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, userAgent);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetUserAgent, userAgent);
Ensure.ZeroResult(res);
}
@@ -3492,7 +3522,11 @@ public static string git_libgit2_opts_get_user_agent()
using (var buf = new GitBuf())
{
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetUserAgent, buf);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.GetUserAgent, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, buf);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetUserAgent, buf);
Ensure.ZeroResult(res);
userAgent = LaxUtf8Marshaler.FromNative(buf.ptr) ?? string.Empty;
@@ -3505,7 +3539,11 @@ public static void git_libgit2_opts_set_extensions(string[] extensions)
{
using (var array = GitStrArrayManaged.BuildFrom(extensions))
{
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetExtensions, array.Array.Strings, array.Array.Count);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.SetExtensions, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, array.Array.Strings, array.Array.Count);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetExtensions, array.Array.Strings, array.Array.Count);
Ensure.ZeroResult(res);
}
}
@@ -3516,7 +3554,11 @@ public static string[] git_libgit2_opts_get_extensions()
try
{
- var res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetExtensions, out array.Array);
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.GetExtensions, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out array.Array);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetExtensions, out array.Array);
Ensure.ZeroResult(res);
return array.ReadStrings();
From a642baea52a5ac652d5248b4e9f064bf1b527dd7 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 2 Apr 2022 15:55:08 -0400
Subject: [PATCH 069/147] Stop testing .NET 5
---
.github/workflows/ci.yml | 11 ++---------
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 2 +-
2 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1f7351f39..118649aa2 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -37,7 +37,7 @@ jobs:
matrix:
arch: [ amd64 ]
os: [windows-2019, macos-10.15]
- tfm: [ net472, netcoreapp3.1, net5.0, net6.0 ]
+ tfm: [ net472, netcoreapp3.1, net6.0 ]
exclude:
- os: macos-10.15
tfm: net472
@@ -51,11 +51,6 @@ jobs:
uses: actions/setup-dotnet@v1.8.1
with:
dotnet-version: 6.0.x
- - name: Install .NET 5 runtime
- if: matrix.tfm == 'net5.0'
- uses: actions/setup-dotnet@v1.8.1
- with:
- dotnet-version: 5.0.x
- name: Install .NET Core 3.1 runtime
if: matrix.tfm == 'netcoreapp3.1'
uses: actions/setup-dotnet@v1.8.1
@@ -71,7 +66,7 @@ jobs:
arch: [ amd64 ]
# arch: [ amd64, arm64 ]
distro: [ alpine.3.12, alpine.3.13, alpine.3.14, centos.7, centos.8, debian.9, debian.10, debian.11, fedora.33, ubuntu.18.04, ubuntu.20.04 ]
- sdk: [ '6.0', '5.0', '3.1' ]
+ sdk: [ '6.0', '3.1' ]
exclude:
- arch: arm64
distro: alpine.3.12
@@ -86,8 +81,6 @@ jobs:
include:
- sdk: '6.0'
tfm: net6.0
- - sdk: '5.0'
- tfm: net5.0
- sdk: '3.1'
tfm: netcoreapp3.1
fail-fast: false
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 6ddcfbd05..25e652522 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,7 +1,7 @@
- net472;netcoreapp3.1;net5.0;net6.0
+ net472;netcoreapp3.1;net6.0
From 70d62d5adf6ac951d756d115c6b34b719947a83a Mon Sep 17 00:00:00 2001
From: Edward Thomson
Date: Thu, 23 Feb 2023 11:33:36 -0800
Subject: [PATCH 070/147] LibGit2Sharp: update to libgit2 v1.6.2
---
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 11 +++-----
LibGit2Sharp/Core/GitFetchOptions.cs | 1 +
LibGit2Sharp/Core/GitOdbBackend.cs | 6 ++---
LibGit2Sharp/Core/GitPushOptions.cs | 1 +
LibGit2Sharp/Core/GitWorktree.cs | 2 ++
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
LibGit2Sharp/RemoteRedirectMode.cs | 28 +++++++++++++++++++++
7 files changed, 38 insertions(+), 13 deletions(-)
create mode 100644 LibGit2Sharp/RemoteRedirectMode.cs
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index bd9a53d1b..e067fd192 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -90,22 +90,17 @@ public void SetExtensions()
var extensions = GlobalSettings.GetExtensions();
// Assert that "noop" is supported by default
- Assert.Equal(new[] { "noop" }, extensions);
+ Assert.Equal(new[] { "noop", "objectformat" }, extensions);
// Disable "noop" extensions
GlobalSettings.SetExtensions("!noop");
extensions = GlobalSettings.GetExtensions();
- Assert.Empty(extensions);
+ Assert.Equal(new[] { "objectformat" }, extensions);
// Enable two new extensions (it will reset the configuration and "noop" will be enabled)
GlobalSettings.SetExtensions("partialclone", "newext");
extensions = GlobalSettings.GetExtensions();
- Assert.Equal(new[] { "noop", "partialclone", "newext" }, extensions);
-
- // You can have multiple times the same extension
- GlobalSettings.SetExtensions("noop", "test", "test" );
- extensions = GlobalSettings.GetExtensions();
- Assert.Equal(new[] { "noop", "noop", "test", "test" }, extensions);
+ Assert.Equal(new[] { "noop", "objectformat", "partialclone", "newext" }, extensions);
}
}
}
diff --git a/LibGit2Sharp/Core/GitFetchOptions.cs b/LibGit2Sharp/Core/GitFetchOptions.cs
index 3f0baa2c2..bdf8aa585 100644
--- a/LibGit2Sharp/Core/GitFetchOptions.cs
+++ b/LibGit2Sharp/Core/GitFetchOptions.cs
@@ -11,6 +11,7 @@ internal class GitFetchOptions
public bool UpdateFetchHead = true;
public TagFetchMode download_tags;
public GitProxyOptions ProxyOptions;
+ public RemoteRedirectMode FollowRedirects = RemoteRedirectMode.Auto;
public GitStrArrayManaged CustomHeaders;
}
}
diff --git a/LibGit2Sharp/Core/GitOdbBackend.cs b/LibGit2Sharp/Core/GitOdbBackend.cs
index 3ff031048..6f017542d 100644
--- a/LibGit2Sharp/Core/GitOdbBackend.cs
+++ b/LibGit2Sharp/Core/GitOdbBackend.cs
@@ -33,10 +33,8 @@ static GitOdbBackend()
public exists_prefix_callback ExistsPrefix;
public IntPtr Refresh;
public foreach_callback Foreach;
-
- private IntPtr Padding; // TODO: add writemidx
-
- public IntPtr Writepack;
+ public IntPtr WritePack;
+ public IntPtr WriteMidx;
public IntPtr Freshen;
public free_callback Free;
diff --git a/LibGit2Sharp/Core/GitPushOptions.cs b/LibGit2Sharp/Core/GitPushOptions.cs
index f733534d2..8c98ce9cc 100644
--- a/LibGit2Sharp/Core/GitPushOptions.cs
+++ b/LibGit2Sharp/Core/GitPushOptions.cs
@@ -9,6 +9,7 @@ internal class GitPushOptions
public int PackbuilderDegreeOfParallelism;
public GitRemoteCallbacks RemoteCallbacks;
public GitProxyOptions ProxyOptions;
+ public RemoteRedirectMode FollowRedirects = RemoteRedirectMode.Auto;
public GitStrArrayManaged CustomHeaders;
}
}
diff --git a/LibGit2Sharp/Core/GitWorktree.cs b/LibGit2Sharp/Core/GitWorktree.cs
index c71cb16c0..b3200dd91 100644
--- a/LibGit2Sharp/Core/GitWorktree.cs
+++ b/LibGit2Sharp/Core/GitWorktree.cs
@@ -37,6 +37,8 @@ internal class git_worktree_add_options
public int locked;
public IntPtr @ref = IntPtr.Zero;
+
+ public GitCheckoutOpts checkoutOpts = new GitCheckoutOpts { version = 1 };
}
[StructLayout(LayoutKind.Sequential)]
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 57c81cdfb..03025744f 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -30,7 +30,7 @@
-
+
diff --git a/LibGit2Sharp/RemoteRedirectMode.cs b/LibGit2Sharp/RemoteRedirectMode.cs
new file mode 100644
index 000000000..08866e68a
--- /dev/null
+++ b/LibGit2Sharp/RemoteRedirectMode.cs
@@ -0,0 +1,28 @@
+namespace LibGit2Sharp
+{
+ ///
+ /// Remote redirection settings; wehther redirects to another
+ /// host are permitted. By default, git will follow a redirect
+ /// on the initial request (`/info/refs`) but not subsequent
+ /// requests.
+ ///
+ public enum RemoteRedirectMode
+ {
+ ///
+ /// Do not follow any off-site redirects at any stage of
+ /// the fetch or push.
+ ///
+ None = 0, // GIT_REMOTE_REDIRECT_NONE
+
+ ///
+ /// Allow off-site redirects only upon the initial
+ /// request. This is the default.
+ ///
+ Auto, // GIT_REMOTE_REDIRECT_INITIAL
+
+ ///
+ /// Allow redirects at any stage in the fetch or push.
+ ///
+ All // GIT_REMOTE_REDIRECT_ALL
+ }
+}
From d0d80290360d9400aafc5814ea78ed5050853b48 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 7 Apr 2023 17:13:35 -0400
Subject: [PATCH 071/147] Update LibGit2Sharp.NativeBinaries to 2.0.319
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 03025744f..c81dd7093 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -30,7 +30,7 @@
-
+
From 1be14ba9a39bffca8b6a272ba780a7b1bdf1119d Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 7 Apr 2023 17:33:44 -0400
Subject: [PATCH 072/147] Update action versions
---
.github/workflows/ci.yml | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 118649aa2..ac62110ec 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -15,17 +15,17 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout
- uses: actions/checkout@v2.3.4
+ uses: actions/checkout@v3.5.0
with:
fetch-depth: 0
- name: Install .NET SDK
- uses: actions/setup-dotnet@v1.8.1
+ uses: actions/setup-dotnet@v3.0.3
with:
dotnet-version: 6.0.x
- name: Build
run: dotnet build LibGit2Sharp.sln --configuration Release
- name: Upload packages
- uses: actions/upload-artifact@v2.2.4
+ uses: actions/upload-artifact@v3.1.2
with:
name: NuGet packages
path: bin/Packages/
@@ -44,16 +44,16 @@ jobs:
fail-fast: false
steps:
- name: Checkout
- uses: actions/checkout@v2.3.4
+ uses: actions/checkout@v3.5.0
with:
fetch-depth: 0
- name: Install .NET SDK
- uses: actions/setup-dotnet@v1.8.1
+ uses: actions/setup-dotnet@v3.0.3
with:
dotnet-version: 6.0.x
- name: Install .NET Core 3.1 runtime
if: matrix.tfm == 'netcoreapp3.1'
- uses: actions/setup-dotnet@v1.8.1
+ uses: actions/setup-dotnet@v3.0.3
with:
dotnet-version: 3.1.x
- name: Run ${{ matrix.tfm }} tests
@@ -86,7 +86,7 @@ jobs:
fail-fast: false
steps:
- name: Checkout
- uses: actions/checkout@v2.3.4
+ uses: actions/checkout@v3.5.0
with:
fetch-depth: 0
- name: Setup QEMU
From b5bb4d5b168e325cd99539acc5143098a2dbf0e7 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 7 Apr 2023 17:45:09 -0400
Subject: [PATCH 073/147] Add .NET 7 and remove .NET Core 3.1
---
.github/workflows/ci.yml | 21 +++++++++-----------
LibGit2Sharp.Tests/BlobFixture.cs | 6 +++---
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 2 +-
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
4 files changed, 14 insertions(+), 17 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ac62110ec..878d9ecd1 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -21,7 +21,7 @@ jobs:
- name: Install .NET SDK
uses: actions/setup-dotnet@v3.0.3
with:
- dotnet-version: 6.0.x
+ dotnet-version: 7.0.x
- name: Build
run: dotnet build LibGit2Sharp.sln --configuration Release
- name: Upload packages
@@ -36,8 +36,8 @@ jobs:
strategy:
matrix:
arch: [ amd64 ]
- os: [windows-2019, macos-10.15]
- tfm: [ net472, netcoreapp3.1, net6.0 ]
+ os: [ windows-2019, macos-10.15 ]
+ tfm: [ net472, net6.0, net7.0 ]
exclude:
- os: macos-10.15
tfm: net472
@@ -50,12 +50,9 @@ jobs:
- name: Install .NET SDK
uses: actions/setup-dotnet@v3.0.3
with:
- dotnet-version: 6.0.x
- - name: Install .NET Core 3.1 runtime
- if: matrix.tfm == 'netcoreapp3.1'
- uses: actions/setup-dotnet@v3.0.3
- with:
- dotnet-version: 3.1.x
+ dotnet-version: |
+ 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
test-linux:
@@ -66,7 +63,7 @@ jobs:
arch: [ amd64 ]
# arch: [ amd64, arm64 ]
distro: [ alpine.3.12, alpine.3.13, alpine.3.14, centos.7, centos.8, debian.9, debian.10, debian.11, fedora.33, ubuntu.18.04, ubuntu.20.04 ]
- sdk: [ '6.0', '3.1' ]
+ sdk: [ '6.0', '7.0' ]
exclude:
- arch: arm64
distro: alpine.3.12
@@ -81,8 +78,8 @@ jobs:
include:
- sdk: '6.0'
tfm: net6.0
- - sdk: '3.1'
- tfm: netcoreapp3.1
+ - sdk: '7.0'
+ tfm: net7.0
fail-fast: false
steps:
- name: Checkout
diff --git a/LibGit2Sharp.Tests/BlobFixture.cs b/LibGit2Sharp.Tests/BlobFixture.cs
index ea35e59ef..314dea379 100644
--- a/LibGit2Sharp.Tests/BlobFixture.cs
+++ b/LibGit2Sharp.Tests/BlobFixture.cs
@@ -45,7 +45,7 @@ public void CanGetBlobAsFilteredText(string autocrlf, string expectedText)
}
}
-#if NETFRAMEWORK || NETCOREAPP3_1 //UTF-7 is disabled in .NET 5+
+#if NETFRAMEWORK //UTF-7 is disabled in .NET 5+
[Theory]
[InlineData("ascii", 4, "31 32 33 34")]
[InlineData("utf-7", 4, "31 32 33 34")]
@@ -239,11 +239,11 @@ public void CanTellIfABlobIsMissing()
// Manually delete the objects directory to simulate a partial clone
Directory.Delete(Path.Combine(repoPath, "objects", "a8"), true);
- using (var repo = new Repository(repoPath))
+ using (var repo = new Repository(repoPath))
{
// Look up for the tree that reference the blob which is now missing
var tree = repo.Lookup("fd093bff70906175335656e6ce6ae05783708765");
- var blob = (Blob) tree["README"].Target;
+ var blob = (Blob)tree["README"].Target;
Assert.Equal("a8233120f6ad708f843d861ce2b7228ec4e3dec6", blob.Sha);
Assert.NotNull(blob);
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 25e652522..dc17e6d53 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,7 +1,7 @@
- net472;netcoreapp3.1;net6.0
+ net472;net6.0;net7.0
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index c81dd7093..bb6365716 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -1,7 +1,7 @@
- netstandard2.0;netcoreapp3.1
+ netstandard2.0;net6.0
true
LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET
LibGit2Sharp contributors
From fbbfd7121b51a7dd1797cd34f38f9ed736a8b395 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 01:29:05 -0400
Subject: [PATCH 074/147] Fix warning
---
LibGit2Sharp/ObjectDatabase.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs
index 52aceb321..b48c72a99 100644
--- a/LibGit2Sharp/ObjectDatabase.cs
+++ b/LibGit2Sharp/ObjectDatabase.cs
@@ -315,10 +315,10 @@ private unsafe Blob CreateBlob(Stream stream, string hintpath, long? numberOfByt
throw new EndOfStreamException("The stream ended unexpectedly");
}
}
- catch(Exception e)
+ catch (Exception)
{
writestream.free(writestream_ptr);
- throw e;
+ throw;
}
ObjectId id = Proxy.git_blob_create_fromstream_commit(writestream_ptr);
From 03cb81103f937385d004cadfeddf77a2470d74e1 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 01:34:36 -0400
Subject: [PATCH 075/147] Update testing packages
---
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index dc17e6d53..c5cbb5f24 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -11,12 +11,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
From 81d501c16741a3d7b258750b1b45d56ed2ea9025 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 01:36:17 -0400
Subject: [PATCH 076/147] Update Microsoft.SourceLink.GitHub
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index bb6365716..597f37e31 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -31,7 +31,7 @@
-
+
From 079daef3aa558a1eb3a12f5b599c222f41077c93 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 01:52:39 -0400
Subject: [PATCH 077/147] Update workflow OSes
---
.github/workflows/ci.yml | 24 +++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 878d9ecd1..cf961279d 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -12,7 +12,7 @@ env:
jobs:
build:
name: Build
- runs-on: ubuntu-20.04
+ runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3.5.0
@@ -36,10 +36,10 @@ jobs:
strategy:
matrix:
arch: [ amd64 ]
- os: [ windows-2019, macos-10.15 ]
+ os: [ windows-2019, macos-11 ]
tfm: [ net472, net6.0, net7.0 ]
exclude:
- - os: macos-10.15
+ - os: macos-11
tfm: net472
fail-fast: false
steps:
@@ -57,24 +57,18 @@ jobs:
run: dotnet test LibGit2Sharp.sln --configuration Release --framework ${{ matrix.tfm }} --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
test-linux:
name: Test / ${{ matrix.distro }} / ${{ matrix.arch }} / ${{ matrix.tfm }}
- runs-on: ubuntu-20.04
+ runs-on: ubuntu-22.04
strategy:
matrix:
arch: [ amd64 ]
# arch: [ amd64, arm64 ]
- distro: [ alpine.3.12, alpine.3.13, alpine.3.14, centos.7, centos.8, debian.9, debian.10, debian.11, fedora.33, ubuntu.18.04, ubuntu.20.04 ]
+ distro: [ alpine.3.13, alpine.3.14, alpine.3.15, alpine.3.16, alpine.3.17, centos.7, centos.stream.8, debian.10, debian.11, fedora.36, ubuntu.18.04, ubuntu.20.04, ubuntu.22.04 ]
sdk: [ '6.0', '7.0' ]
exclude:
- - arch: arm64
- distro: alpine.3.12
- - arch: arm64
- distro: alpine.3.13
- sdk: '3.1'
- - arch: arm64
- distro: alpine.3.14
- sdk: '3.1'
- - arch: arm64
- distro: centos.7
+ - distro: alpine.3.13
+ sdk: '7.0'
+ - distro: alpine.3.14
+ sdk: '7.0'
include:
- sdk: '6.0'
tfm: net6.0
From f1789346c9856f4d93718f605d62d85576a7af5e Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 12:42:43 -0400
Subject: [PATCH 078/147] Remove netstandard2.0 and add net472
---
LibGit2Sharp/Core/NativeMethods.cs | 2 +-
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index f5d45f3cf..e20d755ba 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -66,7 +66,7 @@ private static string GetGlobalSettingsNativeLibraryPath()
return Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension());
}
-#if NETSTANDARD
+#if NETFRAMEWORK
private static bool TryUseNativeLibrary() => false;
#else
private static bool TryUseNativeLibrary()
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 597f37e31..0b88a3af5 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -1,7 +1,7 @@
- netstandard2.0;net6.0
+ net472;net6.0
true
LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET
LibGit2Sharp contributors
From 48460d087d6622159f929f9aa7476d182ca7078b Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 12:46:16 -0400
Subject: [PATCH 079/147] Fix Assembly CodeBase warning
---
LibGit2Sharp/GlobalSettings.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs
index f8db7401a..31cba0965 100644
--- a/LibGit2Sharp/GlobalSettings.cs
+++ b/LibGit2Sharp/GlobalSettings.cs
@@ -20,7 +20,7 @@ public static class GlobalSettings
private static string nativeLibraryPath;
private static bool nativeLibraryPathLocked;
- private static string nativeLibraryDefaultPath;
+ private static readonly string nativeLibraryDefaultPath = null;
static GlobalSettings()
{
@@ -29,19 +29,18 @@ static GlobalSettings()
nativeLibraryPathAllowed = netFX || netCore;
+#if NETFRAMEWORK
if (netFX)
{
// For .NET Framework apps the dependencies are deployed to lib/win32/{architecture} directory
nativeLibraryDefaultPath = Path.Combine(GetExecutingAssemblyDirectory(), "lib", "win32", Platform.ProcessorArchitecture);
}
- else
- {
- nativeLibraryDefaultPath = null;
- }
+#endif
registeredFilters = new Dictionary();
}
+#if NETFRAMEWORK
private static string GetExecutingAssemblyDirectory()
{
// Assembly.CodeBase is not actually a correctly formatted
@@ -66,6 +65,7 @@ private static string GetExecutingAssemblyDirectory()
managedPath = Path.GetDirectoryName(managedPath);
return managedPath;
}
+#endif
///
/// Returns information related to the current LibGit2Sharp
From c157b6a5a72ae64da5856fa5d24f5b7847d7793d Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 13:15:21 -0400
Subject: [PATCH 080/147] Update RemoteRedirectMode to match
git_remote_redirect_t
---
LibGit2Sharp/Core/GitFetchOptions.cs | 2 +-
LibGit2Sharp/Core/GitPushOptions.cs | 2 +-
LibGit2Sharp/RemoteRedirectMode.cs | 8 ++++----
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/LibGit2Sharp/Core/GitFetchOptions.cs b/LibGit2Sharp/Core/GitFetchOptions.cs
index bdf8aa585..d82e2f219 100644
--- a/LibGit2Sharp/Core/GitFetchOptions.cs
+++ b/LibGit2Sharp/Core/GitFetchOptions.cs
@@ -11,7 +11,7 @@ internal class GitFetchOptions
public bool UpdateFetchHead = true;
public TagFetchMode download_tags;
public GitProxyOptions ProxyOptions;
- public RemoteRedirectMode FollowRedirects = RemoteRedirectMode.Auto;
+ public RemoteRedirectMode FollowRedirects = RemoteRedirectMode.Initial;
public GitStrArrayManaged CustomHeaders;
}
}
diff --git a/LibGit2Sharp/Core/GitPushOptions.cs b/LibGit2Sharp/Core/GitPushOptions.cs
index 8c98ce9cc..ce1a58f7c 100644
--- a/LibGit2Sharp/Core/GitPushOptions.cs
+++ b/LibGit2Sharp/Core/GitPushOptions.cs
@@ -9,7 +9,7 @@ internal class GitPushOptions
public int PackbuilderDegreeOfParallelism;
public GitRemoteCallbacks RemoteCallbacks;
public GitProxyOptions ProxyOptions;
- public RemoteRedirectMode FollowRedirects = RemoteRedirectMode.Auto;
+ public RemoteRedirectMode FollowRedirects = RemoteRedirectMode.Initial;
public GitStrArrayManaged CustomHeaders;
}
}
diff --git a/LibGit2Sharp/RemoteRedirectMode.cs b/LibGit2Sharp/RemoteRedirectMode.cs
index 08866e68a..029208857 100644
--- a/LibGit2Sharp/RemoteRedirectMode.cs
+++ b/LibGit2Sharp/RemoteRedirectMode.cs
@@ -1,7 +1,7 @@
namespace LibGit2Sharp
{
///
- /// Remote redirection settings; wehther redirects to another
+ /// Remote redirection settings; whether redirects to another
/// host are permitted. By default, git will follow a redirect
/// on the initial request (`/info/refs`) but not subsequent
/// requests.
@@ -12,17 +12,17 @@ public enum RemoteRedirectMode
/// Do not follow any off-site redirects at any stage of
/// the fetch or push.
///
- None = 0, // GIT_REMOTE_REDIRECT_NONE
+ None = 1 << 0, // GIT_REMOTE_REDIRECT_NONE
///
/// Allow off-site redirects only upon the initial
/// request. This is the default.
///
- Auto, // GIT_REMOTE_REDIRECT_INITIAL
+ Initial = 1 << 1, // GIT_REMOTE_REDIRECT_INITIAL
///
/// Allow redirects at any stage in the fetch or push.
///
- All // GIT_REMOTE_REDIRECT_ALL
+ All = 1 << 2 // GIT_REMOTE_REDIRECT_ALL
}
}
From a7ded296a01358fda726eb8ac27039cc5d2f0433 Mon Sep 17 00:00:00 2001
From: Mark Adamson <3154635+mungojam@users.noreply.github.com>
Date: Sat, 8 Apr 2023 18:40:50 +0100
Subject: [PATCH 081/147] Add NuGet package badge (#1980)
---
README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 8ed3fb4d2..3aafdceb1 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
# LibGit2Sharp
-[](https://github.com/libgit2/libgit2sharp/actions/workflows/ci.yml)
+[](https://github.com/libgit2/libgit2sharp/actions/workflows/ci.yml)
+[](https://www.nuget.org/packages/LibGit2Sharp/)
**LibGit2Sharp brings all the might and speed of [libgit2](http://libgit2.github.com/), a native Git implementation, to the managed world of .NET**
From 1d64999130c392e553b827246f6963c779bf668f Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 21:33:05 -0400
Subject: [PATCH 082/147] Switch to MinVer for versioning
---
LibGit2Sharp.sln | 5 ++--
LibGit2Sharp/LibGit2Sharp.csproj | 8 +++---
LibGit2Sharp/Version.cs | 12 +++++++--
Targets/CodeGenerator.targets | 37 ++++++++++-----------------
Targets/GenerateNativeDllName.targets | 5 +---
version.json | 13 ----------
6 files changed, 31 insertions(+), 49 deletions(-)
delete mode 100644 version.json
diff --git a/LibGit2Sharp.sln b/LibGit2Sharp.sln
index a81b0ce37..e99eec26f 100644
--- a/LibGit2Sharp.sln
+++ b/LibGit2Sharp.sln
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.28803.202
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibGit2Sharp", "LibGit2Sharp\LibGit2Sharp.csproj", "{EE6ED99F-CB12-4683-B055-D28FC7357A34}"
EndProject
@@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
Targets\GenerateNativeDllName.targets = Targets\GenerateNativeDllName.targets
nuget.config = nuget.config
- version.json = version.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeLibraryLoadTestApp.x86", "NativeLibraryLoadTestApp\x86\NativeLibraryLoadTestApp.x86.csproj", "{86453D2C-4953-4DF4-B12A-ADE579608BAA}"
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 0b88a3af5..6aa70519c 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -17,6 +17,8 @@
square-logo.png
App_Readme/LICENSE.md
true
+ preview.0
+ libgit2-$(libgit2_hash.Substring(0,7))
@@ -32,15 +34,15 @@
-
+
-
+
- https://github.com/libgit2/libgit2sharp/blob/$(GitCommitIdShort)/CHANGES.md#libgit2sharp-changes
+ https://github.com/libgit2/libgit2sharp/blob/$(SourceRevisionId)/CHANGES.md
diff --git a/LibGit2Sharp/Version.cs b/LibGit2Sharp/Version.cs
index 3795382a3..2c21ccad2 100644
--- a/LibGit2Sharp/Version.cs
+++ b/LibGit2Sharp/Version.cs
@@ -1,4 +1,5 @@
using System.Globalization;
+using System.Reflection;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -22,7 +23,14 @@ internal static Version Build()
///
/// Returns version of the LibGit2Sharp library.
///
- public virtual string InformationalVersion => ThisAssembly.AssemblyInformationalVersion;
+ public virtual string InformationalVersion
+ {
+ get
+ {
+ var attribute = Assembly.GetExecutingAssembly().GetCustomAttribute();
+ return attribute.InformationalVersion;
+ }
+ }
///
/// Returns all the optional features that were compiled into
@@ -55,7 +63,7 @@ private string RetrieveAbbrevShaFrom(string sha)
///
///
/// The format of the version number is as follows:
- /// Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features)
+ /// Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features)
///
///
public override string ToString()
diff --git a/Targets/CodeGenerator.targets b/Targets/CodeGenerator.targets
index 249cd4f38..16eb8f05b 100644
--- a/Targets/CodeGenerator.targets
+++ b/Targets/CodeGenerator.targets
@@ -1,22 +1,24 @@
-
- $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
-
-
+ $(IntermediateOutputPath)SourceRevisionId.txt
$(IntermediateOutputPath)UniqueIdentifier.g.cs
$(IntermediateOutputPath)AssemblyCommitIds.g.cs
+
+
+
+
+
+
-
-
+
- $([System.Guid]::NewGuid())
- $(GitCommitId)
+ $(SourceRevisionId)
+ $([System.Guid]::NewGuid())
namespace LibGit2Sharp.Core
{
@@ -34,24 +36,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
+
- unknown
- $(GitCommitId)
+ $(SourceRevisionId)
+ unknown
namespace LibGit2Sharp
{
@@ -70,7 +60,6 @@
-
diff --git a/Targets/GenerateNativeDllName.targets b/Targets/GenerateNativeDllName.targets
index 244b707b4..c74dcd31e 100644
--- a/Targets/GenerateNativeDllName.targets
+++ b/Targets/GenerateNativeDllName.targets
@@ -1,9 +1,5 @@
-
- $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
-
-
$(IntermediateOutputPath)NativeDllName.g.cs
@@ -30,4 +26,5 @@
+
diff --git a/version.json b/version.json
deleted file mode 100644
index b0cb8c411..000000000
--- a/version.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
- "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
- "version": "0.27.0-preview.{height}",
- "publicReleaseRefSpec": [
- "^refs/heads/master$", // we release out of master
- "^refs/heads/maint/v\\d+(?:\\.\\d+)?$" // and maint/vNN branches
- ],
- "cloudBuild": {
- "buildNumber": {
- "enabled": true
- }
- }
-}
From 2da1e0eab8bd210dca2a950d90809ff103d59980 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 8 Apr 2023 22:09:42 -0400
Subject: [PATCH 083/147] Update version test
---
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index e067fd192..cd237663e 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -23,25 +23,25 @@ public void CanGetMinimumCompiledInFeatures()
public void CanRetrieveValidVersionString()
{
// Version string format is:
- // Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features)
+ // Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features)
// Example output:
- // "0.25.0-preview.52+871d13a67f.libgit2-15e1193 (x86 - Threads, Https)"
+ // "0.27.0-preview.0.1896+libgit2-c058aa8.c1ac3ed74487da5fac24cf1e48dc8ea71e917b75 (x64 - Threads, Https, NSec)"
string versionInfo = GlobalSettings.Version.ToString();
// The GlobalSettings.Version returned string should contain :
// version: '0.25.0[-previewTag]' LibGit2Sharp version number.
- // git2SharpHash: '871d13a67f' LibGit2Sharp hash.
+ // git2SharpHash: 'c1ac3ed74487da5fac24cf1e48dc8ea71e917b75' LibGit2Sharp hash.
// arch: 'x86' or 'x64' libgit2 target.
// git2Features: 'Threads, Ssh' libgit2 features compiled with.
- string regex = @"^(?\d+\.\d+\.\d+(-[\w\-\.]+)?\+((?[a-f0-9]{10})\.)?libgit2-[a-f0-9]{7}) \((?\w+) - (?(?:\w*(?:, )*\w+)*)\)$";
+ string regex = @"^(?\d+\.\d+\.\d+(-[\w\-\.]+)?)\+libgit2-[a-f0-9]{7}\.((?[a-f0-9]{40}))? \((?\w+) - (?(?:\w*(?:, )*\w+)*)\)$";
Assert.NotNull(versionInfo);
Match regexResult = Regex.Match(versionInfo, regex);
Assert.True(regexResult.Success, "The following version string format is enforced:" +
- "Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features). " +
+ "Major.Minor.Patch[-previewTag]+libgit2-{libgit2_abbrev_hash}.{LibGit2Sharp_hash} (arch - features). " +
"But found \"" + versionInfo + "\" instead.");
}
From 8e1fe56a427ad30129f2e1fbe7fd29d044c714bd Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 9 Apr 2023 02:10:38 -0400
Subject: [PATCH 084/147] Mark repo safe to fix MinVer warning
---
.github/workflows/ci.yml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index cf961279d..f44285812 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -85,5 +85,7 @@ jobs:
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- name: Run ${{ matrix.tfm }} tests
run: |
+ git_command="git config --global --add safe.directory /app"
test_command="dotnet test LibGit2Sharp.sln --configuration Release -p:TargetFrameworks=${{ matrix.tfm }} --logger "GitHubActions" -p:ExtraDefine=LEAKS_IDENTIFYING"
- docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$test_command"
+ 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"
+
From 9552731c51aff4e0a76dd6c2ac87ba90cf0c0aff Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 10 Apr 2023 20:19:09 -0400
Subject: [PATCH 085/147] Add v0.27 changes
---
CHANGES.md | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 78bd537f6..c902a8640 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,14 +1,27 @@
# LibGit2Sharp Changes
-**LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .Net and Mono.**
-
- - Source code:
- - NuGet package:
- - Issue tracker:
- - @libgit2sharp:
- - CI servers:
- - Windows (x86/amd64):
- - Linux/Mac OS X:
+## v0.27 - ([diff](https://github.com/libgit2/libgit2sharp/compare/v0.26..0.27.0))
+
+### Changes
+- LibGit2Sharp now targets .NET Framework 4.7.2 and .NET 6.
+- This release includes [libgit2 v1.6.3](https://github.com/libgit2/libgit2/releases/tag/v1.6.3).
+- Changes to the native binaries let LibGit2Sharp work on all [.NET 6 supported OS versions and architectures](https://github.com/dotnet/core/blob/main/release-notes/6.0/supported-os.md).
+- `GlobalSetings.NativeLibraryPath` used to automatically append architecture to the path when running on .NET Framework. This behavior has been removed to make it consistent. [#1918](https://github.com/libgit2/libgit2sharp/pull/1918)
+
+### Additions
+- Add support for adding and clearing multi-valued configuration [#1720](https://github.com/libgit2/libgit2sharp/pull/1720)
+- added lines and deleted lines in content changes [#1790](https://github.com/libgit2/libgit2sharp/pull/1790)
+- Set / get supported extensions [#1908](https://github.com/libgit2/libgit2sharp/pull/1908)
+- Simplify dealing with missing git objects [#1909](https://github.com/libgit2/libgit2sharp/pull/1909)
+- Throw NotFoundException if trees are missing when computing diff [#1936](https://github.com/libgit2/libgit2sharp/pull/1936)
+
+### Fixes
+- Adjust GitStatusOptions to match structure of native libgit2 [#1884](https://github.com/libgit2/libgit2sharp/pull/1884)
+- Update git_worktree_add_options struct to include ref pointer [#1890](https://github.com/libgit2/libgit2sharp/pull/1890)
+- Fix git_remote_connect not throwing on non-zero result [#1913](https://github.com/libgit2/libgit2sharp/pull/1913)
+- Fix incorrect information in exceptions [#1919](https://github.com/libgit2/libgit2sharp/pull/1919)
+- Checkout branch looks to remote tracking branches as fallback [#1820](https://github.com/libgit2/libgit2sharp/pull/1820)
+- Fixed calling into native libgit2 on osx-arm64 [#1955](https://github.com/libgit2/libgit2sharp/pull/1955)
## v0.26 - ([diff](https://github.com/libgit2/libgit2sharp/compare/v0.25..v0.26))
From 10cd32c43a73995e6c61e091868d9722e8060ff3 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 10 Apr 2023 21:04:31 -0400
Subject: [PATCH 086/147] Add PackageReadmeFile property
---
LibGit2Sharp/LibGit2Sharp.csproj | 1 +
1 file changed, 1 insertion(+)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 6aa70519c..db0d2b29f 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -15,6 +15,7 @@
true
..\libgit2sharp.snk
square-logo.png
+ App_Readme/README.md
App_Readme/LICENSE.md
true
preview.0
From 4dc402a36e795b956475fbde41d50555dfdde58b Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Tue, 11 Apr 2023 13:07:20 -0400
Subject: [PATCH 087/147] Fix AssemblyVersion and PackageVersion
---
LibGit2Sharp/LibGit2Sharp.csproj | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index db0d2b29f..abab84c8a 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -47,4 +47,12 @@
+
+
+ $(MinVerMajor).$(MinVerMinor).0.0
+ $(MinVerMajor).$(MinVerMinor).$(MinVerPatch)
+ $(PackageVersion)-$(MinVerPreRelease)
+
+
+
From 82c190bb997b5e1a003d47b51f662150332697ae Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Tue, 11 Apr 2023 13:21:18 -0400
Subject: [PATCH 088/147] Add fix to Changes doc
---
CHANGES.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CHANGES.md b/CHANGES.md
index c902a8640..6341b4438 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,10 @@
# LibGit2Sharp Changes
+## v0.27.1 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.27.0..0.27.1))
+
+### Fixes
+ - AssemblyVersion of v0.27.0 is `0.0.0.0`, which is lower than the AssemblyVersion of the v0.26.x releases. [#2030](https://github.com/libgit2/libgit2sharp/pull/2030)
+
## v0.27 - ([diff](https://github.com/libgit2/libgit2sharp/compare/v0.26..0.27.0))
### Changes
From 2419633cf4673b6a7d36af9cf47f25a84587acdd Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Wed, 12 Apr 2023 12:45:06 -0400
Subject: [PATCH 089/147] Update LibGit2Sharp.NativeBinaries to 2.0.320
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index abab84c8a..f690c9107 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -33,7 +33,7 @@
-
+
From ce3be35fb51968e007b6a9f3478bb5078ba3c4c3 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Wed, 12 Apr 2023 15:05:26 -0400
Subject: [PATCH 090/147] Update CHANGES doc
---
CHANGES.md | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/CHANGES.md b/CHANGES.md
index 6341b4438..a3a74c0d5 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,9 +1,17 @@
# LibGit2Sharp Changes
+## v0.27.2 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.27.1..0.27.2))
+
+### Changes
+- This release includes [libgit2 v1.6.4](https://github.com/libgit2/libgit2/releases/tag/v1.6.4).
+
+### Fixes
+- Can't access GIT config (Repository.Config) since v0.27.0 [#2031](https://github.com/libgit2/libgit2sharp/issues/2031)
+
## v0.27.1 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.27.0..0.27.1))
### Fixes
- - AssemblyVersion of v0.27.0 is `0.0.0.0`, which is lower than the AssemblyVersion of the v0.26.x releases. [#2030](https://github.com/libgit2/libgit2sharp/pull/2030)
+- AssemblyVersion of v0.27.0 is `0.0.0.0`, which is lower than the AssemblyVersion of the v0.26.x releases. [#2030](https://github.com/libgit2/libgit2sharp/pull/2030)
## v0.27 - ([diff](https://github.com/libgit2/libgit2sharp/compare/v0.26..0.27.0))
From 714a4262374c8da4964debb7a049ef7a9d88b823 Mon Sep 17 00:00:00 2001
From: James La Novara-Gsell
Date: Thu, 2 Nov 2023 23:04:14 -0400
Subject: [PATCH 091/147] feat: Add CustomHeaders to PushOptions
Wires up CustomHeaders in PushOptions in the same vain as FetchOptions.
---
LibGit2Sharp.Tests/PushFixture.cs | 27 ++++++++++++++++
LibGit2Sharp/Core/GitPushOptionsWrapper.cs | 36 ++++++++++++++++++++++
LibGit2Sharp/Network.cs | 21 +++++++++----
LibGit2Sharp/PushOptions.cs | 20 ++++++++++++
4 files changed, 98 insertions(+), 6 deletions(-)
create mode 100644 LibGit2Sharp/Core/GitPushOptionsWrapper.cs
diff --git a/LibGit2Sharp.Tests/PushFixture.cs b/LibGit2Sharp.Tests/PushFixture.cs
index d8cf2befe..fc6c0c42d 100644
--- a/LibGit2Sharp.Tests/PushFixture.cs
+++ b/LibGit2Sharp.Tests/PushFixture.cs
@@ -196,6 +196,33 @@ public void CanForcePush()
}
}
+ [Fact]
+ public void CanPushWithCustomHeaders()
+ {
+ const string knownHeader = "X-Hello: mygit-201";
+ var options = new PushOptions { CustomHeaders = new string[] { knownHeader } };
+ AssertPush(repo =>
+ repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options));
+ }
+
+ [Fact]
+ public void CannotPushWithForbiddenCustomHeaders()
+ {
+ const string knownHeader = "User-Agent: mygit-201";
+ var options = new PushOptions { CustomHeaders = new string[] { knownHeader } };
+ Assert.Throws(
+ () => AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options)));
+ }
+
+ [Fact]
+ public void CannotPushWithMalformedCustomHeaders()
+ {
+ const string knownHeader = "Hello world";
+ var options = new PushOptions { CustomHeaders = new string[] { knownHeader } };
+ Assert.Throws(
+ () => AssertPush(repo => repo.Network.Push(repo.Network.Remotes["origin"], "HEAD", @"refs/heads/master", options)));
+ }
+
private static void AssertRemoteHeadTipEquals(IRepository localRepo, string sha)
{
var remoteReferences = localRepo.Network.ListReferences(localRepo.Network.Remotes.Single());
diff --git a/LibGit2Sharp/Core/GitPushOptionsWrapper.cs b/LibGit2Sharp/Core/GitPushOptionsWrapper.cs
new file mode 100644
index 000000000..ffac5a220
--- /dev/null
+++ b/LibGit2Sharp/Core/GitPushOptionsWrapper.cs
@@ -0,0 +1,36 @@
+using System;
+
+namespace LibGit2Sharp.Core
+{
+ ///
+ /// Git push options wrapper. Disposable wrapper for .
+ ///
+ internal class GitPushOptionsWrapper : IDisposable
+ {
+ public GitPushOptionsWrapper() : this(new GitPushOptions()) { }
+
+ public GitPushOptionsWrapper(GitPushOptions pushOptions)
+ {
+ this.Options = pushOptions;
+ }
+
+ public GitPushOptions Options { get; private set; }
+
+ #region IDisposable
+ private bool disposedValue = false; // To detect redundant calls
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposedValue)
+ return;
+
+ this.Options.CustomHeaders.Dispose();
+ disposedValue = true;
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+ #endregion
+ }
+}
diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs
index d5f032058..825f3c886 100644
--- a/LibGit2Sharp/Network.cs
+++ b/LibGit2Sharp/Network.cs
@@ -365,18 +365,27 @@ public virtual void Push(Remote remote, IEnumerable pushRefSpecs, PushOp
// Load the remote.
using (RemoteHandle remoteHandle = Proxy.git_remote_lookup(repository.Handle, remote.Name, true))
+
+ // Create a git options wrapper so managed strings are disposed.
+ using (var pushOptionsWrapper = new GitPushOptionsWrapper())
{
var callbacks = new RemoteCallbacks(pushOptions);
GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();
+ var gitPushOptions = pushOptionsWrapper.Options;
+ gitPushOptions.PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism;
+ gitPushOptions.RemoteCallbacks = gitCallbacks;
+ gitPushOptions.ProxyOptions = new GitProxyOptions { Version = 1 };
+
+ // If there are custom headers, create a managed string array.
+ if (pushOptions.CustomHeaders != null && pushOptions.CustomHeaders.Length > 0)
+ {
+ gitPushOptions.CustomHeaders = GitStrArrayManaged.BuildFrom(pushOptions.CustomHeaders);
+ }
+
Proxy.git_remote_push(remoteHandle,
pushRefSpecs,
- new GitPushOptions()
- {
- PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism,
- RemoteCallbacks = gitCallbacks,
- ProxyOptions = new GitProxyOptions { Version = 1 },
- });
+ gitPushOptions);
}
}
diff --git a/LibGit2Sharp/PushOptions.cs b/LibGit2Sharp/PushOptions.cs
index 99c65dd8b..f7d37eba9 100644
--- a/LibGit2Sharp/PushOptions.cs
+++ b/LibGit2Sharp/PushOptions.cs
@@ -51,5 +51,25 @@ public sealed class PushOptions
/// information about what updates will be performed.
///
public PrePushHandler OnNegotiationCompletedBeforePush { get; set; }
+
+ ///
+ /// Get/Set the custom headers.
+ ///
+ /// This allows you to set custom headers (e.g. X-Forwarded-For,
+ /// X-Request-Id, etc),
+ ///
+ ///
+ ///
+ /// Libgit2 sets some headers for HTTP requests (User-Agent, Host,
+ /// Accept, Content-Type, Transfer-Encoding, Content-Length, Accept) that
+ /// cannot be overriden.
+ ///
+ ///
+ /// var pushOptions - new PushOptions() {
+ /// CustomHeaders = new String[] {"X-Request-Id: 12345"}
+ /// };
+ ///
+ /// The custom headers string array
+ public string[] CustomHeaders { get; set; }
}
}
From feb83448abaec82446ba6b6e37986890f0fcbd59 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 4 Nov 2023 16:37:00 -0400
Subject: [PATCH 092/147] Update MinVer
---
LibGit2Sharp/LibGit2Sharp.csproj | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index f690c9107..b80d75cd0 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -35,7 +35,7 @@
-
+
@@ -50,8 +50,6 @@
$(MinVerMajor).$(MinVerMinor).0.0
- $(MinVerMajor).$(MinVerMinor).$(MinVerPatch)
- $(PackageVersion)-$(MinVerPreRelease)
From 1c409f9dc5ad0a06d210c0a3f693e021875645d0 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 4 Nov 2023 16:40:17 -0400
Subject: [PATCH 093/147] Update CHANGES.md for v0.28
---
CHANGES.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CHANGES.md b/CHANGES.md
index a3a74c0d5..0cb2c978b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,10 @@
# LibGit2Sharp Changes
+## v0.28
+
+### Additions
+- Add CustomHeaders to PushOptions [#2052](https://github.com/libgit2/libgit2sharp/pull/2052)
+
## v0.27.2 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.27.1..0.27.2))
### Changes
From 7ac90abbe9426cba7e2ad634cf740cfddc52eba1 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 26 Nov 2023 21:09:16 -0500
Subject: [PATCH 094/147] Update LibGit2Sharp.NativeBinaries to 2.0.321
libgit2 v1.7.1
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index b80d75cd0..a12496899 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -33,7 +33,7 @@
-
+
From cd6936506ca7808c2fab7454fe5df95c99188d2d Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 26 Nov 2023 21:12:14 -0500
Subject: [PATCH 095/147] Update GitFetchOptions to include new Depth value
---
LibGit2Sharp/Core/GitFetchOptions.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/LibGit2Sharp/Core/GitFetchOptions.cs b/LibGit2Sharp/Core/GitFetchOptions.cs
index d82e2f219..26f4c8c7e 100644
--- a/LibGit2Sharp/Core/GitFetchOptions.cs
+++ b/LibGit2Sharp/Core/GitFetchOptions.cs
@@ -11,6 +11,7 @@ internal class GitFetchOptions
public bool UpdateFetchHead = true;
public TagFetchMode download_tags;
public GitProxyOptions ProxyOptions;
+ public int Depth = 0; // GIT_FETCH_DEPTH_FULL
public RemoteRedirectMode FollowRedirects = RemoteRedirectMode.Initial;
public GitStrArrayManaged CustomHeaders;
}
From 143e83f9b4c88f3f535db4a827ac96f9e59182c6 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 26 Nov 2023 21:14:34 -0500
Subject: [PATCH 096/147] Remove CentOS 7 from test matrix
---
.github/workflows/ci.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f44285812..5214b064f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -62,7 +62,7 @@ jobs:
matrix:
arch: [ amd64 ]
# arch: [ amd64, arm64 ]
- distro: [ alpine.3.13, alpine.3.14, alpine.3.15, alpine.3.16, alpine.3.17, centos.7, centos.stream.8, debian.10, debian.11, fedora.36, ubuntu.18.04, ubuntu.20.04, ubuntu.22.04 ]
+ 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' ]
exclude:
- distro: alpine.3.13
From 42e98263699776009aeb70cf45673a60a4847dfa Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 26 Nov 2023 21:15:47 -0500
Subject: [PATCH 097/147] Update test to match new sort order
---
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index cd237663e..dd7aef1e1 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -100,7 +100,7 @@ public void SetExtensions()
// Enable two new extensions (it will reset the configuration and "noop" will be enabled)
GlobalSettings.SetExtensions("partialclone", "newext");
extensions = GlobalSettings.GetExtensions();
- Assert.Equal(new[] { "noop", "objectformat", "partialclone", "newext" }, extensions);
+ Assert.Equal(new[] { "newext", "noop", "objectformat", "partialclone" }, extensions);
}
}
}
From e13df56af676eb4bf89dc864d20eabeeca4fe2c3 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 25 Nov 2023 02:05:00 -0500
Subject: [PATCH 098/147] Update GitProxyOptions
---
LibGit2Sharp/Core/GitProxyOptions.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/LibGit2Sharp/Core/GitProxyOptions.cs b/LibGit2Sharp/Core/GitProxyOptions.cs
index b62b8e08f..85d4057ab 100644
--- a/LibGit2Sharp/Core/GitProxyOptions.cs
+++ b/LibGit2Sharp/Core/GitProxyOptions.cs
@@ -16,8 +16,8 @@ internal struct GitProxyOptions
public uint Version;
public GitProxyType Type;
public IntPtr Url;
- public IntPtr CredentialsCb;
- public IntPtr CertificateCheck;
- public IntPtr CbPayload;
+ public NativeMethods.git_cred_acquire_cb Credentials;
+ public NativeMethods.git_transport_certificate_check_cb CertificateCheck;
+ public IntPtr Payload;
}
}
From 75b443221c9238711912e2471565648a3193cdf8 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 25 Nov 2023 02:14:44 -0500
Subject: [PATCH 099/147] Add public proxy APIs
---
LibGit2Sharp/FetchOptionsBase.cs | 2 ++
LibGit2Sharp/ProxyOptions.cs | 15 +++++++++++++++
LibGit2Sharp/ProxyType.cs | 9 +++++++++
3 files changed, 26 insertions(+)
create mode 100644 LibGit2Sharp/ProxyOptions.cs
create mode 100644 LibGit2Sharp/ProxyType.cs
diff --git a/LibGit2Sharp/FetchOptionsBase.cs b/LibGit2Sharp/FetchOptionsBase.cs
index 751678cf9..652a06378 100644
--- a/LibGit2Sharp/FetchOptionsBase.cs
+++ b/LibGit2Sharp/FetchOptionsBase.cs
@@ -48,5 +48,7 @@ internal FetchOptionsBase()
/// Completed operating on the current repository.
///
public RepositoryOperationCompleted RepositoryOperationCompleted { get; set; }
+
+ public ProxyOptions ProxyOptions { get; set; }
}
}
diff --git a/LibGit2Sharp/ProxyOptions.cs b/LibGit2Sharp/ProxyOptions.cs
new file mode 100644
index 000000000..fa3669d95
--- /dev/null
+++ b/LibGit2Sharp/ProxyOptions.cs
@@ -0,0 +1,15 @@
+using LibGit2Sharp.Handlers;
+
+namespace LibGit2Sharp
+{
+ public class ProxyOptions
+ {
+ public ProxyType ProxyType { get; set; }
+
+ public string Url { get; set; }
+
+ public CredentialsHandler CredentialsProvider { get; set; }
+
+ public CertificateCheckHandler CertificateCheck { get; set; }
+ }
+}
diff --git a/LibGit2Sharp/ProxyType.cs b/LibGit2Sharp/ProxyType.cs
new file mode 100644
index 000000000..e78606a72
--- /dev/null
+++ b/LibGit2Sharp/ProxyType.cs
@@ -0,0 +1,9 @@
+namespace LibGit2Sharp
+{
+ public enum ProxyType
+ {
+ None,
+ Auto,
+ Specified
+ }
+}
From db161ee8baad1a8969c1e6a150ab5618e84521c6 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 25 Nov 2023 19:16:49 -0500
Subject: [PATCH 100/147] No reason to derive from FetchOptionsBase and have
FetchOptions property
---
LibGit2Sharp.Tests/CloneFixture.cs | 90 +++++++++++++++++-------------
LibGit2Sharp/CloneOptions.cs | 2 +-
2 files changed, 51 insertions(+), 41 deletions(-)
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs
index 1b26c1226..c1ff7bc74 100644
--- a/LibGit2Sharp.Tests/CloneFixture.cs
+++ b/LibGit2Sharp.Tests/CloneFixture.cs
@@ -151,10 +151,14 @@ public void CallsProgressCallbacks(string url)
Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
{
- OnTransferProgress = _ => { transferWasCalled = true; return true; },
- OnProgress = progress => { progressWasCalled = true; return true; },
- OnUpdateTips = (name, oldId, newId) => { updateTipsWasCalled = true; return true; },
+ FetchOptions =
+ {
+ OnTransferProgress = _ => { transferWasCalled = true; return true; },
+ OnProgress = progress => { progressWasCalled = true; return true; },
+ OnUpdateTips = (name, oldId, newId) => { updateTipsWasCalled = true; return true; }
+ },
OnCheckoutProgress = (a, b, c) => checkoutWasCalled = true
+
});
Assert.True(transferWasCalled);
@@ -174,7 +178,7 @@ public void CanCloneWithCredentials()
string clonedRepoPath = Repository.Clone(Constants.PrivateRepoUrl, scd.DirectoryPath,
new CloneOptions()
{
- CredentialsProvider = Constants.PrivateRepoCredentials
+ FetchOptions = { CredentialsProvider = Constants.PrivateRepoCredentials }
});
@@ -249,43 +253,46 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
var options = new CloneOptions
{
- CertificateCheck = (cert, valid, host) =>
+ FetchOptions =
{
- wasCalled = true;
-
- Assert.Equal(hostname, host);
- Assert.Equal(certType, cert.GetType());
-
- if (certType == typeof(CertificateX509))
+ CertificateCheck = (cert, valid, host) =>
{
- Assert.True(valid);
- var x509 = ((CertificateX509)cert).Certificate;
- // we get a string with the different fields instead of a structure, so...
- Assert.Contains("CN=github.com,", x509.Subject);
- checksHappy = true;
- return false;
- }
+ wasCalled = true;
+
+ Assert.Equal(hostname, host);
+ Assert.Equal(certType, cert.GetType());
+
+ if (certType == typeof(CertificateX509))
+ {
+ Assert.True(valid);
+ var x509 = ((CertificateX509)cert).Certificate;
+ // we get a string with the different fields instead of a structure, so...
+ Assert.Contains("CN=github.com,", x509.Subject);
+ checksHappy = true;
+ return false;
+ }
+
+ if (certType == typeof(CertificateSsh))
+ {
+ var hostkey = (CertificateSsh)cert;
+ Assert.True(hostkey.HasMD5);
+ /*
+ * Once you've connected and thus your ssh has stored the hostkey,
+ * you can get the hostkey for a host with
+ *
+ * ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
+ *
+ * though GitHub's hostkey won't change anytime soon.
+ */
+ Assert.Equal("1627aca576282d36631b564debdfa648",
+ BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
+ checksHappy = true;
+ return false;
+ }
- if (certType == typeof(CertificateSsh))
- {
- var hostkey = (CertificateSsh)cert;
- Assert.True(hostkey.HasMD5);
- /*
- * Once you've connected and thus your ssh has stored the hostkey,
- * you can get the hostkey for a host with
- *
- * ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
- *
- * though GitHub's hostkey won't change anytime soon.
- */
- Assert.Equal("1627aca576282d36631b564debdfa648",
- BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
- checksHappy = true;
return false;
}
-
- return false;
- },
+ }
};
Assert.Throws(() =>
@@ -432,9 +439,12 @@ public void CanRecursivelyCloneSubmodules()
{
RecurseSubmodules = true,
OnCheckoutProgress = checkoutProgressHandler,
- OnUpdateTips = remoteRefUpdated,
- RepositoryOperationStarting = repositoryOperationStarting,
- RepositoryOperationCompleted = repositoryOperationCompleted,
+ FetchOptions =
+ {
+ OnUpdateTips = remoteRefUpdated,
+ RepositoryOperationStarting = repositoryOperationStarting,
+ RepositoryOperationCompleted = repositoryOperationCompleted
+ }
};
string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
@@ -517,7 +527,7 @@ public void CanCancelRecursiveClone()
CloneOptions options = new CloneOptions()
{
RecurseSubmodules = true,
- RepositoryOperationStarting = repositoryOperationStarting,
+ FetchOptions = { RepositoryOperationStarting = repositoryOperationStarting }
};
Assert.Throws(() =>
diff --git a/LibGit2Sharp/CloneOptions.cs b/LibGit2Sharp/CloneOptions.cs
index f88ff58d7..05430085e 100644
--- a/LibGit2Sharp/CloneOptions.cs
+++ b/LibGit2Sharp/CloneOptions.cs
@@ -6,7 +6,7 @@ namespace LibGit2Sharp
///
/// Options to define clone behaviour
///
- public sealed class CloneOptions : FetchOptionsBase, IConvertableToGitCheckoutOpts
+ public sealed class CloneOptions : IConvertableToGitCheckoutOpts
{
///
/// Creates default for a non-bare clone
From 4de7c4f12bbc86b333a54f572fe2f2e8f116fce0 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 25 Nov 2023 19:18:23 -0500
Subject: [PATCH 101/147] Wire up proxy options
---
LibGit2Sharp/Commands/Fetch.cs | 3 +-
LibGit2Sharp/Core/GitFetchOptionsWrapper.cs | 9 +-
LibGit2Sharp/Core/GitProxyOptionsWrapper.cs | 32 +++++++
LibGit2Sharp/Core/GitPushOptionsWrapper.cs | 1 +
LibGit2Sharp/FetchOptionsBase.cs | 2 +-
LibGit2Sharp/LibGit2Sharp.csproj | 1 +
LibGit2Sharp/Network.cs | 67 +++++++++++----
LibGit2Sharp/ProxyOptions.cs | 92 ++++++++++++++++++++-
LibGit2Sharp/PushOptions.cs | 2 +
LibGit2Sharp/Repository.cs | 63 ++++++++------
LibGit2Sharp/SubmoduleCollection.cs | 2 +-
11 files changed, 222 insertions(+), 52 deletions(-)
create mode 100644 LibGit2Sharp/Core/GitProxyOptionsWrapper.cs
diff --git a/LibGit2Sharp/Commands/Fetch.cs b/LibGit2Sharp/Commands/Fetch.cs
index d61fca5a5..e531aac51 100644
--- a/LibGit2Sharp/Commands/Fetch.cs
+++ b/LibGit2Sharp/Commands/Fetch.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using LibGit2Sharp;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Handles;
@@ -75,7 +74,7 @@ public static void Fetch(Repository repository, string remote, IEnumerable
- /// Git fetch options wrapper. Disposable wrapper for GitFetchOptions
+ ///
+ /// Git fetch options wrapper. Disposable wrapper for GitFetchOptions
///
internal class GitFetchOptionsWrapper : IDisposable
{
@@ -11,7 +11,7 @@ public GitFetchOptionsWrapper() : this(new GitFetchOptions()) { }
public GitFetchOptionsWrapper(GitFetchOptions fetchOptions)
{
- this.Options = fetchOptions;
+ Options = fetchOptions;
}
public GitFetchOptions Options { get; private set; }
@@ -23,7 +23,8 @@ protected virtual void Dispose(bool disposing)
if (disposedValue)
return;
- this.Options.CustomHeaders.Dispose();
+ Options.CustomHeaders.Dispose();
+ EncodingMarshaler.Cleanup(Options.ProxyOptions.Url);
disposedValue = true;
}
diff --git a/LibGit2Sharp/Core/GitProxyOptionsWrapper.cs b/LibGit2Sharp/Core/GitProxyOptionsWrapper.cs
new file mode 100644
index 000000000..053213e96
--- /dev/null
+++ b/LibGit2Sharp/Core/GitProxyOptionsWrapper.cs
@@ -0,0 +1,32 @@
+using System;
+
+namespace LibGit2Sharp.Core
+{
+ internal class GitProxyOptionsWrapper : IDisposable
+ {
+ public GitProxyOptionsWrapper() : this(new GitProxyOptions()) { }
+
+ public GitProxyOptionsWrapper(GitProxyOptions fetchOptions)
+ {
+ Options = fetchOptions;
+ }
+
+ public GitProxyOptions Options { get; private set; }
+
+ private bool disposedValue = false;
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposedValue)
+ return;
+
+ EncodingMarshaler.Cleanup(Options.Url);
+ disposedValue = true;
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+ }
+}
diff --git a/LibGit2Sharp/Core/GitPushOptionsWrapper.cs b/LibGit2Sharp/Core/GitPushOptionsWrapper.cs
index ffac5a220..3ccffcf06 100644
--- a/LibGit2Sharp/Core/GitPushOptionsWrapper.cs
+++ b/LibGit2Sharp/Core/GitPushOptionsWrapper.cs
@@ -24,6 +24,7 @@ protected virtual void Dispose(bool disposing)
return;
this.Options.CustomHeaders.Dispose();
+ EncodingMarshaler.Cleanup(Options.ProxyOptions.Url);
disposedValue = true;
}
diff --git a/LibGit2Sharp/FetchOptionsBase.cs b/LibGit2Sharp/FetchOptionsBase.cs
index 652a06378..57de331d1 100644
--- a/LibGit2Sharp/FetchOptionsBase.cs
+++ b/LibGit2Sharp/FetchOptionsBase.cs
@@ -49,6 +49,6 @@ internal FetchOptionsBase()
///
public RepositoryOperationCompleted RepositoryOperationCompleted { get; set; }
- public ProxyOptions ProxyOptions { get; set; }
+ public ProxyOptions ProxyOptions { get; set; } = new();
}
}
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index a12496899..4d0876c4d 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -2,6 +2,7 @@
net472;net6.0
+ 10.0
true
LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET
LibGit2Sharp contributors
diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs
index 825f3c886..19070a344 100644
--- a/LibGit2Sharp/Network.cs
+++ b/LibGit2Sharp/Network.cs
@@ -52,7 +52,14 @@ public virtual IEnumerable ListReferences(Remote remote)
{
Ensure.ArgumentNotNull(remote, "remote");
- return ListReferencesInternal(remote.Url, null);
+ return ListReferencesInternal(remote.Url, null, new ProxyOptions());
+ }
+
+ public virtual IEnumerable ListReferences(Remote remote, ProxyOptions proxyOptions)
+ {
+ Ensure.ArgumentNotNull(remote, "remote");
+
+ return ListReferencesInternal(remote.Url, null, proxyOptions);
}
///
@@ -72,7 +79,15 @@ public virtual IEnumerable ListReferences(Remote remote, CredentialsH
Ensure.ArgumentNotNull(remote, "remote");
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
- return ListReferencesInternal(remote.Url, credentialsProvider);
+ return ListReferencesInternal(remote.Url, credentialsProvider, new ProxyOptions());
+ }
+
+ public virtual IEnumerable ListReferences(Remote remote, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
+ {
+ Ensure.ArgumentNotNull(remote, "remote");
+ Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
+
+ return ListReferencesInternal(remote.Url, credentialsProvider, proxyOptions);
}
///
@@ -90,7 +105,14 @@ public virtual IEnumerable ListReferences(string url)
{
Ensure.ArgumentNotNull(url, "url");
- return ListReferencesInternal(url, null);
+ return ListReferencesInternal(url, null, new ProxyOptions());
+ }
+
+ public virtual IEnumerable ListReferences(string url, ProxyOptions proxyOptions)
+ {
+ Ensure.ArgumentNotNull(url, "url");
+
+ return ListReferencesInternal(url, null, proxyOptions);
}
///
@@ -110,25 +132,36 @@ public virtual IEnumerable ListReferences(string url, CredentialsHand
Ensure.ArgumentNotNull(url, "url");
Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
- return ListReferencesInternal(url, credentialsProvider);
+ return ListReferencesInternal(url, credentialsProvider, new ProxyOptions());
}
- private IEnumerable ListReferencesInternal(string url, CredentialsHandler credentialsProvider)
+ public virtual IEnumerable ListReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
{
- using (RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url))
- {
- GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks { version = 1 };
- GitProxyOptions proxyOptions = new GitProxyOptions { Version = 1 };
+ Ensure.ArgumentNotNull(url, "url");
+ Ensure.ArgumentNotNull(credentialsProvider, "credentialsProvider");
- if (credentialsProvider != null)
- {
- var callbacks = new RemoteCallbacks(credentialsProvider);
- gitCallbacks = callbacks.GenerateCallbacks();
- }
+ return ListReferencesInternal(url, credentialsProvider, new ProxyOptions());
+ }
- Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch, ref gitCallbacks, ref proxyOptions);
- return Proxy.git_remote_ls(repository, remoteHandle);
+ private IEnumerable ListReferencesInternal(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
+ {
+ proxyOptions ??= new();
+
+ using RemoteHandle remoteHandle = BuildRemoteHandle(repository.Handle, url);
+ using var proxyOptionsWrapper = new GitProxyOptionsWrapper(proxyOptions.CreateGitProxyOptions());
+
+ GitRemoteCallbacks gitCallbacks = new GitRemoteCallbacks { version = 1 };
+
+ if (credentialsProvider != null)
+ {
+ var callbacks = new RemoteCallbacks(credentialsProvider);
+ gitCallbacks = callbacks.GenerateCallbacks();
}
+
+ var gitProxyOptions = proxyOptionsWrapper.Options;
+
+ Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch, ref gitCallbacks, ref gitProxyOptions);
+ return Proxy.git_remote_ls(repository, remoteHandle);
}
static RemoteHandle BuildRemoteHandle(RepositoryHandle repoHandle, string url)
@@ -375,7 +408,7 @@ public virtual void Push(Remote remote, IEnumerable pushRefSpecs, PushOp
var gitPushOptions = pushOptionsWrapper.Options;
gitPushOptions.PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism;
gitPushOptions.RemoteCallbacks = gitCallbacks;
- gitPushOptions.ProxyOptions = new GitProxyOptions { Version = 1 };
+ gitPushOptions.ProxyOptions = pushOptions.ProxyOptions.CreateGitProxyOptions();
// If there are custom headers, create a managed string array.
if (pushOptions.CustomHeaders != null && pushOptions.CustomHeaders.Length > 0)
diff --git a/LibGit2Sharp/ProxyOptions.cs b/LibGit2Sharp/ProxyOptions.cs
index fa3669d95..02b75bdd8 100644
--- a/LibGit2Sharp/ProxyOptions.cs
+++ b/LibGit2Sharp/ProxyOptions.cs
@@ -1,15 +1,103 @@
-using LibGit2Sharp.Handlers;
+using System;
+using LibGit2Sharp.Core;
+using LibGit2Sharp.Handlers;
namespace LibGit2Sharp
{
public class ProxyOptions
{
- public ProxyType ProxyType { get; set; }
+ public ProxyType ProxyType { get; set; } = ProxyType.Auto;
public string Url { get; set; }
public CredentialsHandler CredentialsProvider { get; set; }
public CertificateCheckHandler CertificateCheck { get; set; }
+
+ internal unsafe GitProxyOptions CreateGitProxyOptions()
+ {
+ var gitProxyOptions = new GitProxyOptions
+ {
+ Version = 1,
+ Type = (GitProxyType)ProxyType
+ };
+
+ if (Url is not null)
+ {
+ gitProxyOptions.Url = StrictUtf8Marshaler.FromManaged(Url);
+ }
+
+ if (CredentialsProvider is not null)
+ {
+ gitProxyOptions.Credentials = GitCredentialHandler;
+ }
+
+ if (CertificateCheck is not null)
+ {
+ gitProxyOptions.CertificateCheck = GitCertificateCheck;
+ }
+
+ return gitProxyOptions;
+ }
+
+ private int GitCredentialHandler(out IntPtr ptr, IntPtr cUrl, IntPtr usernameFromUrl, GitCredentialType credTypes, IntPtr payload)
+ {
+ string url = LaxUtf8Marshaler.FromNative(cUrl);
+ string username = LaxUtf8Marshaler.FromNative(usernameFromUrl);
+
+ SupportedCredentialTypes types = default(SupportedCredentialTypes);
+ if (credTypes.HasFlag(GitCredentialType.UserPassPlaintext))
+ {
+ types |= SupportedCredentialTypes.UsernamePassword;
+ }
+ if (credTypes.HasFlag(GitCredentialType.Default))
+ {
+ types |= SupportedCredentialTypes.Default;
+ }
+
+ ptr = IntPtr.Zero;
+ try
+ {
+ var cred = CredentialsProvider(url, username, types);
+ if (cred == null)
+ {
+ return (int)GitErrorCode.PassThrough;
+ }
+ return cred.GitCredentialHandler(out ptr);
+ }
+ catch (Exception exception)
+ {
+ Proxy.git_error_set_str(GitErrorCategory.Callback, exception);
+ return (int)GitErrorCode.Error;
+ }
+ }
+
+ private unsafe int GitCertificateCheck(git_certificate* certPtr, int valid, IntPtr cHostname, IntPtr payload)
+ {
+ string hostname = LaxUtf8Marshaler.FromNative(cHostname);
+ Certificate cert = null;
+
+ switch (certPtr->type)
+ {
+ case GitCertificateType.X509:
+ cert = new CertificateX509((git_certificate_x509*)certPtr);
+ break;
+ case GitCertificateType.Hostkey:
+ cert = new CertificateSsh((git_certificate_ssh*)certPtr);
+ break;
+ }
+
+ bool result = false;
+ try
+ {
+ result = CertificateCheck(cert, valid != 0, hostname);
+ }
+ catch (Exception exception)
+ {
+ Proxy.git_error_set_str(GitErrorCategory.Callback, exception);
+ }
+
+ return Proxy.ConvertResultToCancelFlag(result);
+ }
}
}
diff --git a/LibGit2Sharp/PushOptions.cs b/LibGit2Sharp/PushOptions.cs
index f7d37eba9..501e8d8d2 100644
--- a/LibGit2Sharp/PushOptions.cs
+++ b/LibGit2Sharp/PushOptions.cs
@@ -71,5 +71,7 @@ public sealed class PushOptions
///
/// The custom headers string array
public string[] CustomHeaders { get; set; }
+
+ public ProxyOptions ProxyOptions { get; set; } = new();
}
}
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 41aaecfbf..d7c759e8b 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -656,7 +656,12 @@ internal Commit LookupCommit(string committish)
/// The references in the remote repository.
public static IEnumerable ListRemoteReferences(string url)
{
- return ListRemoteReferences(url, null);
+ return ListRemoteReferences(url, null, new ProxyOptions());
+ }
+
+ public static IEnumerable ListRemoteReferences(string url, ProxyOptions proxyOptions)
+ {
+ return ListRemoteReferences(url, null, proxyOptions);
}
///
@@ -671,24 +676,32 @@ public static IEnumerable ListRemoteReferences(string url)
/// The used to connect to remote repository.
/// The references in the remote repository.
public static IEnumerable ListRemoteReferences(string url, CredentialsHandler credentialsProvider)
+ {
+ return ListRemoteReferences(url, credentialsProvider, new ProxyOptions());
+ }
+
+ public static IEnumerable ListRemoteReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(url, "url");
- using (RepositoryHandle repositoryHandle = Proxy.git_repository_new())
- using (RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repositoryHandle, url))
- {
- var gitCallbacks = new GitRemoteCallbacks { version = 1 };
- var proxyOptions = new GitProxyOptions { Version = 1 };
+ proxyOptions ??= new();
- if (credentialsProvider != null)
- {
- var callbacks = new RemoteCallbacks(credentialsProvider);
- gitCallbacks = callbacks.GenerateCallbacks();
- }
+ using RepositoryHandle repositoryHandle = Proxy.git_repository_new();
+ using RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repositoryHandle, url);
+ using var proxyOptionsWrapper = new GitProxyOptionsWrapper(proxyOptions.CreateGitProxyOptions());
+
+ var gitCallbacks = new GitRemoteCallbacks { version = 1 };
- Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch, ref gitCallbacks, ref proxyOptions);
- return Proxy.git_remote_ls(null, remoteHandle);
+ if (credentialsProvider != null)
+ {
+ var callbacks = new RemoteCallbacks(credentialsProvider);
+ gitCallbacks = callbacks.GenerateCallbacks();
}
+
+ var gitProxyOptions = proxyOptionsWrapper.Options;
+
+ Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch, ref gitCallbacks, ref gitProxyOptions);
+ return Proxy.git_remote_ls(null, remoteHandle);
}
///
@@ -754,7 +767,7 @@ public static string Clone(string sourceUrl, string workdirPath,
var context = new RepositoryOperationContext(Path.GetFullPath(workdirPath), sourceUrl);
// Notify caller that we are starting to work with the current repository.
- bool continueOperation = OnRepositoryOperationStarting(options.RepositoryOperationStarting,
+ bool continueOperation = OnRepositoryOperationStarting(options.FetchOptions.RepositoryOperationStarting,
context);
if (!continueOperation)
@@ -768,8 +781,8 @@ public static string Clone(string sourceUrl, string workdirPath,
var gitCheckoutOptions = checkoutOptionsWrapper.Options;
var gitFetchOptions = fetchOptionsWrapper.Options;
- gitFetchOptions.ProxyOptions = new GitProxyOptions { Version = 1 };
- gitFetchOptions.RemoteCallbacks = new RemoteCallbacks(options).GenerateCallbacks();
+ gitFetchOptions.ProxyOptions = options.FetchOptions.ProxyOptions.CreateGitProxyOptions();
+ gitFetchOptions.RemoteCallbacks = new RemoteCallbacks(options.FetchOptions).GenerateCallbacks();
if (options.FetchOptions != null && options.FetchOptions.CustomHeaders != null)
{
gitFetchOptions.CustomHeaders =
@@ -801,7 +814,7 @@ public static string Clone(string sourceUrl, string workdirPath,
}
// Notify caller that we are done with the current repository.
- OnRepositoryOperationCompleted(options.RepositoryOperationCompleted,
+ OnRepositoryOperationCompleted(options.FetchOptions.RepositoryOperationCompleted,
context);
// Recursively clone submodules if requested.
@@ -837,11 +850,11 @@ private static void RecursivelyCloneSubmodules(CloneOptions options, string repo
SubmoduleUpdateOptions updateOptions = new SubmoduleUpdateOptions()
{
Init = true,
- CredentialsProvider = options.CredentialsProvider,
+ CredentialsProvider = options.FetchOptions.CredentialsProvider,
OnCheckoutProgress = options.OnCheckoutProgress,
- OnProgress = options.OnProgress,
- OnTransferProgress = options.OnTransferProgress,
- OnUpdateTips = options.OnUpdateTips,
+ OnProgress = options.FetchOptions.OnProgress,
+ OnTransferProgress = options.FetchOptions.OnTransferProgress,
+ OnUpdateTips = options.FetchOptions.OnUpdateTips,
};
string parentRepoWorkDir = repo.Info.WorkingDirectory;
@@ -862,7 +875,7 @@ private static void RecursivelyCloneSubmodules(CloneOptions options, string repo
sm.Name,
recursionDepth);
- bool continueOperation = OnRepositoryOperationStarting(options.RepositoryOperationStarting,
+ bool continueOperation = OnRepositoryOperationStarting(options.FetchOptions.RepositoryOperationStarting,
context);
if (!continueOperation)
@@ -872,7 +885,7 @@ private static void RecursivelyCloneSubmodules(CloneOptions options, string repo
repo.Submodules.Update(sm.Name, updateOptions);
- OnRepositoryOperationCompleted(options.RepositoryOperationCompleted,
+ OnRepositoryOperationCompleted(options.FetchOptions.RepositoryOperationCompleted,
context);
submodules.Add(Path.Combine(repo.Info.WorkingDirectory, sm.Path));
@@ -1050,7 +1063,7 @@ public Commit Commit(string message, Signature author, Signature committer, Comm
if (treesame && !amendMergeCommit)
{
- throw (options.AmendPreviousCommit ?
+ throw (options.AmendPreviousCommit ?
new EmptyCommitException("Amending this commit would produce a commit that is identical to its parent (id = {0})", parents[0].Id) :
new EmptyCommitException("No changes; nothing to commit."));
}
@@ -1241,7 +1254,7 @@ public MergeResult MergeFetchedRefs(Signature merger, MergeOptions options)
if (fetchHeads.Length == 0)
{
var expectedRef = this.Head.UpstreamBranchCanonicalName;
- throw new MergeFetchHeadNotFoundException("The current branch is configured to merge with the reference '{0}' from the remote, but this reference was not fetched.",
+ throw new MergeFetchHeadNotFoundException("The current branch is configured to merge with the reference '{0}' from the remote, but this reference was not fetched.",
expectedRef);
}
diff --git a/LibGit2Sharp/SubmoduleCollection.cs b/LibGit2Sharp/SubmoduleCollection.cs
index fc508107a..c4cc1c020 100644
--- a/LibGit2Sharp/SubmoduleCollection.cs
+++ b/LibGit2Sharp/SubmoduleCollection.cs
@@ -104,7 +104,7 @@ public virtual void Update(string name, SubmoduleUpdateOptions options)
{
Version = 1,
CheckoutOptions = gitCheckoutOptions,
- FetchOptions = new GitFetchOptions { ProxyOptions = new GitProxyOptions { Version = 1 }, RemoteCallbacks = gitRemoteCallbacks },
+ FetchOptions = new GitFetchOptions { ProxyOptions = options.ProxyOptions.CreateGitProxyOptions(), RemoteCallbacks = gitRemoteCallbacks },
CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE
};
From 4ab3b4604d8eab831d60ef427675ff0b82d26664 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 25 Nov 2023 19:44:54 -0500
Subject: [PATCH 102/147] Ensure FetchOptions property is non-null
---
LibGit2Sharp/CloneOptions.cs | 2 +-
LibGit2Sharp/Repository.cs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp/CloneOptions.cs b/LibGit2Sharp/CloneOptions.cs
index 05430085e..620896e94 100644
--- a/LibGit2Sharp/CloneOptions.cs
+++ b/LibGit2Sharp/CloneOptions.cs
@@ -46,7 +46,7 @@ public CloneOptions()
///
/// Gets or sets the fetch options.
///
- public FetchOptions FetchOptions { get; set; }
+ public FetchOptions FetchOptions { get; set; } = new();
#region IConvertableToGitCheckoutOpts
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index d7c759e8b..3791dfbd1 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -760,7 +760,7 @@ public static string Clone(string sourceUrl, string workdirPath,
Ensure.ArgumentNotNull(sourceUrl, "sourceUrl");
Ensure.ArgumentNotNull(workdirPath, "workdirPath");
- options = options ?? new CloneOptions();
+ options ??= new CloneOptions();
// context variable that contains information on the repository that
// we are cloning.
From 7bf2e3b803b3a3b477e4c4afa978e589ef7e2bce Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 25 Nov 2023 19:47:48 -0500
Subject: [PATCH 103/147] Make ProxyOptions sealed to satisfy test
---
LibGit2Sharp/ProxyOptions.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/ProxyOptions.cs b/LibGit2Sharp/ProxyOptions.cs
index 02b75bdd8..932dc40ef 100644
--- a/LibGit2Sharp/ProxyOptions.cs
+++ b/LibGit2Sharp/ProxyOptions.cs
@@ -4,7 +4,7 @@
namespace LibGit2Sharp
{
- public class ProxyOptions
+ public sealed class ProxyOptions
{
public ProxyType ProxyType { get; set; } = ProxyType.Auto;
From 747bfc62fff758c309b581655d200983e7c066f3 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 25 Nov 2023 22:34:42 -0500
Subject: [PATCH 104/147] Remove property setters since options are initialized
---
LibGit2Sharp.Tests/CloneFixture.cs | 18 ++++++------------
LibGit2Sharp/CloneOptions.cs | 2 +-
LibGit2Sharp/FetchOptionsBase.cs | 2 +-
3 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs
index c1ff7bc74..b4de8797a 100644
--- a/LibGit2Sharp.Tests/CloneFixture.cs
+++ b/LibGit2Sharp.Tests/CloneFixture.cs
@@ -567,10 +567,8 @@ public void CannotCloneWithForbiddenCustomHeaders()
const string url = "https://github.com/libgit2/TestGitRepository";
const string knownHeader = "User-Agent: mygit-201";
- var cloneOptions = new CloneOptions()
- {
- FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
- };
+ var cloneOptions = new CloneOptions();
+ cloneOptions.FetchOptions.CustomHeaders = new string[] { knownHeader };
Assert.Throws(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions));
}
@@ -583,10 +581,8 @@ public void CannotCloneWithMalformedCustomHeaders()
const string url = "https://github.com/libgit2/TestGitRepository";
const string knownHeader = "hello world";
- var cloneOptions = new CloneOptions()
- {
- FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
- };
+ var cloneOptions = new CloneOptions();
+ cloneOptions.FetchOptions.CustomHeaders = new string[] { knownHeader };
Assert.Throws(() => Repository.Clone(url, scd.DirectoryPath, cloneOptions));
}
@@ -599,10 +595,8 @@ public void CanCloneWithCustomHeaders()
const string url = "https://github.com/libgit2/TestGitRepository";
const string knownHeader = "X-Hello: world";
- var cloneOptions = new CloneOptions()
- {
- FetchOptions = new FetchOptions { CustomHeaders = new String[] { knownHeader } }
- };
+ var cloneOptions = new CloneOptions();
+ cloneOptions.FetchOptions.CustomHeaders = new string[] { knownHeader };
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, cloneOptions);
Assert.True(Directory.Exists(clonedRepoPath));
diff --git a/LibGit2Sharp/CloneOptions.cs b/LibGit2Sharp/CloneOptions.cs
index 620896e94..a315d76fc 100644
--- a/LibGit2Sharp/CloneOptions.cs
+++ b/LibGit2Sharp/CloneOptions.cs
@@ -46,7 +46,7 @@ public CloneOptions()
///
/// Gets or sets the fetch options.
///
- public FetchOptions FetchOptions { get; set; } = new();
+ public FetchOptions FetchOptions { get; } = new();
#region IConvertableToGitCheckoutOpts
diff --git a/LibGit2Sharp/FetchOptionsBase.cs b/LibGit2Sharp/FetchOptionsBase.cs
index 57de331d1..dffd34412 100644
--- a/LibGit2Sharp/FetchOptionsBase.cs
+++ b/LibGit2Sharp/FetchOptionsBase.cs
@@ -49,6 +49,6 @@ internal FetchOptionsBase()
///
public RepositoryOperationCompleted RepositoryOperationCompleted { get; set; }
- public ProxyOptions ProxyOptions { get; set; } = new();
+ public ProxyOptions ProxyOptions { get; } = new();
}
}
From c6ef24d85b31a2121d25559f16424feb5a85a3fa Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 25 Nov 2023 23:06:02 -0500
Subject: [PATCH 105/147] Add XML comments
---
LibGit2Sharp/FetchOptions.cs | 8 ++---
LibGit2Sharp/FetchOptionsBase.cs | 5 +++-
LibGit2Sharp/Network.cs | 50 ++++++++++++++++++++++++++++++++
LibGit2Sharp/ProxyOptions.cs | 16 ++++++++++
LibGit2Sharp/ProxyType.cs | 14 +++++++++
LibGit2Sharp/PushOptions.cs | 3 ++
LibGit2Sharp/Repository.cs | 18 ++++++++++++
7 files changed, 109 insertions(+), 5 deletions(-)
diff --git a/LibGit2Sharp/FetchOptions.cs b/LibGit2Sharp/FetchOptions.cs
index 487baed97..5bcf74bfa 100644
--- a/LibGit2Sharp/FetchOptions.cs
+++ b/LibGit2Sharp/FetchOptions.cs
@@ -28,14 +28,14 @@ public sealed class FetchOptions : FetchOptionsBase
///
/// Get/Set the custom headers.
- ///
- ///
- /// This allows you to set custom headers (e.g. X-Forwarded-For,
+ ///
+ ///
+ /// This allows you to set custom headers (e.g. X-Forwarded-For,
/// X-Request-Id, etc),
///
///
///
- /// Libgit2 sets some headers for HTTP requests (User-Agent, Host,
+ /// Libgit2 sets some headers for HTTP requests (User-Agent, Host,
/// Accept, Content-Type, Transfer-Encoding, Content-Length, Accept) that
/// cannot be overriden.
///
diff --git a/LibGit2Sharp/FetchOptionsBase.cs b/LibGit2Sharp/FetchOptionsBase.cs
index dffd34412..0e548652f 100644
--- a/LibGit2Sharp/FetchOptionsBase.cs
+++ b/LibGit2Sharp/FetchOptionsBase.cs
@@ -35,7 +35,7 @@ internal FetchOptionsBase()
///
/// This handler will be called to let the user make a decision on whether to allow
- /// the connection to preoceed based on the certificate presented by the server.
+ /// the connection to proceed based on the certificate presented by the server.
///
public CertificateCheckHandler CertificateCheck { get; set; }
@@ -49,6 +49,9 @@ internal FetchOptionsBase()
///
public RepositoryOperationCompleted RepositoryOperationCompleted { get; set; }
+ ///
+ /// Options for connecting through a proxy.
+ ///
public ProxyOptions ProxyOptions { get; } = new();
}
}
diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs
index 19070a344..bd80834bb 100644
--- a/LibGit2Sharp/Network.cs
+++ b/LibGit2Sharp/Network.cs
@@ -55,6 +55,18 @@ public virtual IEnumerable ListReferences(Remote remote)
return ListReferencesInternal(remote.Url, null, new ProxyOptions());
}
+ ///
+ /// List references in a repository.
+ ///
+ /// When the remote tips are ahead of the local ones, the retrieved
+ /// s may point to non existing
+ /// s in the local repository. In that
+ /// case, will return null.
+ ///
+ ///
+ /// The to list from.
+ /// Options for connecting through a proxy.
+ /// The references in the repository.
public virtual IEnumerable ListReferences(Remote remote, ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(remote, "remote");
@@ -82,6 +94,19 @@ public virtual IEnumerable ListReferences(Remote remote, CredentialsH
return ListReferencesInternal(remote.Url, credentialsProvider, new ProxyOptions());
}
+ ///
+ /// List references in a repository.
+ ///
+ /// When the remote tips are ahead of the local ones, the retrieved
+ /// s may point to non existing
+ /// s in the local repository. In that
+ /// case, will return null.
+ ///
+ ///
+ /// The to list from.
+ /// The used to connect to remote repository.
+ /// Options for connecting through a proxy.
+ /// The references in the repository.
public virtual IEnumerable ListReferences(Remote remote, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(remote, "remote");
@@ -108,6 +133,18 @@ public virtual IEnumerable ListReferences(string url)
return ListReferencesInternal(url, null, new ProxyOptions());
}
+ ///
+ /// List references in a remote repository.
+ ///
+ /// When the remote tips are ahead of the local ones, the retrieved
+ /// s may point to non existing
+ /// s in the local repository. In that
+ /// case, will return null.
+ ///
+ ///
+ /// The url to list from.
+ /// Options for connecting through a proxy.
+ /// The references in the remote repository.
public virtual IEnumerable ListReferences(string url, ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(url, "url");
@@ -135,6 +172,19 @@ public virtual IEnumerable ListReferences(string url, CredentialsHand
return ListReferencesInternal(url, credentialsProvider, new ProxyOptions());
}
+ ///
+ /// List references in a remote repository.
+ ///
+ /// When the remote tips are ahead of the local ones, the retrieved
+ /// s may point to non existing
+ /// s in the local repository. In that
+ /// case, will return null.
+ ///
+ ///
+ /// The url to list from.
+ /// The used to connect to remote repository.
+ /// Options for connecting through a proxy.
+ /// The references in the remote repository.
public virtual IEnumerable ListReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(url, "url");
diff --git a/LibGit2Sharp/ProxyOptions.cs b/LibGit2Sharp/ProxyOptions.cs
index 932dc40ef..076c4e357 100644
--- a/LibGit2Sharp/ProxyOptions.cs
+++ b/LibGit2Sharp/ProxyOptions.cs
@@ -4,14 +4,30 @@
namespace LibGit2Sharp
{
+ ///
+ /// Options for connecting through a proxy.
+ ///
public sealed class ProxyOptions
{
+ ///
+ /// The type of proxy to use. Set to Auto by default.
+ ///
public ProxyType ProxyType { get; set; } = ProxyType.Auto;
+ ///
+ /// The URL of the proxy when is set to Specified.
+ ///
public string Url { get; set; }
+ ///
+ /// Handler to generate for authentication.
+ ///
public CredentialsHandler CredentialsProvider { get; set; }
+ ///
+ /// This handler will be called to let the user make a decision on whether to allow
+ /// the connection to proceed based on the certificate presented by the server.
+ ///
public CertificateCheckHandler CertificateCheck { get; set; }
internal unsafe GitProxyOptions CreateGitProxyOptions()
diff --git a/LibGit2Sharp/ProxyType.cs b/LibGit2Sharp/ProxyType.cs
index e78606a72..13ec705ee 100644
--- a/LibGit2Sharp/ProxyType.cs
+++ b/LibGit2Sharp/ProxyType.cs
@@ -1,9 +1,23 @@
namespace LibGit2Sharp
{
+ ///
+ /// The type of proxy to use.
+ ///
public enum ProxyType
{
+ ///
+ /// Do not attempt to connect through a proxy.
+ ///
None,
+
+ ///
+ /// Try to auto-detect the proxy from the git configuration.
+ ///
Auto,
+
+ ///
+ /// Connect via the URL given in the options.
+ ///
Specified
}
}
diff --git a/LibGit2Sharp/PushOptions.cs b/LibGit2Sharp/PushOptions.cs
index 501e8d8d2..829eb0d60 100644
--- a/LibGit2Sharp/PushOptions.cs
+++ b/LibGit2Sharp/PushOptions.cs
@@ -72,6 +72,9 @@ public sealed class PushOptions
/// The custom headers string array
public string[] CustomHeaders { get; set; }
+ ///
+ /// Options for connecting through a proxy.
+ ///
public ProxyOptions ProxyOptions { get; set; } = new();
}
}
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 3791dfbd1..a4f2e3077 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -659,6 +659,12 @@ public static IEnumerable ListRemoteReferences(string url)
return ListRemoteReferences(url, null, new ProxyOptions());
}
+ ///
+ /// Lists the Remote Repository References.
+ ///
+ /// The url to list from.
+ /// Options for connecting through a proxy.
+ /// The references in the remote repository.
public static IEnumerable ListRemoteReferences(string url, ProxyOptions proxyOptions)
{
return ListRemoteReferences(url, null, proxyOptions);
@@ -680,6 +686,18 @@ public static IEnumerable ListRemoteReferences(string url, Credential
return ListRemoteReferences(url, credentialsProvider, new ProxyOptions());
}
+ ///
+ /// Lists the Remote Repository References.
+ ///
+ ///
+ /// Does not require a local Repository. The retrieved
+ ///
+ /// throws in this case.
+ ///
+ /// The url to list from.
+ /// The used to connect to remote repository.
+ /// Options for connecting through a proxy.
+ /// The references in the remote repository.
public static IEnumerable ListRemoteReferences(string url, CredentialsHandler credentialsProvider, ProxyOptions proxyOptions)
{
Ensure.ArgumentNotNull(url, "url");
From 01a6ccb3549e6713261638c4e8fe29da732b97a5 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 26 Nov 2023 00:28:16 -0500
Subject: [PATCH 106/147] Update how submodule fetch options are handled
---
LibGit2Sharp.Tests/SubmoduleFixture.cs | 4 +-
LibGit2Sharp/Core/GitSubmoduleOptions.cs | 2 -
LibGit2Sharp/Repository.cs | 7 +---
LibGit2Sharp/SubmoduleCollection.cs | 48 ++++++++++++------------
LibGit2Sharp/SubmoduleUpdateOptions.cs | 7 +++-
5 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/LibGit2Sharp.Tests/SubmoduleFixture.cs b/LibGit2Sharp.Tests/SubmoduleFixture.cs
index 735bfd938..2d7f04e6d 100644
--- a/LibGit2Sharp.Tests/SubmoduleFixture.cs
+++ b/LibGit2Sharp.Tests/SubmoduleFixture.cs
@@ -3,7 +3,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -240,9 +239,10 @@ public void CanUpdateSubmodule()
OnCheckoutProgress = (x, y, z) => checkoutProgressCalled = true,
OnCheckoutNotify = (x, y) => { checkoutNotifyCalled = true; return true; },
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated,
- OnUpdateTips = (x, y, z) => { updateTipsCalled = true; return true; },
};
+ options.FetchOptions.OnUpdateTips = (x, y, z) => { updateTipsCalled = true; return true; };
+
repo.Submodules.Init(submodule.Name, false);
repo.Submodules.Update(submodule.Name, options);
diff --git a/LibGit2Sharp/Core/GitSubmoduleOptions.cs b/LibGit2Sharp/Core/GitSubmoduleOptions.cs
index 59c2b3f80..09a8e8265 100644
--- a/LibGit2Sharp/Core/GitSubmoduleOptions.cs
+++ b/LibGit2Sharp/Core/GitSubmoduleOptions.cs
@@ -11,8 +11,6 @@ internal struct GitSubmoduleUpdateOptions
public GitFetchOptions FetchOptions;
- public CheckoutStrategy CloneCheckoutStrategy;
-
public int AllowFetch;
}
}
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index a4f2e3077..73f560c3c 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -865,14 +865,11 @@ private static void RecursivelyCloneSubmodules(CloneOptions options, string repo
using (Repository repo = new Repository(repoPath))
{
- SubmoduleUpdateOptions updateOptions = new SubmoduleUpdateOptions()
+ var updateOptions = new SubmoduleUpdateOptions()
{
Init = true,
- CredentialsProvider = options.FetchOptions.CredentialsProvider,
OnCheckoutProgress = options.OnCheckoutProgress,
- OnProgress = options.FetchOptions.OnProgress,
- OnTransferProgress = options.FetchOptions.OnTransferProgress,
- OnUpdateTips = options.FetchOptions.OnUpdateTips,
+ FetchOptions = options.FetchOptions
};
string parentRepoWorkDir = repo.Info.WorkingDirectory;
diff --git a/LibGit2Sharp/SubmoduleCollection.cs b/LibGit2Sharp/SubmoduleCollection.cs
index c4cc1c020..061196c7d 100644
--- a/LibGit2Sharp/SubmoduleCollection.cs
+++ b/LibGit2Sharp/SubmoduleCollection.cs
@@ -74,43 +74,41 @@ public virtual void Init(string name, bool overwrite)
/// Update specified submodule.
///
/// This will:
- /// 1) Optionally initialize the if it not already initialzed,
+ /// 1) Optionally initialize the if it not already initialized,
/// 2) clone the sub repository if it has not already been cloned, and
/// 3) checkout the commit ID for the submodule in the sub repository.
///
///
/// The name of the submodule to update.
- /// Options controlling submodule udpate behavior and callbacks.
+ /// Options controlling submodule update behavior and callbacks.
public virtual void Update(string name, SubmoduleUpdateOptions options)
{
- options = options ?? new SubmoduleUpdateOptions();
+ options ??= new SubmoduleUpdateOptions();
- using (var handle = Proxy.git_submodule_lookup(repo.Handle, name))
- {
- if (handle == null)
- {
- throw new NotFoundException("Submodule lookup failed for '{0}'.",
- name);
- }
+ using var handle = Proxy.git_submodule_lookup(repo.Handle, name) ?? throw new NotFoundException("Submodule lookup failed for '{0}'.", name);
+ using var checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options);
+ using var fetchOptionsWrapper = new GitFetchOptionsWrapper();
- using (GitCheckoutOptsWrapper checkoutOptionsWrapper = new GitCheckoutOptsWrapper(options))
- {
- var gitCheckoutOptions = checkoutOptionsWrapper.Options;
+ var gitCheckoutOptions = checkoutOptionsWrapper.Options;
- var remoteCallbacks = new RemoteCallbacks(options);
- var gitRemoteCallbacks = remoteCallbacks.GenerateCallbacks();
+ var gitFetchOptions = fetchOptionsWrapper.Options;
+ gitFetchOptions.ProxyOptions = options.FetchOptions.ProxyOptions.CreateGitProxyOptions();
+ gitFetchOptions.RemoteCallbacks = new RemoteCallbacks(options.FetchOptions).GenerateCallbacks();
- var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions
- {
- Version = 1,
- CheckoutOptions = gitCheckoutOptions,
- FetchOptions = new GitFetchOptions { ProxyOptions = options.ProxyOptions.CreateGitProxyOptions(), RemoteCallbacks = gitRemoteCallbacks },
- CloneCheckoutStrategy = CheckoutStrategy.GIT_CHECKOUT_SAFE
- };
-
- Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts);
- }
+ if (options.FetchOptions != null && options.FetchOptions.CustomHeaders != null)
+ {
+ gitFetchOptions.CustomHeaders =
+ GitStrArrayManaged.BuildFrom(options.FetchOptions.CustomHeaders);
}
+
+ var gitSubmoduleUpdateOpts = new GitSubmoduleUpdateOptions
+ {
+ Version = 1,
+ CheckoutOptions = gitCheckoutOptions,
+ FetchOptions = gitFetchOptions
+ };
+
+ Proxy.git_submodule_update(handle, options.Init, ref gitSubmoduleUpdateOpts);
}
///
diff --git a/LibGit2Sharp/SubmoduleUpdateOptions.cs b/LibGit2Sharp/SubmoduleUpdateOptions.cs
index 89f895d75..082e17338 100644
--- a/LibGit2Sharp/SubmoduleUpdateOptions.cs
+++ b/LibGit2Sharp/SubmoduleUpdateOptions.cs
@@ -6,7 +6,7 @@ namespace LibGit2Sharp
///
/// Options controlling Submodule Update behavior and callbacks.
///
- public sealed class SubmoduleUpdateOptions : FetchOptionsBase, IConvertableToGitCheckoutOpts
+ public sealed class SubmoduleUpdateOptions : IConvertableToGitCheckoutOpts
{
///
/// Initialize the submodule if it is not already initialized.
@@ -30,6 +30,11 @@ public sealed class SubmoduleUpdateOptions : FetchOptionsBase, IConvertableToGit
///
public CheckoutNotifyFlags CheckoutNotifyFlags { get; set; }
+ ///
+ /// Collection of parameters controlling Fetch behavior.
+ ///
+ public FetchOptions FetchOptions { get; internal set; } = new();
+
CheckoutCallbacks IConvertableToGitCheckoutOpts.GenerateCallbacks()
{
return CheckoutCallbacks.From(OnCheckoutProgress, OnCheckoutNotify);
From de87973b56633459d770602fc87d8f896af93175 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 3 Dec 2023 15:42:35 -0500
Subject: [PATCH 107/147] Update CHANGES.md for v0.29
---
CHANGES.md | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/CHANGES.md b/CHANGES.md
index 0cb2c978b..ae27d7716 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,6 +1,16 @@
# LibGit2Sharp Changes
-## v0.28
+## v0.29 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.28.0..0.29.0))
+
+### Changes
+- This release includes [libgit2 v1.7.1](https://github.com/libgit2/libgit2/releases/tag/v1.7.1).
+ - CI changes for the native binaries has removed support for CentOS 7. See [#2066](https://github.com/libgit2/libgit2sharp/pull/2066) for details.
+
+### Additions
+- Add proxy options [#2065](https://github.com/libgit2/libgit2sharp/pull/2065)
+ - See PR for details, including some breaking changes to `CloneOptions` and `SubmoduleUpdateOptions`
+
+## v0.28 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.27.2..0.28.0))
### Additions
- Add CustomHeaders to PushOptions [#2052](https://github.com/libgit2/libgit2sharp/pull/2052)
From 2cad6cd44dcb419d9bcadaeab92dd75d3b68ff9a Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Wed, 13 Mar 2024 23:50:12 -0400
Subject: [PATCH 108/147] Add project to test trimming compatibility
---
.github/workflows/ci.yml | 2 ++
LibGit2Sharp/LibGit2Sharp.csproj | 4 ++++
TrimmingTestApp/Program.cs | 3 +++
TrimmingTestApp/TrimmingTestApp.csproj | 18 ++++++++++++++++++
4 files changed, 27 insertions(+)
create mode 100644 TrimmingTestApp/Program.cs
create mode 100644 TrimmingTestApp/TrimmingTestApp.csproj
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5214b064f..9d3551569 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -30,6 +30,8 @@ jobs:
name: NuGet packages
path: bin/Packages/
retention-days: 7
+ - name: Verify trimming compatibility
+ run: dotnet publish TrimmingTestApp
test:
name: Test / ${{ matrix.os }} / ${{ matrix.arch }} / ${{ matrix.tfm }}
runs-on: ${{ matrix.os }}
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 4d0876c4d..e8836b90c 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -23,6 +23,10 @@
libgit2-$(libgit2_hash.Substring(0,7))
+
+ true
+
+
diff --git a/TrimmingTestApp/Program.cs b/TrimmingTestApp/Program.cs
new file mode 100644
index 000000000..e568c227b
--- /dev/null
+++ b/TrimmingTestApp/Program.cs
@@ -0,0 +1,3 @@
+using LibGit2Sharp;
+
+_ = new Repository();
diff --git a/TrimmingTestApp/TrimmingTestApp.csproj b/TrimmingTestApp/TrimmingTestApp.csproj
new file mode 100644
index 000000000..9cb7e75b4
--- /dev/null
+++ b/TrimmingTestApp/TrimmingTestApp.csproj
@@ -0,0 +1,18 @@
+
+
+
+ net8.0
+ Exe
+ enable
+ enable
+ true
+ true
+ true
+
+
+
+
+
+
+
+
From 70ac848e7faa2f42a3d90a32dbc118a932051617 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Wed, 13 Mar 2024 23:54:52 -0400
Subject: [PATCH 109/147] Address trimming warnings
---
LibGit2Sharp/Core/GitObjectLazyGroup.cs | 6 ++++++
LibGit2Sharp/Core/LazyGroup.cs | 9 +++++++++
LibGit2Sharp/Core/NativeMethods.cs | 2 +-
LibGit2Sharp/Core/Platform.cs | 4 ++++
LibGit2Sharp/ReferenceWrapper.cs | 5 +++++
5 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/LibGit2Sharp/Core/GitObjectLazyGroup.cs b/LibGit2Sharp/Core/GitObjectLazyGroup.cs
index 11c83a81e..f00900837 100644
--- a/LibGit2Sharp/Core/GitObjectLazyGroup.cs
+++ b/LibGit2Sharp/Core/GitObjectLazyGroup.cs
@@ -1,4 +1,5 @@
using System;
+using System.Diagnostics.CodeAnalysis;
using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp.Core
@@ -21,7 +22,12 @@ protected override void EvaluateInternal(Action evaluator)
}
}
+#if NET
+ public static ILazy Singleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TResult>(Repository repo, ObjectId id, Func resultSelector, bool throwIfMissing = false)
+#else
public static ILazy Singleton(Repository repo, ObjectId id, Func resultSelector, bool throwIfMissing = false)
+#endif
+
{
return Singleton(() =>
{
diff --git a/LibGit2Sharp/Core/LazyGroup.cs b/LibGit2Sharp/Core/LazyGroup.cs
index d8b13fa42..bcd160290 100644
--- a/LibGit2Sharp/Core/LazyGroup.cs
+++ b/LibGit2Sharp/Core/LazyGroup.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
namespace LibGit2Sharp.Core
{
@@ -44,7 +45,11 @@ public void Evaluate()
protected abstract void EvaluateInternal(Action evaluator);
+#if NET
+ protected static ILazy Singleton<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TResult>(Func resultSelector)
+#else
protected static ILazy Singleton(Func resultSelector)
+#endif
{
return new LazyWrapper(resultSelector);
}
@@ -90,7 +95,11 @@ void IEvaluator.Evaluate(TInput input)
}
}
+#if NET
+ protected class LazyWrapper<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TType> : Lazy, ILazy
+#else
protected class LazyWrapper : Lazy, ILazy
+#endif
{
public LazyWrapper(Func evaluator)
: base(evaluator)
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index e20d755ba..cd3e1de7a 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -102,7 +102,7 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor
{
// The libraries are located at 'runtimes//native/lib{libraryName}.so'
// The ends with the processor architecture. e.g. fedora-x64.
- string assemblyDirectory = Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location);
+ string assemblyDirectory = Path.GetDirectoryName(AppContext.BaseDirectory);
string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
string runtimesDirectory = Path.Combine(assemblyDirectory, "runtimes");
diff --git a/LibGit2Sharp/Core/Platform.cs b/LibGit2Sharp/Core/Platform.cs
index 42b752612..1fcb59faf 100644
--- a/LibGit2Sharp/Core/Platform.cs
+++ b/LibGit2Sharp/Core/Platform.cs
@@ -58,7 +58,11 @@ public static string GetNativeLibraryExtension()
/// Returns true if the runtime is Mono.
///
public static bool IsRunningOnMono()
+#if NETFRAMEWORK
=> Type.GetType("Mono.Runtime") != null;
+#else
+ => false;
+#endif
///
/// Returns true if the runtime is .NET Framework.
diff --git a/LibGit2Sharp/ReferenceWrapper.cs b/LibGit2Sharp/ReferenceWrapper.cs
index 3e4243a7e..eff09e6ce 100644
--- a/LibGit2Sharp/ReferenceWrapper.cs
+++ b/LibGit2Sharp/ReferenceWrapper.cs
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using LibGit2Sharp.Core;
@@ -10,7 +11,11 @@ namespace LibGit2Sharp
///
/// The type of the referenced Git object.
[DebuggerDisplay("{DebuggerDisplay,nq}")]
+#if NET
+ public abstract class ReferenceWrapper<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TObject> : IEquatable>, IBelongToARepository where TObject : GitObject
+#else
public abstract class ReferenceWrapper : IEquatable>, IBelongToARepository where TObject : GitObject
+#endif
{
///
/// The repository.
From 29b7380483d6de917a3edb45108d332eab197460 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Wed, 13 Mar 2024 23:58:40 -0400
Subject: [PATCH 110/147] Use .NET 8 SDK
---
.github/workflows/ci.yml | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9d3551569..f09880169 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -21,7 +21,7 @@ jobs:
- name: Install .NET SDK
uses: actions/setup-dotnet@v3.0.3
with:
- dotnet-version: 7.0.x
+ dotnet-version: 8.0.x
- name: Build
run: dotnet build LibGit2Sharp.sln --configuration Release
- name: Upload packages
@@ -53,6 +53,7 @@ jobs:
uses: actions/setup-dotnet@v3.0.3
with:
dotnet-version: |
+ 8.0.x
7.0.x
6.0.x
- name: Run ${{ matrix.tfm }} tests
From ea4e6c979e9fa0c744eca4f42c5dc6bdbfde3dae Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Mar 2024 21:01:32 -0400
Subject: [PATCH 111/147] Fix failing test
---
LibGit2Sharp.Tests/CloneFixture.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs
index b4de8797a..f205eddc2 100644
--- a/LibGit2Sharp.Tests/CloneFixture.cs
+++ b/LibGit2Sharp.Tests/CloneFixture.cs
@@ -267,7 +267,7 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
Assert.True(valid);
var x509 = ((CertificateX509)cert).Certificate;
// we get a string with the different fields instead of a structure, so...
- Assert.Contains("CN=github.com,", x509.Subject);
+ Assert.Contains("CN=github.com", x509.Subject);
checksHappy = true;
return false;
}
From 4e8e00e8d8d8fb9ea046a4302ceca3655e17a912 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Mar 2024 22:53:13 -0400
Subject: [PATCH 112/147] Add net8.0 test targets
---
.github/workflows/ci.yml | 10 ++++++++--
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 2 +-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f09880169..aba8ce0a0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -39,7 +39,7 @@ jobs:
matrix:
arch: [ amd64 ]
os: [ windows-2019, macos-11 ]
- tfm: [ net472, net6.0, net7.0 ]
+ tfm: [ net472, net6.0, net7.0, net8.0 ]
exclude:
- os: macos-11
tfm: net472
@@ -66,17 +66,23 @@ jobs:
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' ]
+ sdk: [ '6.0', '7.0' , '8.0' ]
exclude:
- distro: alpine.3.13
sdk: '7.0'
- distro: alpine.3.14
sdk: '7.0'
+ - distro: alpine.3.13
+ sdk: '8.0'
+ - distro: alpine.3.14
+ 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
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index c5cbb5f24..7501b9560 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,7 +1,7 @@
- net472;net6.0;net7.0
+ net472;net6.0;net7.0;net8.0
From 2b585e991a7efe0a471a6f411efdef4c12ff7016 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Mar 2024 23:26:45 -0400
Subject: [PATCH 113/147] Use .NET 8 SDK artifacts output
---
.github/workflows/ci.yml | 2 +-
.gitignore | 2 +-
Directory.Build.props | 4 +---
LibGit2Sharp/LibGit2Sharp.csproj | 1 +
NativeLibraryLoadTestApp/Directory.Build.props | 7 -------
5 files changed, 4 insertions(+), 12 deletions(-)
delete mode 100644 NativeLibraryLoadTestApp/Directory.Build.props
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index aba8ce0a0..f751435bf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -28,7 +28,7 @@ jobs:
uses: actions/upload-artifact@v3.1.2
with:
name: NuGet packages
- path: bin/Packages/
+ path: artifacts/package/
retention-days: 7
- name: Verify trimming compatibility
run: dotnet publish TrimmingTestApp
diff --git a/.gitignore b/.gitignore
index 2f75ccc1d..32e17b4d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,5 +38,5 @@ _ReSharper*/
*.DotSettings
_NCrunch_LibGit2Sharp/
-packages/
+artifacts/
worktree.playlist
diff --git a/Directory.Build.props b/Directory.Build.props
index 72eda8864..95f095732 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -2,9 +2,7 @@
true
- $(MSBuildThisFileDirectory)bin\$(MSBuildProjectName)\$(Configuration)\
- $(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\
- $(MSBuildThisFileDirectory)bin\Packages\
+ true
$(DefineConstants);$(ExtraDefine)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index e8836b90c..36f0d8672 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -19,6 +19,7 @@
App_Readme/README.md
App_Readme/LICENSE.md
true
+ $(ArtifactsPath)\package
preview.0
libgit2-$(libgit2_hash.Substring(0,7))
diff --git a/NativeLibraryLoadTestApp/Directory.Build.props b/NativeLibraryLoadTestApp/Directory.Build.props
deleted file mode 100644
index c55b35c72..000000000
--- a/NativeLibraryLoadTestApp/Directory.Build.props
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
- false
-
-
-
From c9352c3236b882e2b83f64d917ab1b7ba32f2776 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Mar 2024 23:37:25 -0400
Subject: [PATCH 114/147] Update packages
---
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 12 ++++++------
LibGit2Sharp.Tests/MetaFixture.cs | 3 ---
LibGit2Sharp/LibGit2Sharp.csproj | 4 ++--
3 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 7501b9560..8f5ac09dd 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -11,12 +11,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/LibGit2Sharp.Tests/MetaFixture.cs b/LibGit2Sharp.Tests/MetaFixture.cs
index b70d9022c..eac08793d 100644
--- a/LibGit2Sharp.Tests/MetaFixture.cs
+++ b/LibGit2Sharp.Tests/MetaFixture.cs
@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
-using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
-using Moq;
namespace LibGit2Sharp.Tests
{
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 36f0d8672..fcf965c7d 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -40,8 +40,8 @@
-
-
+
+
From 9e4669c3d95931acb486cda43fab227217d5e258 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 15 Mar 2024 23:53:35 -0400
Subject: [PATCH 115/147] Fix test analyzer warnings
---
LibGit2Sharp.Tests/BranchFixture.cs | 5 ++---
LibGit2Sharp.Tests/FilterFixture.cs | 15 ++++++---------
LibGit2Sharp.Tests/MetaFixture.cs | 8 ++++----
LibGit2Sharp.Tests/PushFixture.cs | 3 +--
LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 2 +-
5 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs
index 736b0faec..88247e256 100644
--- a/LibGit2Sharp.Tests/BranchFixture.cs
+++ b/LibGit2Sharp.Tests/BranchFixture.cs
@@ -4,7 +4,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -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);
@@ -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);
diff --git a/LibGit2Sharp.Tests/FilterFixture.cs b/LibGit2Sharp.Tests/FilterFixture.cs
index 4de354003..832ca0cad 100644
--- a/LibGit2Sharp.Tests/FilterFixture.cs
+++ b/LibGit2Sharp.Tests/FilterFixture.cs
@@ -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
{
@@ -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";
@@ -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);
}
}
diff --git a/LibGit2Sharp.Tests/MetaFixture.cs b/LibGit2Sharp.Tests/MetaFixture.cs
index eac08793d..5ff76e307 100644
--- a/LibGit2Sharp.Tests/MetaFixture.cs
+++ b/LibGit2Sharp.Tests/MetaFixture.cs
@@ -112,7 +112,7 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
if (typesWithDebuggerDisplayAndInvalidImplPattern.Any())
{
- Assert.True(false, Environment.NewLine + BuildMissingDebuggerDisplayPropertyMessage(typesWithDebuggerDisplayAndInvalidImplPattern));
+ Assert.Fail(Environment.NewLine + BuildMissingDebuggerDisplayPropertyMessage(typesWithDebuggerDisplayAndInvalidImplPattern));
}
}
@@ -167,7 +167,7 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
if (nonTestableTypes.Any())
{
- Assert.True(false, Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes));
+ Assert.Fail(Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes));
}
}
@@ -287,7 +287,7 @@ public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability()
method.DeclaringType, Environment.NewLine);
}
- Assert.True(false, Environment.NewLine + sb.ToString());
+ Assert.Fail(Environment.NewLine + sb.ToString());
}
}
@@ -316,7 +316,7 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
type.FullName, coreNamespace, Environment.NewLine);
}
- Assert.True(false, Environment.NewLine + sb.ToString());
+ Assert.Fail(Environment.NewLine + sb.ToString());
}
}
diff --git a/LibGit2Sharp.Tests/PushFixture.cs b/LibGit2Sharp.Tests/PushFixture.cs
index fc6c0c42d..824c1d8c0 100644
--- a/LibGit2Sharp.Tests/PushFixture.cs
+++ b/LibGit2Sharp.Tests/PushFixture.cs
@@ -12,8 +12,7 @@ public class PushFixture : BaseFixture
{
private void OnPushStatusError(PushStatusError pushStatusErrors)
{
- Assert.True(false, string.Format("Failed to update reference '{0}': {1}",
- pushStatusErrors.Reference, pushStatusErrors.Message));
+ Assert.Fail(string.Format("Failed to update reference '{0}': {1}", pushStatusErrors.Reference, pushStatusErrors.Message));
}
private void AssertPush(Action push)
diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
index 8d9b9ba0c..cde8f3ddb 100644
--- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
+++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
@@ -278,7 +278,7 @@ public virtual void Dispose()
if (Core.LeaksContainer.TypeNames.Any())
{
- Assert.False(true, string.Format("Some handles of the following types haven't been properly released: {0}.{1}"
+ Assert.Fail(string.Format("Some handles of the following types haven't been properly released: {0}.{1}"
+ "In order to get some help fixing those leaks, uncomment the define LEAKS_TRACKING in Libgit2Object.cs{1}"
+ "and run the tests locally.", string.Join(", ", Core.LeaksContainer.TypeNames), Environment.NewLine));
}
From 8d79ff45f67f632e26ff2e3d29f863fac3aa4c22 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Mar 2024 00:10:10 -0400
Subject: [PATCH 116/147] Update workflow actions
---
.github/workflows/ci.yml | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f751435bf..6cac69258 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -15,17 +15,17 @@ 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: artifacts/package/
@@ -46,11 +46,11 @@ jobs:
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
@@ -86,7 +86,7 @@ jobs:
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
From 4193f6bbd0c18efc81419640fed61cb4fe791aee Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Mar 2024 01:09:18 -0400
Subject: [PATCH 117/147] Update testing matrix
---
.github/workflows/ci.yml | 40 ++++++++++++++------
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 2 +-
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6cac69258..35f0241ef 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -37,12 +37,25 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
- arch: [ amd64 ]
- os: [ windows-2019, macos-11 ]
- tfm: [ net472, net6.0, net7.0, net8.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
@@ -54,7 +67,6 @@ jobs:
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
@@ -65,22 +77,26 @@ 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' , '8.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'
- - distro: alpine.3.14
- sdk: '7.0'
- distro: alpine.3.13
sdk: '8.0'
- distro: alpine.3.14
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
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 8f5ac09dd..4d648eead 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,7 +1,7 @@
- net472;net6.0;net7.0;net8.0
+ net472;net6.0;net8.0
From c4073715055b2d8c6009ced0a52db6659ceaa104 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Mar 2024 00:45:34 -0400
Subject: [PATCH 118/147] Fix analyzer warnings
---
Directory.Build.props | 1 +
.../desktop/SmartSubtransportFixture.cs | 2 +-
LibGit2Sharp/AmbiguousSpecificationException.cs | 10 ++++++++--
LibGit2Sharp/BareRepositoryException.cs | 6 ++++++
LibGit2Sharp/CheckoutConflictException.cs | 6 ++++++
LibGit2Sharp/EmptyCommitException.cs | 6 ++++++
LibGit2Sharp/EntryExistsException.cs | 7 +++++++
LibGit2Sharp/InvalidSpecificationException.cs | 6 ++++++
LibGit2Sharp/LibGit2SharpException.cs | 9 +++++++--
LibGit2Sharp/LockedFileException.cs | 6 ++++++
LibGit2Sharp/MergeFetchHeadNotFoundException.cs | 6 ++++++
LibGit2Sharp/NameConflictException.cs | 6 ++++++
LibGit2Sharp/NativeException.cs | 13 ++++++++-----
LibGit2Sharp/NonFastForwardException.cs | 6 ++++++
LibGit2Sharp/NotFoundException.cs | 6 ++++++
LibGit2Sharp/PeelException.cs | 6 ++++++
LibGit2Sharp/RecurseSubmodulesException.cs | 6 ++++++
LibGit2Sharp/RemoveFromIndexException.cs | 7 ++++++-
LibGit2Sharp/RepositoryNotFoundException.cs | 6 ++++++
LibGit2Sharp/UnbornBranchException.cs | 6 ++++++
LibGit2Sharp/UnmatchedPathException.cs | 6 ++++++
LibGit2Sharp/UnmergedIndexEntriesException.cs | 6 ++++++
LibGit2Sharp/UserCanceledException.cs | 6 ++++++
23 files changed, 134 insertions(+), 11 deletions(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index 95f095732..2c14cc2bd 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,6 +1,7 @@
+ true
true
true
$(DefineConstants);$(ExtraDefine)
diff --git a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
index ff4d0fcd6..bc7e7ac15 100644
--- a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
+++ b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
@@ -313,7 +313,7 @@ private HttpWebResponse GetResponseWithRedirects()
}
// rethrow if it's not 401
- throw ex;
+ throw;
}
if (response.StatusCode == HttpStatusCode.Moved || response.StatusCode == HttpStatusCode.Redirect)
diff --git a/LibGit2Sharp/AmbiguousSpecificationException.cs b/LibGit2Sharp/AmbiguousSpecificationException.cs
index 16c77f6df..4903d9df9 100644
--- a/LibGit2Sharp/AmbiguousSpecificationException.cs
+++ b/LibGit2Sharp/AmbiguousSpecificationException.cs
@@ -1,13 +1,17 @@
-using LibGit2Sharp.Core;
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
+using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
///
/// The exception that is thrown when the provided specification cannot uniquely identify a reference, an object or a path.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class AmbiguousSpecificationException : NativeException
{
///
@@ -30,7 +34,7 @@ public AmbiguousSpecificationException(string message)
/// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public AmbiguousSpecificationException(string format, params object[] args)
- : base(String.Format(format, args))
+ : base(string.Format(format, args))
{
}
@@ -43,6 +47,7 @@ public AmbiguousSpecificationException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -51,6 +56,7 @@ public AmbiguousSpecificationException(string message, Exception innerException)
protected AmbiguousSpecificationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal override GitErrorCode ErrorCode
{
diff --git a/LibGit2Sharp/BareRepositoryException.cs b/LibGit2Sharp/BareRepositoryException.cs
index 7ee830a0c..461204acd 100644
--- a/LibGit2Sharp/BareRepositoryException.cs
+++ b/LibGit2Sharp/BareRepositoryException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -8,7 +10,9 @@ namespace LibGit2Sharp
/// The exception that is thrown when an operation which requires a
/// working directory is performed against a bare repository.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class BareRepositoryException : NativeException
{
///
@@ -43,6 +47,7 @@ public BareRepositoryException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -51,6 +56,7 @@ public BareRepositoryException(string message, Exception innerException)
protected BareRepositoryException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal BareRepositoryException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/CheckoutConflictException.cs b/LibGit2Sharp/CheckoutConflictException.cs
index f2f5092e9..23b97143e 100644
--- a/LibGit2Sharp/CheckoutConflictException.cs
+++ b/LibGit2Sharp/CheckoutConflictException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -9,7 +11,9 @@ namespace LibGit2Sharp
/// because of a conflicting change staged in the index, or unstaged
/// in the working directory.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class CheckoutConflictException : NativeException
{
///
@@ -44,6 +48,7 @@ public CheckoutConflictException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -52,6 +57,7 @@ public CheckoutConflictException(string message, Exception innerException)
protected CheckoutConflictException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal CheckoutConflictException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/EmptyCommitException.cs b/LibGit2Sharp/EmptyCommitException.cs
index 8cd48e49f..0c247bec7 100644
--- a/LibGit2Sharp/EmptyCommitException.cs
+++ b/LibGit2Sharp/EmptyCommitException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
namespace LibGit2Sharp
{
@@ -7,7 +9,9 @@ namespace LibGit2Sharp
/// The exception that is thrown when a commit would create an "empty"
/// commit that is treesame to its parent without an explicit override.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class EmptyCommitException : LibGit2SharpException
{
///
@@ -42,6 +46,7 @@ public EmptyCommitException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -50,5 +55,6 @@ public EmptyCommitException(string message, Exception innerException)
protected EmptyCommitException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
}
}
diff --git a/LibGit2Sharp/EntryExistsException.cs b/LibGit2Sharp/EntryExistsException.cs
index 2c46e4acd..8039f5edd 100644
--- a/LibGit2Sharp/EntryExistsException.cs
+++ b/LibGit2Sharp/EntryExistsException.cs
@@ -1,5 +1,8 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
+
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -7,7 +10,9 @@ namespace LibGit2Sharp
///
/// The exception that is thrown attempting to create a resource that already exists.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class EntryExistsException : LibGit2SharpException
{
///
@@ -42,6 +47,7 @@ public EntryExistsException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -50,6 +56,7 @@ public EntryExistsException(string message, Exception innerException)
protected EntryExistsException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal EntryExistsException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
diff --git a/LibGit2Sharp/InvalidSpecificationException.cs b/LibGit2Sharp/InvalidSpecificationException.cs
index 3d34571a4..573a8a1db 100644
--- a/LibGit2Sharp/InvalidSpecificationException.cs
+++ b/LibGit2Sharp/InvalidSpecificationException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -10,7 +12,9 @@ namespace LibGit2Sharp
/// if the spec refers to an object of an incorrect type (e.g. asking to
/// create a branch from a blob, or peeling a blob to a commit).
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class InvalidSpecificationException : NativeException
{
///
@@ -45,6 +49,7 @@ public InvalidSpecificationException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -53,6 +58,7 @@ public InvalidSpecificationException(string message, Exception innerException)
protected InvalidSpecificationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal InvalidSpecificationException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/LibGit2SharpException.cs b/LibGit2Sharp/LibGit2SharpException.cs
index 5d1c33f25..e5d90f61f 100644
--- a/LibGit2Sharp/LibGit2SharpException.cs
+++ b/LibGit2Sharp/LibGit2SharpException.cs
@@ -1,14 +1,17 @@
using System;
using System.Globalization;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
-using LibGit2Sharp.Core;
+#endif
namespace LibGit2Sharp
{
///
/// The exception that is thrown when an error occurs during application execution.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class LibGit2SharpException : Exception
{
///
@@ -40,10 +43,11 @@ public LibGit2SharpException(string message, Exception innerException)
/// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public LibGit2SharpException(string format, params object[] args)
- : base(String.Format(CultureInfo.InvariantCulture, format, args))
+ : base(string.Format(CultureInfo.InvariantCulture, format, args))
{
}
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -52,5 +56,6 @@ public LibGit2SharpException(string format, params object[] args)
protected LibGit2SharpException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
}
}
diff --git a/LibGit2Sharp/LockedFileException.cs b/LibGit2Sharp/LockedFileException.cs
index 44fd65b02..d58c8dbec 100644
--- a/LibGit2Sharp/LockedFileException.cs
+++ b/LibGit2Sharp/LockedFileException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -7,7 +9,9 @@ namespace LibGit2Sharp
///
/// The exception that is thrown attempting to open a locked file.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class LockedFileException : NativeException
{
///
@@ -42,6 +46,7 @@ public LockedFileException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -50,6 +55,7 @@ public LockedFileException(string message, Exception innerException)
protected LockedFileException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal LockedFileException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/MergeFetchHeadNotFoundException.cs b/LibGit2Sharp/MergeFetchHeadNotFoundException.cs
index a86bf5caf..34b6b71aa 100644
--- a/LibGit2Sharp/MergeFetchHeadNotFoundException.cs
+++ b/LibGit2Sharp/MergeFetchHeadNotFoundException.cs
@@ -1,12 +1,16 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
namespace LibGit2Sharp
{
///
/// The exception that is thrown when the ref to merge with was as part of a pull operation not fetched.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class MergeFetchHeadNotFoundException : NotFoundException
{
///
@@ -41,6 +45,7 @@ public MergeFetchHeadNotFoundException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -49,5 +54,6 @@ public MergeFetchHeadNotFoundException(string message, Exception innerException)
protected MergeFetchHeadNotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
}
}
diff --git a/LibGit2Sharp/NameConflictException.cs b/LibGit2Sharp/NameConflictException.cs
index 0dcffc648..0f4dde744 100644
--- a/LibGit2Sharp/NameConflictException.cs
+++ b/LibGit2Sharp/NameConflictException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -7,7 +9,9 @@ namespace LibGit2Sharp
///
/// The exception that is thrown when a reference, a remote, a submodule... with the same name already exists in the repository
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class NameConflictException : NativeException
{
///
@@ -42,6 +46,7 @@ public NameConflictException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -50,6 +55,7 @@ public NameConflictException(string message, Exception innerException)
protected NameConflictException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal NameConflictException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/NativeException.cs b/LibGit2Sharp/NativeException.cs
index 292372db7..66dc03c57 100644
--- a/LibGit2Sharp/NativeException.cs
+++ b/LibGit2Sharp/NativeException.cs
@@ -1,16 +1,17 @@
-using LibGit2Sharp.Core;
-using System;
-using System.Collections.Generic;
-using System.Globalization;
+using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
-using System.Text;
+#endif
+using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
///
/// An exception thrown that corresponds to a libgit2 (native library) error.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public abstract class NativeException : LibGit2SharpException
{
///
@@ -32,9 +33,11 @@ internal NativeException(string format, params object[] args)
{
}
+#if NETFRAMEWORK
internal NativeException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal NativeException(string message, GitErrorCategory category) : this(message)
{
diff --git a/LibGit2Sharp/NonFastForwardException.cs b/LibGit2Sharp/NonFastForwardException.cs
index b5a858f47..f63e2eb1d 100644
--- a/LibGit2Sharp/NonFastForwardException.cs
+++ b/LibGit2Sharp/NonFastForwardException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -8,7 +10,9 @@ namespace LibGit2Sharp
/// The exception that is thrown when push cannot be performed
/// against the remote without losing commits.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class NonFastForwardException : NativeException
{
///
@@ -43,6 +47,7 @@ public NonFastForwardException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -51,6 +56,7 @@ public NonFastForwardException(string message, Exception innerException)
protected NonFastForwardException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal NonFastForwardException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/NotFoundException.cs b/LibGit2Sharp/NotFoundException.cs
index f8c49cc91..4aefe3f8a 100644
--- a/LibGit2Sharp/NotFoundException.cs
+++ b/LibGit2Sharp/NotFoundException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -7,7 +9,9 @@ namespace LibGit2Sharp
///
/// The exception that is thrown attempting to reference a resource that does not exist.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class NotFoundException : NativeException
{
///
@@ -42,6 +46,7 @@ public NotFoundException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -50,6 +55,7 @@ public NotFoundException(string message, Exception innerException)
protected NotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal NotFoundException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/PeelException.cs b/LibGit2Sharp/PeelException.cs
index d7758d7c9..92a6a0f13 100644
--- a/LibGit2Sharp/PeelException.cs
+++ b/LibGit2Sharp/PeelException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -8,7 +10,9 @@ namespace LibGit2Sharp
/// The exception that is thrown when a tag cannot be peeled to the
/// target type due to the object model.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class PeelException : NativeException
{
///
@@ -43,6 +47,7 @@ public PeelException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -51,6 +56,7 @@ public PeelException(string message, Exception innerException)
protected PeelException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal PeelException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/RecurseSubmodulesException.cs b/LibGit2Sharp/RecurseSubmodulesException.cs
index cf4479701..2269f0d16 100644
--- a/LibGit2Sharp/RecurseSubmodulesException.cs
+++ b/LibGit2Sharp/RecurseSubmodulesException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
namespace LibGit2Sharp
{
@@ -8,7 +10,9 @@ namespace LibGit2Sharp
/// through submodules. The inner exception contains the exception that was
/// initially thrown while operating on the submodule.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class RecurseSubmodulesException : LibGit2SharpException
{
///
@@ -34,6 +38,7 @@ public RecurseSubmodulesException(string message, Exception innerException, stri
InitialRepositoryPath = initialRepositoryPath;
}
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -42,5 +47,6 @@ public RecurseSubmodulesException(string message, Exception innerException, stri
protected RecurseSubmodulesException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
}
}
diff --git a/LibGit2Sharp/RemoveFromIndexException.cs b/LibGit2Sharp/RemoveFromIndexException.cs
index 6d9718c18..37e7daf79 100644
--- a/LibGit2Sharp/RemoveFromIndexException.cs
+++ b/LibGit2Sharp/RemoveFromIndexException.cs
@@ -1,13 +1,16 @@
using System;
-using System.Globalization;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
namespace LibGit2Sharp
{
///
/// The exception that is thrown when a file cannot be removed from the index.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class RemoveFromIndexException : LibGit2SharpException
{
///
@@ -43,6 +46,7 @@ public RemoveFromIndexException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -51,5 +55,6 @@ public RemoveFromIndexException(string message, Exception innerException)
protected RemoveFromIndexException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
}
}
diff --git a/LibGit2Sharp/RepositoryNotFoundException.cs b/LibGit2Sharp/RepositoryNotFoundException.cs
index 2255c0891..2e8deb393 100644
--- a/LibGit2Sharp/RepositoryNotFoundException.cs
+++ b/LibGit2Sharp/RepositoryNotFoundException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
namespace LibGit2Sharp
{
@@ -7,7 +9,9 @@ namespace LibGit2Sharp
/// The exception that is thrown when a is being built with
/// a path that doesn't point at a valid Git repository or workdir.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class RepositoryNotFoundException : LibGit2SharpException
{
///
@@ -42,6 +46,7 @@ public RepositoryNotFoundException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -50,5 +55,6 @@ public RepositoryNotFoundException(string message, Exception innerException)
protected RepositoryNotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
}
}
diff --git a/LibGit2Sharp/UnbornBranchException.cs b/LibGit2Sharp/UnbornBranchException.cs
index 34ef437cb..8f56eed3d 100644
--- a/LibGit2Sharp/UnbornBranchException.cs
+++ b/LibGit2Sharp/UnbornBranchException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
namespace LibGit2Sharp
{
@@ -7,7 +9,9 @@ namespace LibGit2Sharp
/// The exception that is thrown when a operation requiring an existing
/// branch is performed against an unborn branch.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class UnbornBranchException : LibGit2SharpException
{
///
@@ -42,6 +46,7 @@ public UnbornBranchException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -50,5 +55,6 @@ public UnbornBranchException(string message, Exception innerException)
protected UnbornBranchException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
}
}
diff --git a/LibGit2Sharp/UnmatchedPathException.cs b/LibGit2Sharp/UnmatchedPathException.cs
index 7d118346d..daf48db6d 100644
--- a/LibGit2Sharp/UnmatchedPathException.cs
+++ b/LibGit2Sharp/UnmatchedPathException.cs
@@ -1,12 +1,16 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
namespace LibGit2Sharp
{
///
/// The exception that is thrown when an explicit path or a list of explicit paths could not be matched.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class UnmatchedPathException : LibGit2SharpException
{
///
@@ -41,6 +45,7 @@ public UnmatchedPathException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -49,5 +54,6 @@ public UnmatchedPathException(string message, Exception innerException)
protected UnmatchedPathException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
}
}
diff --git a/LibGit2Sharp/UnmergedIndexEntriesException.cs b/LibGit2Sharp/UnmergedIndexEntriesException.cs
index 7594049b1..ca01c256d 100644
--- a/LibGit2Sharp/UnmergedIndexEntriesException.cs
+++ b/LibGit2Sharp/UnmergedIndexEntriesException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -8,7 +10,9 @@ namespace LibGit2Sharp
/// The exception that is thrown when an operation that requires a fully merged index
/// is performed against an index with unmerged entries
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class UnmergedIndexEntriesException : NativeException
{
///
@@ -43,6 +47,7 @@ public UnmergedIndexEntriesException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -51,6 +56,7 @@ public UnmergedIndexEntriesException(string message, Exception innerException)
protected UnmergedIndexEntriesException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal UnmergedIndexEntriesException(string message, GitErrorCategory category)
: base(message, category)
diff --git a/LibGit2Sharp/UserCanceledException.cs b/LibGit2Sharp/UserCanceledException.cs
index ba6458049..0139bdb1c 100644
--- a/LibGit2Sharp/UserCanceledException.cs
+++ b/LibGit2Sharp/UserCanceledException.cs
@@ -1,5 +1,7 @@
using System;
+#if NETFRAMEWORK
using System.Runtime.Serialization;
+#endif
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -7,7 +9,9 @@ namespace LibGit2Sharp
///
/// The exception that is thrown when an operation is canceled.
///
+#if NETFRAMEWORK
[Serializable]
+#endif
public class UserCancelledException : NativeException
{
///
@@ -42,6 +46,7 @@ public UserCancelledException(string message, Exception innerException)
: base(message, innerException)
{ }
+#if NETFRAMEWORK
///
/// Initializes a new instance of the class with a serialized data.
///
@@ -50,6 +55,7 @@ public UserCancelledException(string message, Exception innerException)
protected UserCancelledException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
+#endif
internal UserCancelledException(string message, GitErrorCategory category)
: base(message, category)
From 729ef8d939bc578f3f226761bf53d245d62b7d4b Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Mar 2024 12:51:14 -0400
Subject: [PATCH 119/147] Clean up more analyzer warnings
---
LibGit2Sharp.Tests/CommitFixture.cs | 4 +--
LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs | 4 +--
LibGit2Sharp.Tests/FetchFixture.cs | 28 +++++++++----------
LibGit2Sharp.Tests/FilterBranchFixture.cs | 2 +-
LibGit2Sharp.Tests/FilterFixture.cs | 2 +-
LibGit2Sharp.Tests/MetaFixture.cs | 14 +++++-----
LibGit2Sharp.Tests/NetworkFixture.cs | 8 +++---
LibGit2Sharp.Tests/ReferenceFixture.cs | 2 +-
LibGit2Sharp.Tests/RemoveFixture.cs | 2 +-
LibGit2Sharp.Tests/RepositoryFixture.cs | 4 +--
LibGit2Sharp.Tests/StageFixture.cs | 6 ++--
LibGit2Sharp.Tests/TestHelpers/Constants.cs | 4 +--
LibGit2Sharp.Tests/UnstageFixture.cs | 2 +-
.../desktop/SmartSubtransportFixture.cs | 14 +++++-----
.../AmbiguousSpecificationException.cs | 2 +-
LibGit2Sharp/BareRepositoryException.cs | 2 +-
LibGit2Sharp/BlameHunk.cs | 6 ++--
LibGit2Sharp/BlameHunkCollection.cs | 2 +-
LibGit2Sharp/Blob.cs | 2 +-
LibGit2Sharp/CheckoutConflictException.cs | 2 +-
LibGit2Sharp/Commands/Pull.cs | 3 +-
LibGit2Sharp/Commands/Stage.cs | 2 +-
LibGit2Sharp/Conflict.cs | 6 ++--
LibGit2Sharp/Core/EncodingMarshaler.cs | 16 +++++------
LibGit2Sharp/Core/Ensure.cs | 2 +-
LibGit2Sharp/Core/FileHistory.cs | 2 +-
LibGit2Sharp/Core/FilePathMarshaler.cs | 4 +--
LibGit2Sharp/Core/GitBlame.cs | 2 +-
LibGit2Sharp/Core/GitDiff.cs | 22 +++++++--------
LibGit2Sharp/Core/GitOdbBackend.cs | 2 +-
LibGit2Sharp/Core/GitOdbBackendStream.cs | 4 +--
LibGit2Sharp/Core/GitStrArrayNative.cs | 4 +--
LibGit2Sharp/Core/HistoryRewriter.cs | 2 +-
LibGit2Sharp/Core/NativeMethods.cs | 10 +++----
LibGit2Sharp/Core/Proxy.cs | 20 ++++++-------
LibGit2Sharp/Core/TarWriter.cs | 14 +++++-----
LibGit2Sharp/Core/Utf8Marshaler.cs | 4 +--
LibGit2Sharp/Diff.cs | 5 ++--
LibGit2Sharp/EmptyCommitException.cs | 2 +-
LibGit2Sharp/EntryExistsException.cs | 2 +-
LibGit2Sharp/FetchHead.cs | 2 +-
LibGit2Sharp/Filter.cs | 12 ++++----
LibGit2Sharp/GitObject.cs | 8 +++---
LibGit2Sharp/GlobalSettings.cs | 4 +--
LibGit2Sharp/IndexEntry.cs | 6 ++--
LibGit2Sharp/IndexNameEntry.cs | 6 ++--
LibGit2Sharp/IndexReucEntry.cs | 6 ++--
LibGit2Sharp/InvalidSpecificationException.cs | 2 +-
LibGit2Sharp/LibGit2SharpException.cs | 2 +-
LibGit2Sharp/LockedFileException.cs | 2 +-
.../MergeFetchHeadNotFoundException.cs | 2 +-
LibGit2Sharp/NameConflictException.cs | 2 +-
LibGit2Sharp/NonFastForwardException.cs | 2 +-
LibGit2Sharp/NotFoundException.cs | 2 +-
LibGit2Sharp/Note.cs | 6 ++--
LibGit2Sharp/ObjectDatabase.cs | 18 ++++++------
LibGit2Sharp/ObjectId.cs | 14 +++++-----
LibGit2Sharp/OdbBackend.cs | 2 +-
LibGit2Sharp/PackBuilder.cs | 2 +-
LibGit2Sharp/PeelException.cs | 2 +-
LibGit2Sharp/PushUpdate.cs | 4 +--
LibGit2Sharp/Reference.cs | 8 +++---
LibGit2Sharp/ReferenceCollection.cs | 2 +-
LibGit2Sharp/ReferenceWrapper.cs | 6 ++--
LibGit2Sharp/RemoveFromIndexException.cs | 2 +-
LibGit2Sharp/RenameDetails.cs | 6 ++--
LibGit2Sharp/Repository.cs | 6 ++--
LibGit2Sharp/RepositoryNotFoundException.cs | 2 +-
LibGit2Sharp/Signature.cs | 6 ++--
LibGit2Sharp/SmartSubtransport.cs | 8 +++---
LibGit2Sharp/StashCollection.cs | 8 +++---
LibGit2Sharp/StatusEntry.cs | 6 ++--
LibGit2Sharp/Submodule.cs | 8 +++---
LibGit2Sharp/Tree.cs | 2 +-
LibGit2Sharp/TreeChanges.cs | 4 +--
LibGit2Sharp/TreeEntry.cs | 6 ++--
LibGit2Sharp/TreeEntryDefinition.cs | 6 ++--
LibGit2Sharp/UnbornBranchException.cs | 2 +-
LibGit2Sharp/UnmatchedPathException.cs | 2 +-
LibGit2Sharp/UnmergedIndexEntriesException.cs | 2 +-
LibGit2Sharp/UserCanceledException.cs | 2 +-
LibGit2Sharp/Worktree.cs | 8 +++---
82 files changed, 223 insertions(+), 225 deletions(-)
diff --git a/LibGit2Sharp.Tests/CommitFixture.cs b/LibGit2Sharp.Tests/CommitFixture.cs
index f555e7874..1a849c2df 100644
--- a/LibGit2Sharp.Tests/CommitFixture.cs
+++ b/LibGit2Sharp.Tests/CommitFixture.cs
@@ -406,7 +406,7 @@ public void CanEnumerateCommitsFromATagWhichPointsToABlob()
{
AssertEnumerationOfCommits(
repo => new CommitFilter { IncludeReachableFrom = repo.Tags["point_to_blob"] },
- new string[] { });
+ Array.Empty());
}
[Fact]
@@ -421,7 +421,7 @@ public void CanEnumerateCommitsFromATagWhichPointsToATree()
AssertEnumerationOfCommitsInRepo(repo,
r => new CommitFilter { IncludeReachableFrom = tag },
- new string[] { });
+ Array.Empty());
}
}
diff --git a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
index 0fe7adee1..9212dfa99 100644
--- a/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
+++ b/LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
@@ -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()
@@ -27,7 +27,7 @@ public void ComparingATreeAgainstItselfReturnsNoDifference()
using (var patch = repo.Diff.Compare(tree, tree))
{
Assert.Empty(patch);
- Assert.Equal(String.Empty, patch);
+ Assert.Equal(string.Empty, patch);
}
}
}
diff --git a/LibGit2Sharp.Tests/FetchFixture.cs b/LibGit2Sharp.Tests/FetchFixture.cs
index c0c6f0478..b36da7ccd 100644
--- a/LibGit2Sharp.Tests/FetchFixture.cs
+++ b/LibGit2Sharp.Tests/FetchFixture.cs
@@ -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(), new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
// Verify the expected
expectedFetchState.CheckUpdatedReferences(repo);
@@ -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(), new FetchOptions
{
CredentialsProvider = Constants.PrivateRepoCredentials
}, null);
@@ -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(), new FetchOptions
{
TagFetchMode = TagFetchMode.All,
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
@@ -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(), null, null);
// Verify the number of fetched tags.
Assert.Equal(expectedTagCount, repo.Tags.Count());
@@ -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(), new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
}
}
@@ -223,17 +223,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()
// No pruning when the configuration entry isn't defined
Assert.Null(clonedRepo.Config.Get("fetch.prune"));
- Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
+ Commands.Fetch(clonedRepo, "origin", Array.Empty(), 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("fetch.prune", false);
- Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
+ Commands.Fetch(clonedRepo, "origin", Array.Empty(), 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("fetch.prune", true);
- Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
+ Commands.Fetch(clonedRepo, "origin", Array.Empty(), null, null);
Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
}
}
@@ -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(() => Commands.Fetch(repo, "origin", new string[0], options, null));
+ Assert.Throws(() => Commands.Fetch(repo, "origin", Array.Empty(), options, null));
}
}
@@ -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(), options, null);
}
}
@@ -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(() => Commands.Fetch(repo, "origin", new string[0], options, null));
+ Assert.Throws(() => Commands.Fetch(repo, "origin", Array.Empty(), options, null));
}
}
diff --git a/LibGit2Sharp.Tests/FilterBranchFixture.cs b/LibGit2Sharp.Tests/FilterBranchFixture.cs
index 60aee38f3..2ca3e507a 100644
--- a/LibGit2Sharp.Tests/FilterBranchFixture.cs
+++ b/LibGit2Sharp.Tests/FilterBranchFixture.cs
@@ -234,7 +234,7 @@ public void CanRewriteTreesByInjectingTreeEntry()
AssertSucceedingButNotError();
- Assert.Equal(new Commit[0],
+ Assert.Equal(Array.Empty(),
repo.Commits
.QueryBy(new CommitFilter {IncludeReachableFrom = repo.Branches})
.Where(c => c["README"] != null
diff --git a/LibGit2Sharp.Tests/FilterFixture.cs b/LibGit2Sharp.Tests/FilterFixture.cs
index 832ca0cad..8fd9c8392 100644
--- a/LibGit2Sharp.Tests/FilterFixture.cs
+++ b/LibGit2Sharp.Tests/FilterFixture.cs
@@ -396,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);
diff --git a/LibGit2Sharp.Tests/MetaFixture.cs b/LibGit2Sharp.Tests/MetaFixture.cs
index 5ff76e307..1d0a1d101 100644
--- a/LibGit2Sharp.Tests/MetaFixture.cs
+++ b/LibGit2Sharp.Tests/MetaFixture.cs
@@ -83,7 +83,7 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
var typesWithDebuggerDisplayAndInvalidImplPattern = new List();
IEnumerable libGit2SharpTypes = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
- .Where(t => t.GetTypeInfo().GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Any());
+ .Where(t => t.GetTypeInfo().GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Length != 0);
foreach (Type type in libGit2SharpTypes)
{
@@ -110,7 +110,7 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
}
}
- if (typesWithDebuggerDisplayAndInvalidImplPattern.Any())
+ if (typesWithDebuggerDisplayAndInvalidImplPattern.Count != 0)
{
Assert.Fail(Environment.NewLine + BuildMissingDebuggerDisplayPropertyMessage(typesWithDebuggerDisplayAndInvalidImplPattern));
}
@@ -131,7 +131,7 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
continue;
var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames(type).ToList();
- if (nonVirtualMethodNamesForType.Any())
+ if (nonVirtualMethodNamesForType.Count != 0)
{
nonTestableTypes.Add(type, nonVirtualMethodNamesForType);
continue;
@@ -165,7 +165,7 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
}
}
- if (nonTestableTypes.Any())
+ if (nonTestableTypes.Count != 0)
{
Assert.Fail(Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes));
}
@@ -193,7 +193,7 @@ private static bool MustBeMockable(Type type)
public void EnumsWithFlagsHaveMutuallyExclusiveValues()
{
var flagsEnums = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
- .Where(t => t.GetTypeInfo().IsEnum && t.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any());
+ .Where(t => t.GetTypeInfo().IsEnum && t.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Length != 0);
var overlaps = from t in flagsEnums
from int x in Enum.GetValues(t)
@@ -277,7 +277,7 @@ public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability()
(!m.IsVirtual || m.IsFinal))
.ToList();
- if (nonVirtualGetEnumeratorMethods.Any())
+ if (nonVirtualGetEnumeratorMethods.Count != 0)
{
var sb = new StringBuilder();
@@ -306,7 +306,7 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
.Where(t => t.FullName != "LibGit2Sharp.Core.LeaksContainer")
.ToList();
- if (types.Any())
+ if (types.Count != 0)
{
var sb = new StringBuilder();
diff --git a/LibGit2Sharp.Tests/NetworkFixture.cs b/LibGit2Sharp.Tests/NetworkFixture.cs
index 3a3517432..f4ad922f6 100644
--- a/LibGit2Sharp.Tests/NetworkFixture.cs
+++ b/LibGit2Sharp.Tests/NetworkFixture.cs
@@ -249,7 +249,7 @@ public void CanMergeFetchedRefs()
Assert.False(repo.RetrieveStatus().Any());
Assert.Equal(repo.Lookup("refs/remotes/origin/master~1"), repo.Head.Tip);
- Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null);
+ Commands.Fetch(repo, repo.Head.RemoteName, Array.Empty(), null, null);
MergeOptions mergeOptions = new MergeOptions()
{
@@ -276,7 +276,7 @@ public void CanPruneRefs()
using (var repo = new Repository(clonedRepoPath))
{
repo.Network.Remotes.Add("pruner", clonedRepoPath2);
- Commands.Fetch(repo, "pruner", new string[0], null, null);
+ Commands.Fetch(repo, "pruner", Array.Empty(), null, null);
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);
// Remove the branch from the source repository
@@ -286,11 +286,11 @@ public void CanPruneRefs()
}
// and by default we don't prune it
- Commands.Fetch(repo, "pruner", new string[0], null, null);
+ Commands.Fetch(repo, "pruner", Array.Empty(), null, null);
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);
// but we do when asked by the user
- Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true }, null);
+ Commands.Fetch(repo, "pruner", Array.Empty(), new FetchOptions { Prune = true }, null);
Assert.Null(repo.Refs["refs/remotes/pruner/master"]);
}
}
diff --git a/LibGit2Sharp.Tests/ReferenceFixture.cs b/LibGit2Sharp.Tests/ReferenceFixture.cs
index 186d2e869..ad34d0fb2 100644
--- a/LibGit2Sharp.Tests/ReferenceFixture.cs
+++ b/LibGit2Sharp.Tests/ReferenceFixture.cs
@@ -894,7 +894,7 @@ public void CanHandleInvalidArguments()
Assert.Throws(() => repo.Refs.ReachableFrom(null));
Assert.Throws(() => repo.Refs.ReachableFrom(null, repo.Commits.Take(2)));
Assert.Throws(() => repo.Refs.ReachableFrom(repo.Refs, null));
- Assert.Empty(repo.Refs.ReachableFrom(new Commit[] { }));
+ Assert.Empty(repo.Refs.ReachableFrom(Array.Empty()));
}
}
}
diff --git a/LibGit2Sharp.Tests/RemoveFixture.cs b/LibGit2Sharp.Tests/RemoveFixture.cs
index e97636d9c..921bc417d 100644
--- a/LibGit2Sharp.Tests/RemoveFixture.cs
+++ b/LibGit2Sharp.Tests/RemoveFixture.cs
@@ -182,7 +182,7 @@ public void RemovingFileWithBadParamsThrows()
{
Assert.Throws(() => Commands.Remove(repo, string.Empty));
Assert.Throws(() => Commands.Remove(repo, (string)null));
- Assert.Throws(() => Commands.Remove(repo, new string[] { }));
+ Assert.Throws(() => Commands.Remove(repo, Array.Empty()));
Assert.Throws(() => Commands.Remove(repo, new string[] { null }));
}
}
diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs
index bf27b6091..ef3e72f07 100644
--- a/LibGit2Sharp.Tests/RepositoryFixture.cs
+++ b/LibGit2Sharp.Tests/RepositoryFixture.cs
@@ -212,13 +212,13 @@ public void CanFetchFromRemoteByName()
}
// Perform the actual fetch
- Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
+ Commands.Fetch(repo, remoteName, Array.Empty(), new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
// Verify the expected state
expectedFetchState.CheckUpdatedReferences(repo);
// Now fetch the rest of the tags
- Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
+ Commands.Fetch(repo, remoteName, Array.Empty(), new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
// Verify that the "nearly-dangling" tag is now in the repo.
Tag nearlyDanglingTag = repo.Tags["nearly-dangling"];
diff --git a/LibGit2Sharp.Tests/StageFixture.cs b/LibGit2Sharp.Tests/StageFixture.cs
index 51cb31a51..c087aa7be 100644
--- a/LibGit2Sharp.Tests/StageFixture.cs
+++ b/LibGit2Sharp.Tests/StageFixture.cs
@@ -265,7 +265,7 @@ public void StagingFileWithBadParamsThrows()
{
Assert.Throws(() => Commands.Stage(repo, string.Empty));
Assert.Throws(() => Commands.Stage(repo, (string)null));
- Assert.Throws(() => Commands.Stage(repo, new string[] { }));
+ Assert.Throws(() => Commands.Stage(repo, Array.Empty()));
Assert.Throws(() => Commands.Stage(repo, new string[] { null }));
}
}
@@ -362,7 +362,7 @@ public void IgnoredFilesAreOnlyStagedIfTheyreInTheRepo(string filename, FileStat
using (var repo = new Repository(path))
{
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, ".gitignore"),
- String.Format("{0}\n", filename));
+ string.Format("{0}\n", filename));
Commands.Stage(repo, filename);
Assert.Equal(expected, repo.RetrieveStatus(filename));
@@ -384,7 +384,7 @@ public void CanStageConflictedIgnoredFiles(string filename, FileStatus expected)
using (var repo = new Repository(path))
{
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, ".gitignore"),
- String.Format("{0}\n", filename));
+ string.Format("{0}\n", filename));
Commands.Stage(repo, filename);
Assert.Equal(expected, repo.RetrieveStatus(filename));
diff --git a/LibGit2Sharp.Tests/TestHelpers/Constants.cs b/LibGit2Sharp.Tests/TestHelpers/Constants.cs
index b5cd96d7e..d8c14dbca 100644
--- a/LibGit2Sharp.Tests/TestHelpers/Constants.cs
+++ b/LibGit2Sharp.Tests/TestHelpers/Constants.cs
@@ -61,10 +61,10 @@ public static string BuildPath()
if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath))
{
Trace.TraceInformation("{0} environment variable detected", LibGit2TestPath);
- tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as String;
+ tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as string;
}
- if (String.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
+ if (string.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
{
Trace.TraceInformation("Using default test path value");
tempPath = Path.GetTempPath();
diff --git a/LibGit2Sharp.Tests/UnstageFixture.cs b/LibGit2Sharp.Tests/UnstageFixture.cs
index a5dc143d3..1eeee0e72 100644
--- a/LibGit2Sharp.Tests/UnstageFixture.cs
+++ b/LibGit2Sharp.Tests/UnstageFixture.cs
@@ -251,7 +251,7 @@ public void UnstagingFileWithBadParamsThrows()
{
Assert.Throws(() => Commands.Unstage(repo, string.Empty));
Assert.Throws(() => Commands.Unstage(repo, (string)null));
- Assert.Throws(() => Commands.Unstage(repo, new string[] { }));
+ Assert.Throws(() => Commands.Unstage(repo, Array.Empty()));
Assert.Throws(() => Commands.Unstage(repo, new string[] { null }));
}
}
diff --git a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
index bc7e7ac15..4e3b03ce3 100644
--- a/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
+++ b/LibGit2Sharp.Tests/desktop/SmartSubtransportFixture.cs
@@ -61,7 +61,7 @@ public void CustomSmartSubtransportTest(string scheme, string url)
}
// Perform the actual fetch
- Commands.Fetch(repo, remoteName, new string[0],
+ Commands.Fetch(repo, remoteName, Array.Empty(),
new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto },
null);
@@ -161,29 +161,29 @@ public void CannotUnregisterTwice()
private class MockSmartSubtransport : RpcSmartSubtransport
{
- protected override SmartSubtransportStream Action(String url, GitSmartSubtransportAction action)
+ protected override SmartSubtransportStream Action(string url, GitSmartSubtransportAction action)
{
- String endpointUrl, contentType = null;
+ string endpointUrl, contentType = null;
bool isPost = false;
switch (action)
{
case GitSmartSubtransportAction.UploadPackList:
- endpointUrl = String.Concat(url, "/info/refs?service=git-upload-pack");
+ endpointUrl = string.Concat(url, "/info/refs?service=git-upload-pack");
break;
case GitSmartSubtransportAction.UploadPack:
- endpointUrl = String.Concat(url, "/git-upload-pack");
+ endpointUrl = string.Concat(url, "/git-upload-pack");
contentType = "application/x-git-upload-pack-request";
isPost = true;
break;
case GitSmartSubtransportAction.ReceivePackList:
- endpointUrl = String.Concat(url, "/info/refs?service=git-receive-pack");
+ endpointUrl = string.Concat(url, "/info/refs?service=git-receive-pack");
break;
case GitSmartSubtransportAction.ReceivePack:
- endpointUrl = String.Concat(url, "/git-receive-pack");
+ endpointUrl = string.Concat(url, "/git-receive-pack");
contentType = "application/x-git-receive-pack-request";
isPost = true;
break;
diff --git a/LibGit2Sharp/AmbiguousSpecificationException.cs b/LibGit2Sharp/AmbiguousSpecificationException.cs
index 4903d9df9..b5ddd7963 100644
--- a/LibGit2Sharp/AmbiguousSpecificationException.cs
+++ b/LibGit2Sharp/AmbiguousSpecificationException.cs
@@ -31,7 +31,7 @@ public AmbiguousSpecificationException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public AmbiguousSpecificationException(string format, params object[] args)
: base(string.Format(format, args))
diff --git a/LibGit2Sharp/BareRepositoryException.cs b/LibGit2Sharp/BareRepositoryException.cs
index 461204acd..412e5e4d4 100644
--- a/LibGit2Sharp/BareRepositoryException.cs
+++ b/LibGit2Sharp/BareRepositoryException.cs
@@ -32,7 +32,7 @@ public BareRepositoryException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public BareRepositoryException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/BlameHunk.cs b/LibGit2Sharp/BlameHunk.cs
index 553efb14e..4feac239d 100644
--- a/LibGit2Sharp/BlameHunk.cs
+++ b/LibGit2Sharp/BlameHunk.cs
@@ -135,10 +135,10 @@ public bool Equals(BlameHunk other)
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as BlameHunk);
diff --git a/LibGit2Sharp/BlameHunkCollection.cs b/LibGit2Sharp/BlameHunkCollection.cs
index 869daf527..2766ee7a6 100644
--- a/LibGit2Sharp/BlameHunkCollection.cs
+++ b/LibGit2Sharp/BlameHunkCollection.cs
@@ -82,7 +82,7 @@ public virtual BlameHunk HunkForLine(int line)
{
return hunk;
}
- throw new ArgumentOutOfRangeException("line", "No hunk for that line");
+ throw new ArgumentOutOfRangeException(nameof(line), "No hunk for that line");
}
///
diff --git a/LibGit2Sharp/Blob.cs b/LibGit2Sharp/Blob.cs
index d3cccf6ac..29ef8d812 100644
--- a/LibGit2Sharp/Blob.cs
+++ b/LibGit2Sharp/Blob.cs
@@ -13,7 +13,7 @@ namespace LibGit2Sharp
///
public class Blob : GitObject
{
- private readonly ILazy lazySize;
+ private readonly ILazy lazySize;
private readonly ILazy lazyIsBinary;
///
diff --git a/LibGit2Sharp/CheckoutConflictException.cs b/LibGit2Sharp/CheckoutConflictException.cs
index 23b97143e..67dc8d2cc 100644
--- a/LibGit2Sharp/CheckoutConflictException.cs
+++ b/LibGit2Sharp/CheckoutConflictException.cs
@@ -33,7 +33,7 @@ public CheckoutConflictException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public CheckoutConflictException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/Commands/Pull.cs b/LibGit2Sharp/Commands/Pull.cs
index bee1bbbda..f0a68fe9b 100644
--- a/LibGit2Sharp/Commands/Pull.cs
+++ b/LibGit2Sharp/Commands/Pull.cs
@@ -1,5 +1,4 @@
using System;
-using LibGit2Sharp;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
@@ -34,7 +33,7 @@ public static MergeResult Pull(Repository repository, Signature merger, PullOpti
throw new LibGit2SharpException("No upstream remote for the current branch.");
}
- Commands.Fetch(repository, currentBranch.RemoteName, new string[0], options.FetchOptions, null);
+ Commands.Fetch(repository, currentBranch.RemoteName, Array.Empty(), options.FetchOptions, null);
return repository.MergeFetchedRefs(merger, options.MergeOptions);
}
}
diff --git a/LibGit2Sharp/Commands/Stage.cs b/LibGit2Sharp/Commands/Stage.cs
index a1febafcb..d11bf6f76 100644
--- a/LibGit2Sharp/Commands/Stage.cs
+++ b/LibGit2Sharp/Commands/Stage.cs
@@ -237,7 +237,7 @@ public static void Move(IRepository repository, IEnumerable sourcePaths,
if (batch.Count == 0)
{
- throw new ArgumentNullException("sourcePaths");
+ throw new ArgumentNullException(nameof(sourcePaths));
}
foreach (KeyValuePair, Tuple> keyValuePair in batch)
diff --git a/LibGit2Sharp/Conflict.cs b/LibGit2Sharp/Conflict.cs
index 252535af1..705f66d15 100644
--- a/LibGit2Sharp/Conflict.cs
+++ b/LibGit2Sharp/Conflict.cs
@@ -61,12 +61,12 @@ public virtual IndexEntry Theirs
}
///
- /// Determines whether the specified is
+ /// Determines whether the specified is
/// equal to the current .
///
- /// The to compare with
+ /// The to compare with
/// the current .
- /// true if the specified is equal
+ /// true if the specified is equal
/// to the current ; otherwise,
/// false.
public override bool Equals(object obj)
diff --git a/LibGit2Sharp/Core/EncodingMarshaler.cs b/LibGit2Sharp/Core/EncodingMarshaler.cs
index 0cafd9aa1..cb02c649b 100644
--- a/LibGit2Sharp/Core/EncodingMarshaler.cs
+++ b/LibGit2Sharp/Core/EncodingMarshaler.cs
@@ -32,7 +32,7 @@ public int GetNativeDataSize()
return -1;
}
- public virtual IntPtr MarshalManagedToNative(Object managedObj)
+ public virtual IntPtr MarshalManagedToNative(object managedObj)
{
if (managedObj == null)
{
@@ -51,14 +51,14 @@ public virtual IntPtr MarshalManagedToNative(Object managedObj)
return FromManaged(encoding, str);
}
- public virtual Object MarshalNativeToManaged(IntPtr pNativeData)
+ public virtual object MarshalNativeToManaged(IntPtr pNativeData)
{
return FromNative(encoding, pNativeData);
}
#endregion
- public static unsafe IntPtr FromManaged(Encoding encoding, String value)
+ public static unsafe IntPtr FromManaged(Encoding encoding, string value)
{
if (encoding == null || value == null)
{
@@ -114,10 +114,10 @@ public static unsafe string FromNative(Encoding encoding, byte* pNativeData)
if (walk == start)
{
- return String.Empty;
+ return string.Empty;
}
- return new String((sbyte*)pNativeData, 0, (int)(walk - start), encoding);
+ return new string((sbyte*)pNativeData, 0, (int)(walk - start), encoding);
}
public static unsafe string FromNative(Encoding encoding, IntPtr pNativeData, int length)
@@ -129,10 +129,10 @@ public static unsafe string FromNative(Encoding encoding, IntPtr pNativeData, in
if (length == 0)
{
- return String.Empty;
+ return string.Empty;
}
- return new String((sbyte*)pNativeData.ToPointer(), 0, length, encoding);
+ return new string((sbyte*)pNativeData.ToPointer(), 0, length, encoding);
}
public static string FromBuffer(Encoding encoding, byte[] buffer)
@@ -160,7 +160,7 @@ public static string FromBuffer(Encoding encoding, byte[] buffer, int length)
if (length == 0)
{
- return String.Empty;
+ return string.Empty;
}
return encoding.GetString(buffer, 0, length);
diff --git a/LibGit2Sharp/Core/Ensure.cs b/LibGit2Sharp/Core/Ensure.cs
index 3cf03d24b..7adea961a 100644
--- a/LibGit2Sharp/Core/Ensure.cs
+++ b/LibGit2Sharp/Core/Ensure.cs
@@ -49,7 +49,7 @@ public static void ArgumentNotNullOrEmptyString(string argumentValue, string arg
{
ArgumentNotNull(argumentValue, argumentName);
- if (String.IsNullOrWhiteSpace (argumentValue))
+ if (string.IsNullOrWhiteSpace (argumentValue))
{
throw new ArgumentException("String cannot be empty", argumentName);
}
diff --git a/LibGit2Sharp/Core/FileHistory.cs b/LibGit2Sharp/Core/FileHistory.cs
index 5c10a1a24..5775d0ab8 100644
--- a/LibGit2Sharp/Core/FileHistory.cs
+++ b/LibGit2Sharp/Core/FileHistory.cs
@@ -74,7 +74,7 @@ internal FileHistory(Repository repo, string path, CommitFilter queryFilter)
if (!AllowedSortStrategies.Contains(queryFilter.SortBy))
{
throw new ArgumentException("Unsupported sort strategy. Only 'Topological', 'Time', or 'Topological | Time' are allowed.",
- "queryFilter");
+ nameof(queryFilter));
}
_repo = repo;
diff --git a/LibGit2Sharp/Core/FilePathMarshaler.cs b/LibGit2Sharp/Core/FilePathMarshaler.cs
index 209254ac5..af6afb048 100644
--- a/LibGit2Sharp/Core/FilePathMarshaler.cs
+++ b/LibGit2Sharp/Core/FilePathMarshaler.cs
@@ -57,7 +57,7 @@ internal class StrictFilePathMarshaler : StrictUtf8Marshaler
#region ICustomMarshaler
- public override IntPtr MarshalManagedToNative(Object managedObj)
+ public override IntPtr MarshalManagedToNative(object managedObj)
{
if (null == managedObj)
{
@@ -105,7 +105,7 @@ internal class LaxFilePathMarshaler : LaxUtf8Marshaler
#region ICustomMarshaler
- public override Object MarshalNativeToManaged(IntPtr pNativeData)
+ public override object MarshalNativeToManaged(IntPtr pNativeData)
{
return FromNative(pNativeData);
}
diff --git a/LibGit2Sharp/Core/GitBlame.cs b/LibGit2Sharp/Core/GitBlame.cs
index df99f44b7..b2683cc73 100644
--- a/LibGit2Sharp/Core/GitBlame.cs
+++ b/LibGit2Sharp/Core/GitBlame.cs
@@ -46,7 +46,7 @@ internal class git_blame_options
public uint version = 1;
public GitBlameOptionFlags flags;
- public UInt16 min_match_characters;
+ public ushort min_match_characters;
public git_oid newest_commit;
public git_oid oldest_commit;
public UIntPtr min_line;
diff --git a/LibGit2Sharp/Core/GitDiff.cs b/LibGit2Sharp/Core/GitDiff.cs
index cc1ab1af1..44679124d 100644
--- a/LibGit2Sharp/Core/GitDiff.cs
+++ b/LibGit2Sharp/Core/GitDiff.cs
@@ -231,7 +231,7 @@ internal class GitDiffOptions : IDisposable
public uint ContextLines;
public uint InterhunkLines;
public ushort IdAbbrev;
- public Int64 MaxSize;
+ public long MaxSize;
public IntPtr OldPrefixString;
public IntPtr NewPrefixString;
@@ -255,10 +255,10 @@ internal unsafe struct git_diff_file
{
public git_oid Id;
public char* Path;
- public Int64 Size;
+ public long Size;
public GitDiffFlags Flags;
- public UInt16 Mode;
- public UInt16 IdAbbrev;
+ public ushort Mode;
+ public ushort IdAbbrev;
}
[StructLayout(LayoutKind.Sequential)]
@@ -266,8 +266,8 @@ internal unsafe struct git_diff_delta
{
public ChangeKind status;
public GitDiffFlags flags;
- public UInt16 similarity;
- public UInt16 nfiles;
+ public ushort similarity;
+ public ushort nfiles;
public git_diff_file old_file;
public git_diff_file new_file;
}
@@ -293,7 +293,7 @@ internal class GitDiffLine
public int NewLineNo;
public int NumLines;
public UIntPtr contentLen;
- public Int64 contentOffset;
+ public long contentOffset;
public IntPtr content;
}
@@ -371,10 +371,10 @@ internal class GitDiffFindOptions
{
public uint Version = 1;
public GitDiffFindFlags Flags;
- public UInt16 RenameThreshold;
- public UInt16 RenameFromRewriteThreshold;
- public UInt16 CopyThreshold;
- public UInt16 BreakRewriteThreshold;
+ public ushort RenameThreshold;
+ public ushort RenameFromRewriteThreshold;
+ public ushort CopyThreshold;
+ public ushort BreakRewriteThreshold;
public UIntPtr RenameLimit;
// TODO
diff --git a/LibGit2Sharp/Core/GitOdbBackend.cs b/LibGit2Sharp/Core/GitOdbBackend.cs
index 6f017542d..c102c94eb 100644
--- a/LibGit2Sharp/Core/GitOdbBackend.cs
+++ b/LibGit2Sharp/Core/GitOdbBackend.cs
@@ -137,7 +137,7 @@ public delegate int write_callback(
public delegate int writestream_callback(
out IntPtr stream_out,
IntPtr backend,
- Int64 length,
+ long length,
GitObjectType type);
///
diff --git a/LibGit2Sharp/Core/GitOdbBackendStream.cs b/LibGit2Sharp/Core/GitOdbBackendStream.cs
index 984274f04..14b126c7a 100644
--- a/LibGit2Sharp/Core/GitOdbBackendStream.cs
+++ b/LibGit2Sharp/Core/GitOdbBackendStream.cs
@@ -22,8 +22,8 @@ static GitOdbBackendStream()
public GitOdbBackendStreamMode Mode;
public IntPtr HashCtx;
- public Int64 DeclaredSize;
- public Int64 ReceivedBytes;
+ public long DeclaredSize;
+ public long ReceivedBytes;
public read_callback Read;
public write_callback Write;
diff --git a/LibGit2Sharp/Core/GitStrArrayNative.cs b/LibGit2Sharp/Core/GitStrArrayNative.cs
index 8813f8e6e..01cd18e6e 100644
--- a/LibGit2Sharp/Core/GitStrArrayNative.cs
+++ b/LibGit2Sharp/Core/GitStrArrayNative.cs
@@ -15,11 +15,11 @@ internal struct GitStrArrayNative : IDisposable
///
/// Enumerates each string from the array using the UTF-8 marshaler.
///
- public String[] ReadStrings()
+ public string[] ReadStrings()
{
var count = checked((int)Array.Count.ToUInt32());
- String[] toReturn = new String[count];
+ string[] toReturn = new string[count];
for (int i = 0; i < count; i++)
{
diff --git a/LibGit2Sharp/Core/HistoryRewriter.cs b/LibGit2Sharp/Core/HistoryRewriter.cs
index c4cc2be8b..094d5ca1c 100644
--- a/LibGit2Sharp/Core/HistoryRewriter.cs
+++ b/LibGit2Sharp/Core/HistoryRewriter.cs
@@ -170,7 +170,7 @@ private Reference RewriteReference(
if (repo.Refs.Resolve(backupName) != null)
{
- throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture,
+ throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
"Can't back up reference '{0}' - '{1}' already exists",
oldRef.CanonicalName,
backupName));
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index cd3e1de7a..e8e59843e 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -177,11 +177,11 @@ internal static extern int git_error_set_str(
internal static extern void git_error_set_oom();
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe UInt32 git_blame_get_hunk_count(git_blame* blame);
+ internal static extern unsafe uint git_blame_get_hunk_count(git_blame* blame);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe git_blame_hunk* git_blame_get_hunk_byindex(
- git_blame* blame, UInt32 index);
+ git_blame* blame, uint index);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_blame_file(
@@ -227,7 +227,7 @@ internal static extern unsafe int git_blob_filtered_content(
internal static extern unsafe IntPtr git_blob_rawcontent(git_object* blob);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe Int64 git_blob_rawsize(git_object* blob);
+ internal static extern unsafe long git_blob_rawsize(git_object* blob);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_branch_create_from_annotated(
@@ -1078,7 +1078,7 @@ internal static extern unsafe int git_odb_foreach(
IntPtr payload);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe int git_odb_open_wstream(out git_odb_stream* stream, git_odb* odb, Int64 size, GitObjectType type);
+ internal static extern unsafe int git_odb_open_wstream(out git_odb_stream* stream, git_odb* odb, long size, GitObjectType type);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe void git_odb_free(git_odb* odb);
@@ -1175,7 +1175,7 @@ internal static extern unsafe int git_packbuilder_insert_tree(
internal static extern unsafe UIntPtr git_packbuilder_object_count(git_packbuilder* packbuilder);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe UInt32 git_packbuilder_set_threads(git_packbuilder* packbuilder, UInt32 numThreads);
+ internal static extern unsafe uint git_packbuilder_set_threads(git_packbuilder* packbuilder, uint numThreads);
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern unsafe int git_packbuilder_write(
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 50cefc0df..18e952e68 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -86,7 +86,7 @@ public static unsafe UnmanagedMemoryStream git_blob_filtered_content_stream(Repo
new[] { buf });
}
- public static unsafe UnmanagedMemoryStream git_blob_rawcontent_stream(RepositoryHandle repo, ObjectId id, Int64 size)
+ public static unsafe UnmanagedMemoryStream git_blob_rawcontent_stream(RepositoryHandle repo, ObjectId id, long size)
{
var handle = new ObjectSafeWrapper(id, repo, throwIfMissing: true).ObjectPtr;
return new RawContentStream(handle, h => NativeMethods.git_blob_rawcontent(h), h => size);
@@ -341,7 +341,7 @@ public static unsafe string git_commit_create_buffer(
using (var treeHandle = Proxy.git_object_lookup(tree.repo.Handle, tree.Id, GitObjectType.Tree))
using (var buf = new GitBuf())
{
- ObjectHandle[] handles = new ObjectHandle[0];
+ ObjectHandle[] handles = Array.Empty();
try
{
handles = parents.Select(c => Proxy.git_object_lookup(c.repo.Handle, c.Id, GitObjectType.Commit)).ToArray();
@@ -871,7 +871,7 @@ public static int git_error_set_str(GitErrorCategory error_class, Exception exce
}
}
- public static int git_error_set_str(GitErrorCategory error_class, String errorString)
+ public static int git_error_set_str(GitErrorCategory error_class, string errorString)
{
return NativeMethods.git_error_set_str(error_class, errorString);
}
@@ -2368,7 +2368,7 @@ public static unsafe IEnumerable git_remote_ls(Repository repository,
}
var refs = directRefs.Values.ToList();
- refs.Sort((r1, r2) => String.CompareOrdinal(r1.CanonicalName, r2.CanonicalName));
+ refs.Sort((r1, r2) => string.CompareOrdinal(r1.CanonicalName, r2.CanonicalName));
return refs;
}
@@ -3211,7 +3211,7 @@ public static void git_trace_set(LogLevel level, NativeMethods.git_trace_cb call
#region git_transport_
- public static void git_transport_register(String prefix, IntPtr transport_cb, IntPtr param)
+ public static void git_transport_register(string prefix, IntPtr transport_cb, IntPtr param)
{
int res = NativeMethods.git_transport_register(prefix, transport_cb, param);
@@ -3224,7 +3224,7 @@ public static void git_transport_register(String prefix, IntPtr transport_cb, In
Ensure.ZeroResult(res);
}
- public static void git_transport_unregister(String prefix)
+ public static void git_transport_unregister(string prefix)
{
int res = NativeMethods.git_transport_unregister(prefix);
@@ -3707,7 +3707,7 @@ private static ICollection git_foreach(
if (ignoredErrorCodes != null && ignoredErrorCodes.Contains((GitErrorCode)res))
{
- return new TResult[0];
+ return Array.Empty();
}
Ensure.ZeroResult(res);
@@ -3728,7 +3728,7 @@ private static ICollection git_foreach(
if (ignoredErrorCodes != null && ignoredErrorCodes.Contains((GitErrorCode)res))
{
- return new TResult[0];
+ return Array.Empty();
}
Ensure.ZeroResult(res);
@@ -3749,7 +3749,7 @@ private static ICollection git_foreach(
if (ignoredErrorCodes != null && ignoredErrorCodes.Contains((GitErrorCode)res))
{
- return new TResult[0];
+ return Array.Empty();
}
Ensure.ZeroResult(res);
@@ -3772,7 +3772,7 @@ private static ICollection git_foreach(
if (ignoredErrorCodes != null && ignoredErrorCodes.Contains((GitErrorCode)res))
{
- return new TResult[0];
+ return Array.Empty();
}
Ensure.ZeroResult(res);
diff --git a/LibGit2Sharp/Core/TarWriter.cs b/LibGit2Sharp/Core/TarWriter.cs
index 609449316..0a051b9e6 100644
--- a/LibGit2Sharp/Core/TarWriter.cs
+++ b/LibGit2Sharp/Core/TarWriter.cs
@@ -301,31 +301,31 @@ public UsTarHeader(
if (userName.Length > 32)
{
- throw new ArgumentException("ustar userName cannot be longer than 32 characters.", "userName");
+ throw new ArgumentException("ustar userName cannot be longer than 32 characters.", nameof(userName));
}
if (groupName.Length > 32)
{
- throw new ArgumentException("ustar groupName cannot be longer than 32 characters.", "groupName");
+ throw new ArgumentException("ustar groupName cannot be longer than 32 characters.", nameof(groupName));
}
if (userId.Length > 7)
{
- throw new ArgumentException("ustar userId cannot be longer than 7 characters.", "userId");
+ throw new ArgumentException("ustar userId cannot be longer than 7 characters.", nameof(userId));
}
if (groupId.Length > 7)
{
- throw new ArgumentException("ustar groupId cannot be longer than 7 characters.", "groupId");
+ throw new ArgumentException("ustar groupId cannot be longer than 7 characters.", nameof(groupId));
}
if (deviceMajorNumber.Length > 7)
{
- throw new ArgumentException("ustar deviceMajorNumber cannot be longer than 7 characters.", "deviceMajorNumber");
+ throw new ArgumentException("ustar deviceMajorNumber cannot be longer than 7 characters.", nameof(deviceMajorNumber));
}
if (deviceMinorNumber.Length > 7)
{
- throw new ArgumentException("ustar deviceMinorNumber cannot be longer than 7 characters.", "deviceMinorNumber");
+ throw new ArgumentException("ustar deviceMinorNumber cannot be longer than 7 characters.", nameof(deviceMinorNumber));
}
if (link.Length > 100)
{
- throw new ArgumentException("ustar link cannot be longer than 100 characters.", "link");
+ throw new ArgumentException("ustar link cannot be longer than 100 characters.", nameof(link));
}
#endregion
diff --git a/LibGit2Sharp/Core/Utf8Marshaler.cs b/LibGit2Sharp/Core/Utf8Marshaler.cs
index a6fddb808..54e0086cb 100644
--- a/LibGit2Sharp/Core/Utf8Marshaler.cs
+++ b/LibGit2Sharp/Core/Utf8Marshaler.cs
@@ -67,7 +67,7 @@ public static ICustomMarshaler GetInstance(string cookie)
#region ICustomMarshaler
- public override Object MarshalNativeToManaged(IntPtr pNativeData)
+ public override object MarshalNativeToManaged(IntPtr pNativeData)
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
"{0} cannot be used to retrieve data from libgit2.",
@@ -76,7 +76,7 @@ public override Object MarshalNativeToManaged(IntPtr pNativeData)
#endregion
- public static IntPtr FromManaged(String value)
+ public static IntPtr FromManaged(string value)
{
return FromManaged(encoding, value);
}
diff --git a/LibGit2Sharp/Diff.cs b/LibGit2Sharp/Diff.cs
index 087ee8d6d..857eb8ed1 100644
--- a/LibGit2Sharp/Diff.cs
+++ b/LibGit2Sharp/Diff.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Globalization;
using System.Linq;
using System.Text;
using LibGit2Sharp.Core;
@@ -546,7 +545,7 @@ private DiffHandle BuildDiffList(
MatchedPathsAggregator matchedPaths = null;
- // We can't match paths unless we've got something to match
+ // We can't match paths unless we've got something to match
// against and we're told to do so.
if (filePaths != null && explicitPathsOptions != null)
{
@@ -653,7 +652,7 @@ private static void DispatchUnmatchedPaths(
List unmatchedPaths = (filePaths != null ?
filePaths.Except(matchedPaths) : Enumerable.Empty()).ToList();
- if (!unmatchedPaths.Any())
+ if (unmatchedPaths.Count == 0)
{
return;
}
diff --git a/LibGit2Sharp/EmptyCommitException.cs b/LibGit2Sharp/EmptyCommitException.cs
index 0c247bec7..00d1081e5 100644
--- a/LibGit2Sharp/EmptyCommitException.cs
+++ b/LibGit2Sharp/EmptyCommitException.cs
@@ -31,7 +31,7 @@ public EmptyCommitException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public EmptyCommitException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/EntryExistsException.cs b/LibGit2Sharp/EntryExistsException.cs
index 8039f5edd..3ebfbdfba 100644
--- a/LibGit2Sharp/EntryExistsException.cs
+++ b/LibGit2Sharp/EntryExistsException.cs
@@ -32,7 +32,7 @@ public EntryExistsException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public EntryExistsException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/FetchHead.cs b/LibGit2Sharp/FetchHead.cs
index 456abedc2..812865cf3 100644
--- a/LibGit2Sharp/FetchHead.cs
+++ b/LibGit2Sharp/FetchHead.cs
@@ -61,7 +61,7 @@ public virtual GitObject Target
/// The URL of the remote repository this
/// has been built from.
///
- public virtual String Url { get; private set; }
+ public virtual string Url { get; private set; }
///
/// Determines if this fetch head entry has been explicitly fetched.
diff --git a/LibGit2Sharp/Filter.cs b/LibGit2Sharp/Filter.cs
index 5a46e12b5..50f5fe8c5 100644
--- a/LibGit2Sharp/Filter.cs
+++ b/LibGit2Sharp/Filter.cs
@@ -165,10 +165,10 @@ protected virtual void Smudge(string path, string root, Stream input, Stream out
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as Filter);
@@ -306,7 +306,7 @@ int StreamCloseCallback(IntPtr stream)
if(!activeStreams.TryGetValue(stream, out state))
{
- throw new ArgumentException("Unknown stream pointer", "stream");
+ throw new ArgumentException("Unknown stream pointer", nameof(stream));
}
Ensure.ArgumentIsExpectedIntPtr(stream, state.thisPtr, "stream");
@@ -339,7 +339,7 @@ void StreamFreeCallback(IntPtr stream)
if (!activeStreams.TryRemove(stream, out state))
{
- throw new ArgumentException("Double free or invalid stream pointer", "stream");
+ throw new ArgumentException("Double free or invalid stream pointer", nameof(stream));
}
Ensure.ArgumentIsExpectedIntPtr(stream, state.thisPtr, "stream");
@@ -365,7 +365,7 @@ unsafe int StreamWriteCallback(IntPtr stream, IntPtr buffer, UIntPtr len)
if (!activeStreams.TryGetValue(stream, out state))
{
- throw new ArgumentException("Invalid or already freed stream pointer", "stream");
+ throw new ArgumentException("Invalid or already freed stream pointer", nameof(stream));
}
Ensure.ArgumentIsExpectedIntPtr(stream, state.thisPtr, "stream");
diff --git a/LibGit2Sharp/GitObject.cs b/LibGit2Sharp/GitObject.cs
index 539fe6f8b..f9813a3ea 100644
--- a/LibGit2Sharp/GitObject.cs
+++ b/LibGit2Sharp/GitObject.cs
@@ -129,10 +129,10 @@ public virtual T Peel() where T : GitObject
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as GitObject);
@@ -180,7 +180,7 @@ public override int GetHashCode()
}
///
- /// Returns the , a representation of the current .
+ /// Returns the , a representation of the current .
///
/// The that represents the current .
public override string ToString()
diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs
index 31cba0965..bf7875f96 100644
--- a/LibGit2Sharp/GlobalSettings.cs
+++ b/LibGit2Sharp/GlobalSettings.cs
@@ -247,9 +247,9 @@ public static FilterRegistration RegisterFilter(Filter filter, int priority)
Ensure.ArgumentNotNull(filter, "filter");
if (priority < FilterRegistration.FilterPriorityMin || priority > FilterRegistration.FilterPriorityMax)
{
- throw new ArgumentOutOfRangeException("priority",
+ throw new ArgumentOutOfRangeException(nameof(priority),
priority,
- String.Format(System.Globalization.CultureInfo.InvariantCulture,
+ string.Format(System.Globalization.CultureInfo.InvariantCulture,
"Filter priorities must be within the inclusive range of [{0}, {1}].",
FilterRegistration.FilterPriorityMin,
FilterRegistration.FilterPriorityMax));
diff --git a/LibGit2Sharp/IndexEntry.cs b/LibGit2Sharp/IndexEntry.cs
index e07e284b7..554d9a9f1 100644
--- a/LibGit2Sharp/IndexEntry.cs
+++ b/LibGit2Sharp/IndexEntry.cs
@@ -60,10 +60,10 @@ internal static unsafe IndexEntry BuildFromPtr(git_index_entry* entry)
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as IndexEntry);
diff --git a/LibGit2Sharp/IndexNameEntry.cs b/LibGit2Sharp/IndexNameEntry.cs
index 79b3f6993..40c202acc 100644
--- a/LibGit2Sharp/IndexNameEntry.cs
+++ b/LibGit2Sharp/IndexNameEntry.cs
@@ -63,10 +63,10 @@ internal static unsafe IndexNameEntry BuildFromPtr(git_index_name_entry* entry)
public virtual string Theirs { get; private set; }
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as IndexNameEntry);
diff --git a/LibGit2Sharp/IndexReucEntry.cs b/LibGit2Sharp/IndexReucEntry.cs
index 583df95ba..becd20122 100644
--- a/LibGit2Sharp/IndexReucEntry.cs
+++ b/LibGit2Sharp/IndexReucEntry.cs
@@ -88,10 +88,10 @@ internal static unsafe IndexReucEntry BuildFromPtr(git_index_reuc_entry* entry)
public virtual Mode TheirMode { get; private set; }
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as IndexReucEntry);
diff --git a/LibGit2Sharp/InvalidSpecificationException.cs b/LibGit2Sharp/InvalidSpecificationException.cs
index 573a8a1db..d9625dc32 100644
--- a/LibGit2Sharp/InvalidSpecificationException.cs
+++ b/LibGit2Sharp/InvalidSpecificationException.cs
@@ -34,7 +34,7 @@ public InvalidSpecificationException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public InvalidSpecificationException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/LibGit2SharpException.cs b/LibGit2Sharp/LibGit2SharpException.cs
index e5d90f61f..0518fa757 100644
--- a/LibGit2Sharp/LibGit2SharpException.cs
+++ b/LibGit2Sharp/LibGit2SharpException.cs
@@ -40,7 +40,7 @@ public LibGit2SharpException(string message, Exception innerException)
///
/// Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public LibGit2SharpException(string format, params object[] args)
: base(string.Format(CultureInfo.InvariantCulture, format, args))
diff --git a/LibGit2Sharp/LockedFileException.cs b/LibGit2Sharp/LockedFileException.cs
index d58c8dbec..b38f40496 100644
--- a/LibGit2Sharp/LockedFileException.cs
+++ b/LibGit2Sharp/LockedFileException.cs
@@ -31,7 +31,7 @@ public LockedFileException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public LockedFileException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/MergeFetchHeadNotFoundException.cs b/LibGit2Sharp/MergeFetchHeadNotFoundException.cs
index 34b6b71aa..d7d761c1d 100644
--- a/LibGit2Sharp/MergeFetchHeadNotFoundException.cs
+++ b/LibGit2Sharp/MergeFetchHeadNotFoundException.cs
@@ -30,7 +30,7 @@ public MergeFetchHeadNotFoundException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public MergeFetchHeadNotFoundException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/NameConflictException.cs b/LibGit2Sharp/NameConflictException.cs
index 0f4dde744..0517f2550 100644
--- a/LibGit2Sharp/NameConflictException.cs
+++ b/LibGit2Sharp/NameConflictException.cs
@@ -31,7 +31,7 @@ public NameConflictException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public NameConflictException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/NonFastForwardException.cs b/LibGit2Sharp/NonFastForwardException.cs
index f63e2eb1d..d8ed8f474 100644
--- a/LibGit2Sharp/NonFastForwardException.cs
+++ b/LibGit2Sharp/NonFastForwardException.cs
@@ -32,7 +32,7 @@ public NonFastForwardException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public NonFastForwardException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/NotFoundException.cs b/LibGit2Sharp/NotFoundException.cs
index 4aefe3f8a..f282c4340 100644
--- a/LibGit2Sharp/NotFoundException.cs
+++ b/LibGit2Sharp/NotFoundException.cs
@@ -31,7 +31,7 @@ public NotFoundException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public NotFoundException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/Note.cs b/LibGit2Sharp/Note.cs
index 1df0125e4..2ffc89690 100644
--- a/LibGit2Sharp/Note.cs
+++ b/LibGit2Sharp/Note.cs
@@ -59,10 +59,10 @@ internal static Note BuildFromPtr(NoteHandle note, string @namespace, ObjectId t
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as Note);
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs
index b48c72a99..42b65d7d0 100644
--- a/LibGit2Sharp/ObjectDatabase.cs
+++ b/LibGit2Sharp/ObjectDatabase.cs
@@ -199,7 +199,7 @@ public virtual ObjectId Write(Stream stream, long numberOfBytesToConsume) whe
if (!stream.CanRead)
{
- throw new ArgumentException("The stream cannot be read from.", "stream");
+ throw new ArgumentException("The stream cannot be read from.", nameof(stream));
}
using (var odbStream = Proxy.git_odb_open_wstream(handle, numberOfBytesToConsume, GitObjectType.Blob))
@@ -274,7 +274,7 @@ private unsafe Blob CreateBlob(Stream stream, string hintpath, long? numberOfByt
if (!stream.CanRead)
{
- throw new ArgumentException("The stream cannot be read from.", "stream");
+ throw new ArgumentException("The stream cannot be read from.", nameof(stream));
}
IntPtr writestream_ptr = Proxy.git_blob_create_from_stream(repo.Handle, hintpath);
@@ -588,7 +588,7 @@ public virtual MergeTreeResult CherryPickCommit(Commit cherryPickCommit, Commit
// Stopped due to FailOnConflict so there's no index or conflict list
if (earlyStop)
{
- return new MergeTreeResult(new Conflict[] { });
+ return new MergeTreeResult(Array.Empty());
}
if (Proxy.git_index_has_conflicts(indexHandle))
@@ -639,7 +639,7 @@ public virtual string ShortenObjectId(GitObject gitObject, int minLength)
if (minLength <= 0 || minLength > ObjectId.HexSize)
{
- throw new ArgumentOutOfRangeException("minLength",
+ throw new ArgumentOutOfRangeException(nameof(minLength),
minLength,
string.Format("Expected value should be greater than zero and less than or equal to {0}.",
ObjectId.HexSize));
@@ -714,7 +714,7 @@ public virtual Commit FindMergeBase(IEnumerable commits, MergeBaseFindin
{
if (commit == null)
{
- throw new ArgumentException("Enumerable contains null at position: " + count.ToString(CultureInfo.InvariantCulture), "commits");
+ throw new ArgumentException("Enumerable contains null at position: " + count.ToString(CultureInfo.InvariantCulture), nameof(commits));
}
ids.Add(commit.Id.Oid);
count++;
@@ -722,7 +722,7 @@ public virtual Commit FindMergeBase(IEnumerable commits, MergeBaseFindin
if (count < 2)
{
- throw new ArgumentException("The enumerable must contains at least two commits.", "commits");
+ throw new ArgumentException("The enumerable must contains at least two commits.", nameof(commits));
}
switch (strategy)
@@ -736,7 +736,7 @@ public virtual Commit FindMergeBase(IEnumerable commits, MergeBaseFindin
break;
default:
- throw new ArgumentException("", "strategy");
+ throw new ArgumentException("", nameof(strategy));
}
return id == null ? null : repo.Lookup(id);
@@ -780,7 +780,7 @@ public virtual MergeTreeResult MergeCommits(Commit ours, Commit theirs, MergeTre
// Stopped due to FailOnConflict so there's no index or conflict list
if (earlyStop)
{
- return new MergeTreeResult(new Conflict[] { });
+ return new MergeTreeResult(Array.Empty());
}
if (Proxy.git_index_has_conflicts(indexHandle))
@@ -1063,7 +1063,7 @@ public virtual MergeTreeResult RevertCommit(Commit revertCommit, Commit revertOn
// Stopped due to FailOnConflict so there's no index or conflict list
if (earlyStop)
{
- return new MergeTreeResult(new Conflict[] { });
+ return new MergeTreeResult(Array.Empty());
}
if (Proxy.git_index_has_conflicts(indexHandle))
diff --git a/LibGit2Sharp/ObjectId.cs b/LibGit2Sharp/ObjectId.cs
index 9d754781c..ad61cba36 100644
--- a/LibGit2Sharp/ObjectId.cs
+++ b/LibGit2Sharp/ObjectId.cs
@@ -39,7 +39,7 @@ internal ObjectId(GitOid oid)
{
if (oid.Id == null || oid.Id.Length != rawSize)
{
- throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "A non null array of {0} bytes is expected.", rawSize), "oid");
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "A non null array of {0} bytes is expected.", rawSize), nameof(oid));
}
this.oid = oid;
@@ -145,10 +145,10 @@ public static bool TryParse(string sha, out ObjectId result)
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as ObjectId);
@@ -174,7 +174,7 @@ public override int GetHashCode()
}
///
- /// Returns the , a representation of the current .
+ /// Returns the , a representation of the current .
///
/// The that represents the current .
public override string ToString()
@@ -183,7 +183,7 @@ public override string ToString()
}
///
- /// Returns the , a representation of the current .
+ /// Returns the , a representation of the current .
///
/// The number of chars the should be truncated to.
/// The that represents the current .
@@ -327,7 +327,7 @@ private static bool LooksValid(string objectId, bool throwIfInvalid)
"'{0}' is not a valid object identifier. Its length should be {1}.",
objectId,
HexSize),
- "objectId");
+ nameof(objectId));
}
return objectId.All(c => hexDigits.IndexOf(c) >= 0);
diff --git a/LibGit2Sharp/OdbBackend.cs b/LibGit2Sharp/OdbBackend.cs
index 9736ed803..645d0ac5f 100644
--- a/LibGit2Sharp/OdbBackend.cs
+++ b/LibGit2Sharp/OdbBackend.cs
@@ -63,7 +63,7 @@ protected unsafe UnmanagedMemoryStream Allocate(long size)
{
if (size < 0 || (UIntPtr.Size == sizeof(int) && size > int.MaxValue))
{
- throw new ArgumentOutOfRangeException("size");
+ throw new ArgumentOutOfRangeException(nameof(size));
}
IntPtr buffer = Proxy.git_odb_backend_malloc(this.GitOdbBackendPointer, new UIntPtr((ulong)size));
diff --git a/LibGit2Sharp/PackBuilder.cs b/LibGit2Sharp/PackBuilder.cs
index dcaa2617a..2ede4ab7b 100644
--- a/LibGit2Sharp/PackBuilder.cs
+++ b/LibGit2Sharp/PackBuilder.cs
@@ -189,7 +189,7 @@ public int MaximumNumberOfThreads
{
if (value < 0)
{
- throw new ArgumentException("Argument can not be negative", "value");
+ throw new ArgumentException("Argument can not be negative", nameof(value));
}
nThreads = value;
diff --git a/LibGit2Sharp/PeelException.cs b/LibGit2Sharp/PeelException.cs
index 92a6a0f13..b5a3d628b 100644
--- a/LibGit2Sharp/PeelException.cs
+++ b/LibGit2Sharp/PeelException.cs
@@ -32,7 +32,7 @@ public PeelException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public PeelException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/PushUpdate.cs b/LibGit2Sharp/PushUpdate.cs
index bbabb6817..0aa915dc0 100644
--- a/LibGit2Sharp/PushUpdate.cs
+++ b/LibGit2Sharp/PushUpdate.cs
@@ -29,9 +29,9 @@ internal unsafe PushUpdate(git_push_update* update)
protected PushUpdate()
{
DestinationObjectId = ObjectId.Zero;
- DestinationRefName = String.Empty;
+ DestinationRefName = string.Empty;
SourceObjectId = ObjectId.Zero;
- SourceRefName = String.Empty;
+ SourceRefName = string.Empty;
}
///
diff --git a/LibGit2Sharp/Reference.cs b/LibGit2Sharp/Reference.cs
index 40a85f79f..616b386a9 100644
--- a/LibGit2Sharp/Reference.cs
+++ b/LibGit2Sharp/Reference.cs
@@ -153,10 +153,10 @@ public virtual string TargetIdentifier
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as Reference);
@@ -204,7 +204,7 @@ public override int GetHashCode()
}
///
- /// Returns the , a representation of the current .
+ /// Returns the , a representation of the current .
///
/// The that represents the current .
public override string ToString()
diff --git a/LibGit2Sharp/ReferenceCollection.cs b/LibGit2Sharp/ReferenceCollection.cs
index 602a20f17..456b1a043 100644
--- a/LibGit2Sharp/ReferenceCollection.cs
+++ b/LibGit2Sharp/ReferenceCollection.cs
@@ -539,7 +539,7 @@ public virtual Reference UpdateTarget(string name, string canonicalRefNameOrObje
if (refState == RefState.DoesNotLookValid)
{
- throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The reference specified by {0} is a Symbolic reference, you must provide a reference canonical name as the target.", name), "canonicalRefNameOrObjectish");
+ throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The reference specified by {0} is a Symbolic reference, you must provide a reference canonical name as the target.", name), nameof(canonicalRefNameOrObjectish));
}
return UpdateTarget(symbolicReference, targetRef, logMessage);
diff --git a/LibGit2Sharp/ReferenceWrapper.cs b/LibGit2Sharp/ReferenceWrapper.cs
index eff09e6ce..7fb8497c6 100644
--- a/LibGit2Sharp/ReferenceWrapper.cs
+++ b/LibGit2Sharp/ReferenceWrapper.cs
@@ -129,10 +129,10 @@ public bool Equals(ReferenceWrapper other)
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as ReferenceWrapper);
diff --git a/LibGit2Sharp/RemoveFromIndexException.cs b/LibGit2Sharp/RemoveFromIndexException.cs
index 37e7daf79..847e4026e 100644
--- a/LibGit2Sharp/RemoveFromIndexException.cs
+++ b/LibGit2Sharp/RemoveFromIndexException.cs
@@ -30,7 +30,7 @@ public RemoveFromIndexException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public RemoveFromIndexException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/RenameDetails.cs b/LibGit2Sharp/RenameDetails.cs
index b866aac60..8742ff0d3 100644
--- a/LibGit2Sharp/RenameDetails.cs
+++ b/LibGit2Sharp/RenameDetails.cs
@@ -56,10 +56,10 @@ public virtual int Similarity
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as RenameDetails);
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 73f560c3c..e23c9cd3b 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -1456,7 +1456,7 @@ private FastForwardStrategy FastForwardStrategyFromMergePreference(GitMergePrefe
case GitMergePreference.GIT_MERGE_PREFERENCE_NO_FASTFORWARD:
return FastForwardStrategy.NoFastForward;
default:
- throw new InvalidOperationException(String.Format("Unknown merge preference: {0}", preference));
+ throw new InvalidOperationException(string.Format("Unknown merge preference: {0}", preference));
}
}
@@ -1674,7 +1674,7 @@ internal FilePath[] ToFilePaths(IEnumerable paths)
{
if (string.IsNullOrEmpty(path))
{
- throw new ArgumentException("At least one provided path is either null or empty.", "paths");
+ throw new ArgumentException("At least one provided path is either null or empty.", nameof(paths));
}
filePaths.Add(this.BuildRelativePathFrom(path));
@@ -1682,7 +1682,7 @@ internal FilePath[] ToFilePaths(IEnumerable paths)
if (filePaths.Count == 0)
{
- throw new ArgumentException("No path has been provided.", "paths");
+ throw new ArgumentException("No path has been provided.", nameof(paths));
}
return filePaths.ToArray();
diff --git a/LibGit2Sharp/RepositoryNotFoundException.cs b/LibGit2Sharp/RepositoryNotFoundException.cs
index 2e8deb393..e2bc63d8b 100644
--- a/LibGit2Sharp/RepositoryNotFoundException.cs
+++ b/LibGit2Sharp/RepositoryNotFoundException.cs
@@ -31,7 +31,7 @@ public RepositoryNotFoundException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public RepositoryNotFoundException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/Signature.cs b/LibGit2Sharp/Signature.cs
index bad656d05..7ed7a4916 100644
--- a/LibGit2Sharp/Signature.cs
+++ b/LibGit2Sharp/Signature.cs
@@ -86,10 +86,10 @@ public DateTimeOffset When
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as Signature);
diff --git a/LibGit2Sharp/SmartSubtransport.cs b/LibGit2Sharp/SmartSubtransport.cs
index 66fcd12bf..e7a331b4b 100644
--- a/LibGit2Sharp/SmartSubtransport.cs
+++ b/LibGit2Sharp/SmartSubtransport.cs
@@ -158,7 +158,7 @@ public int AcquireCredentials(out Credentials cred, string user, params Type[] m
/// The endpoint to connect to
/// The type of connection to create
/// A SmartSubtransportStream representing the connection
- protected abstract SmartSubtransportStream Action(String url, GitSmartSubtransportAction action);
+ protected abstract SmartSubtransportStream Action(string url, GitSmartSubtransportAction action);
///
/// Invoked by libgit2 when this subtransport is no longer needed, but may be re-used in the future.
@@ -225,7 +225,7 @@ private static int Action(
stream = IntPtr.Zero;
SmartSubtransport t = GCHandle.FromIntPtr(Marshal.ReadIntPtr(subtransport, GitSmartSubtransport.GCHandleOffset)).Target as SmartSubtransport;
- String urlAsString = LaxUtf8Marshaler.FromNative(url);
+ string urlAsString = LaxUtf8Marshaler.FromNative(url);
if (t == null)
{
@@ -233,12 +233,12 @@ private static int Action(
return (int)GitErrorCode.Error;
}
- if (String.IsNullOrEmpty(urlAsString))
+ if (string.IsNullOrEmpty(urlAsString))
{
urlAsString = t.LastActionUrl;
}
- if (String.IsNullOrEmpty(urlAsString))
+ if (string.IsNullOrEmpty(urlAsString))
{
Proxy.git_error_set_str(GitErrorCategory.Net, "no url provided");
return (int)GitErrorCode.Error;
diff --git a/LibGit2Sharp/StashCollection.cs b/LibGit2Sharp/StashCollection.cs
index 5fe775eba..42162ada5 100644
--- a/LibGit2Sharp/StashCollection.cs
+++ b/LibGit2Sharp/StashCollection.cs
@@ -67,7 +67,7 @@ public virtual Stash this[int index]
{
if (index < 0)
{
- throw new ArgumentOutOfRangeException("index", "The passed index must be a positive integer.");
+ throw new ArgumentOutOfRangeException(nameof(index), "The passed index must be a positive integer.");
}
GitObject stashCommit = repo.Lookup(string.Format(CultureInfo.InvariantCulture,
@@ -146,7 +146,7 @@ public virtual StashApplyStatus Apply(int index, StashApplyOptions options)
{
if (index < 0)
{
- throw new ArgumentException("The passed index must be a positive integer.", "index");
+ throw new ArgumentException("The passed index must be a positive integer.", nameof(index));
}
if (options == null)
@@ -189,7 +189,7 @@ public virtual StashApplyStatus Pop(int index, StashApplyOptions options)
{
if (index < 0)
{
- throw new ArgumentException("The passed index must be a positive integer.", "index");
+ throw new ArgumentException("The passed index must be a positive integer.", nameof(index));
}
if (options == null)
@@ -231,7 +231,7 @@ public virtual void Remove(int index)
{
if (index < 0)
{
- throw new ArgumentException("The passed index must be a positive integer.", "index");
+ throw new ArgumentException("The passed index must be a positive integer.", nameof(index));
}
Proxy.git_stash_drop(repo.Handle, index);
diff --git a/LibGit2Sharp/StatusEntry.cs b/LibGit2Sharp/StatusEntry.cs
index 7008712c6..bd2ef8883 100644
--- a/LibGit2Sharp/StatusEntry.cs
+++ b/LibGit2Sharp/StatusEntry.cs
@@ -66,10 +66,10 @@ public virtual RenameDetails IndexToWorkDirRenameDetails
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as StatusEntry);
diff --git a/LibGit2Sharp/Submodule.cs b/LibGit2Sharp/Submodule.cs
index ace995205..f8193af13 100644
--- a/LibGit2Sharp/Submodule.cs
+++ b/LibGit2Sharp/Submodule.cs
@@ -107,10 +107,10 @@ public virtual SubmoduleStatus RetrieveStatus()
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as Submodule);
@@ -136,7 +136,7 @@ public override int GetHashCode()
}
///
- /// Returns the , a representation of the current .
+ /// Returns the , a representation of the current .
///
/// The that represents the current .
public override string ToString()
diff --git a/LibGit2Sharp/Tree.cs b/LibGit2Sharp/Tree.cs
index f8494ad8b..64d46145d 100644
--- a/LibGit2Sharp/Tree.cs
+++ b/LibGit2Sharp/Tree.cs
@@ -90,7 +90,7 @@ internal static string CombinePath(string a, string b)
{
var bld = new StringBuilder();
bld.Append(a);
- if (!String.IsNullOrEmpty(a) &&
+ if (!string.IsNullOrEmpty(a) &&
!a.EndsWith("/", StringComparison.Ordinal) &&
!b.StartsWith("/", StringComparison.Ordinal))
{
diff --git a/LibGit2Sharp/TreeChanges.cs b/LibGit2Sharp/TreeChanges.cs
index 6e8a0eff5..6a54d9c09 100644
--- a/LibGit2Sharp/TreeChanges.cs
+++ b/LibGit2Sharp/TreeChanges.cs
@@ -55,7 +55,7 @@ private IEnumerable GetChangesOfKind(ChangeKind changeKind)
private unsafe bool TryGetEntryWithChangeTypeAt(int index, ChangeKind changeKind, out TreeEntryChanges entry)
{
if (index < 0 || index > count.Value)
- throw new ArgumentOutOfRangeException("index", "Index was out of range. Must be non-negative and less than the size of the collection.");
+ throw new ArgumentOutOfRangeException(nameof(index), "Index was out of range. Must be non-negative and less than the size of the collection.");
var delta = Proxy.git_diff_get_delta(diff, index);
@@ -90,7 +90,7 @@ public virtual IEnumerator GetEnumerator()
private unsafe TreeEntryChanges GetEntryAt(int index)
{
if (index < 0 || index > count.Value)
- throw new ArgumentOutOfRangeException("index", "Index was out of range. Must be non-negative and less than the size of the collection.");
+ throw new ArgumentOutOfRangeException(nameof(index), "Index was out of range. Must be non-negative and less than the size of the collection.");
return new TreeEntryChanges(Proxy.git_diff_get_delta(diff, index));
}
diff --git a/LibGit2Sharp/TreeEntry.cs b/LibGit2Sharp/TreeEntry.cs
index e500a8ee1..943e14570 100644
--- a/LibGit2Sharp/TreeEntry.cs
+++ b/LibGit2Sharp/TreeEntry.cs
@@ -93,10 +93,10 @@ private GitObject RetrieveTreeEntryTarget()
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as TreeEntry);
diff --git a/LibGit2Sharp/TreeEntryDefinition.cs b/LibGit2Sharp/TreeEntryDefinition.cs
index 2a3ceb35f..d32cc722c 100644
--- a/LibGit2Sharp/TreeEntryDefinition.cs
+++ b/LibGit2Sharp/TreeEntryDefinition.cs
@@ -112,10 +112,10 @@ internal static TreeEntryDefinition From(Tree tree)
}
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as TreeEntryDefinition);
diff --git a/LibGit2Sharp/UnbornBranchException.cs b/LibGit2Sharp/UnbornBranchException.cs
index 8f56eed3d..8f01a63ab 100644
--- a/LibGit2Sharp/UnbornBranchException.cs
+++ b/LibGit2Sharp/UnbornBranchException.cs
@@ -31,7 +31,7 @@ public UnbornBranchException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public UnbornBranchException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/UnmatchedPathException.cs b/LibGit2Sharp/UnmatchedPathException.cs
index daf48db6d..96e5654c7 100644
--- a/LibGit2Sharp/UnmatchedPathException.cs
+++ b/LibGit2Sharp/UnmatchedPathException.cs
@@ -30,7 +30,7 @@ public UnmatchedPathException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public UnmatchedPathException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/UnmergedIndexEntriesException.cs b/LibGit2Sharp/UnmergedIndexEntriesException.cs
index ca01c256d..f9f1a834b 100644
--- a/LibGit2Sharp/UnmergedIndexEntriesException.cs
+++ b/LibGit2Sharp/UnmergedIndexEntriesException.cs
@@ -32,7 +32,7 @@ public UnmergedIndexEntriesException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public UnmergedIndexEntriesException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/UserCanceledException.cs b/LibGit2Sharp/UserCanceledException.cs
index 0139bdb1c..f3c6af7dd 100644
--- a/LibGit2Sharp/UserCanceledException.cs
+++ b/LibGit2Sharp/UserCanceledException.cs
@@ -31,7 +31,7 @@ public UserCancelledException(string message)
///
/// Initializes a new instance of the class with a specified error message.
///
- /// A composite format string for use in .
+ /// A composite format string for use in .
/// An object array that contains zero or more objects to format.
public UserCancelledException(string format, params object[] args)
: base(format, args)
diff --git a/LibGit2Sharp/Worktree.cs b/LibGit2Sharp/Worktree.cs
index 13fea072b..bd10f6110 100644
--- a/LibGit2Sharp/Worktree.cs
+++ b/LibGit2Sharp/Worktree.cs
@@ -65,10 +65,10 @@ internal WorktreeHandle GetWorktreeHandle()
public virtual string LockReason { get { return worktreeLock == null ? null : worktreeLock.Reason; } }
///
- /// Determines whether the specified is equal to the current .
+ /// Determines whether the specified is equal to the current .
///
- /// The to compare with the current .
- /// True if the specified is equal to the current ; otherwise, false.
+ /// The to compare with the current .
+ /// True if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
return Equals(obj as Worktree);
@@ -118,7 +118,7 @@ public override int GetHashCode()
}
///
- /// Returns the , a representation of the current .
+ /// Returns the , a representation of the current .
///
/// The that represents the current .
public override string ToString()
From e1703369d6eb7bdcc9bc13aa10d31324a07d6f5c Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Mar 2024 14:38:00 -0400
Subject: [PATCH 120/147] Update LibGit2Sharp.NativeBinaries to 2.0.322
---
LibGit2Sharp/LibGit2Sharp.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index fcf965c7d..28404d948 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -39,7 +39,7 @@
-
+
From a37362367aeadbebbfa22c28cdff16a3da26f081 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 16 Mar 2024 22:20:57 -0400
Subject: [PATCH 121/147] Increase assert range to avoid flaky tests
---
LibGit2Sharp.Tests/CommitFixture.cs | 75 ++++++++++---------
LibGit2Sharp.Tests/ReflogFixture.cs | 23 ++++--
LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 6 +-
3 files changed, 59 insertions(+), 45 deletions(-)
diff --git a/LibGit2Sharp.Tests/CommitFixture.cs b/LibGit2Sharp.Tests/CommitFixture.cs
index 1a849c2df..e99ca918f 100644
--- a/LibGit2Sharp.Tests/CommitFixture.cs
+++ b/LibGit2Sharp.Tests/CommitFixture.cs
@@ -3,10 +3,8 @@
using System.IO;
using System.Linq;
using System.Text;
-using LibGit2Sharp.Core;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -150,10 +148,10 @@ public void CanEnumerateCommitsWithReverseTimeSorting()
using (var repo = new Repository(path))
{
foreach (Commit commit in repo.Commits.QueryBy(new CommitFilter
- {
- IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f",
- SortBy = CommitSortStrategies.Time | CommitSortStrategies.Reverse
- }))
+ {
+ IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f",
+ SortBy = CommitSortStrategies.Time | CommitSortStrategies.Reverse
+ }))
{
Assert.NotNull(commit);
Assert.StartsWith(reversedShas[count], commit.Sha);
@@ -170,10 +168,10 @@ public void CanEnumerateCommitsWithReverseTopoSorting()
using (var repo = new Repository(path))
{
List commits = repo.Commits.QueryBy(new CommitFilter
- {
- IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f",
- SortBy = CommitSortStrategies.Time | CommitSortStrategies.Reverse
- }).ToList();
+ {
+ IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f",
+ SortBy = CommitSortStrategies.Time | CommitSortStrategies.Reverse
+ }).ToList();
foreach (Commit commit in commits)
{
Assert.NotNull(commit);
@@ -216,10 +214,10 @@ public void CanEnumerateCommitsWithTimeSorting()
using (var repo = new Repository(path))
{
foreach (Commit commit in repo.Commits.QueryBy(new CommitFilter
- {
- IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f",
- SortBy = CommitSortStrategies.Time
- }))
+ {
+ IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f",
+ SortBy = CommitSortStrategies.Time
+ }))
{
Assert.NotNull(commit);
Assert.StartsWith(expectedShas[count], commit.Sha);
@@ -236,10 +234,10 @@ public void CanEnumerateCommitsWithTopoSorting()
using (var repo = new Repository(path))
{
List commits = repo.Commits.QueryBy(new CommitFilter
- {
- IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f",
- SortBy = CommitSortStrategies.Topological
- }).ToList();
+ {
+ IncludeReachableFrom = "a4a7dce85cf63874e984719f4fdd239f5145052f",
+ SortBy = CommitSortStrategies.Topological
+ }).ToList();
foreach (Commit commit in commits)
{
Assert.NotNull(commit);
@@ -331,9 +329,12 @@ public void CanEnumerateCommitsFromTwoHeads()
public void CanEnumerateCommitsFromMixedStartingPoints()
{
AssertEnumerationOfCommits(
- repo => new CommitFilter { IncludeReachableFrom = new object[] { repo.Branches["br2"],
+ repo => new CommitFilter
+ {
+ IncludeReachableFrom = new object[] { repo.Branches["br2"],
"refs/heads/master",
- new ObjectId("e90810b8df3e80c413d903f631643c716887138d") } },
+ new ObjectId("e90810b8df3e80c413d903f631643c716887138d") }
+ },
new[]
{
"4c062a6", "e90810b", "6dcf9bf", "a4a7dce",
@@ -389,9 +390,9 @@ public void CanEnumerateAllCommits()
{
AssertEnumerationOfCommits(
repo => new CommitFilter
- {
- IncludeReachableFrom = repo.Refs.OrderBy(r => r.CanonicalName, StringComparer.Ordinal),
- },
+ {
+ IncludeReachableFrom = repo.Refs.OrderBy(r => r.CanonicalName, StringComparer.Ordinal),
+ },
new[]
{
"44d5d18", "bb65291", "532740a", "503a16f", "3dfd6fd",
@@ -680,8 +681,12 @@ public void CanCommitALittleBit()
Assert.Equal(identity.Name, reflogEntry.Committer.Name);
Assert.Equal(identity.Email, reflogEntry.Committer.Email);
- var now = DateTimeOffset.Now;
- Assert.InRange(reflogEntry.Committer.When, before, now);
+ // When verifying the timestamp range, give a little more room on the range.
+ // Git or file system datetime truncation seems to cause these stamps to jump up to a second earlier
+ // than we expect. See https://github.com/libgit2/libgit2sharp/issues/1764
+ var low = before - TimeSpan.FromSeconds(1);
+ var high = DateTimeOffset.Now.TruncateMilliseconds() + TimeSpan.FromSeconds(1);
+ Assert.InRange(reflogEntry.Committer.When, low, high);
Assert.Equal(commit.Id, reflogEntry.To);
Assert.Equal(ObjectId.Zero, reflogEntry.From);
@@ -859,21 +864,21 @@ public void CanRetrieveChildrenOfASpecificCommit()
const string parentSha = "5b5b025afb0b4c913b4c338a42934a3863bf3644";
var filter = new CommitFilter
- {
- /* Revwalk from all the refs (git log --all) ... */
- IncludeReachableFrom = repo.Refs,
+ {
+ /* Revwalk from all the refs (git log --all) ... */
+ IncludeReachableFrom = repo.Refs,
- /* ... and stop when the parent is reached */
- ExcludeReachableFrom = parentSha
- };
+ /* ... and stop when the parent is reached */
+ ExcludeReachableFrom = parentSha
+ };
var commits = repo.Commits.QueryBy(filter);
var children = from c in commits
- from p in c.Parents
- let pId = p.Id
- where pId.Sha == parentSha
- select c;
+ from p in c.Parents
+ let pId = p.Id
+ where pId.Sha == parentSha
+ select c;
var expectedChildren = new[] { "c47800c7266a2be04c571c04d5a6614691ea99bd",
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045" };
diff --git a/LibGit2Sharp.Tests/ReflogFixture.cs b/LibGit2Sharp.Tests/ReflogFixture.cs
index f93952e6e..52973454b 100644
--- a/LibGit2Sharp.Tests/ReflogFixture.cs
+++ b/LibGit2Sharp.Tests/ReflogFixture.cs
@@ -3,7 +3,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -59,7 +58,7 @@ public void CommitShouldCreateReflogEntryOnHeadAndOnTargetedDirectReference()
var identity = Constants.Identity;
- using (var repo = new Repository(repoPath, new RepositoryOptions{ Identity = identity }))
+ using (var repo = new Repository(repoPath, new RepositoryOptions { Identity = identity }))
{
// setup refs as HEAD => unit_test => master
var newRef = repo.Refs.Add("refs/heads/unit_test", "refs/heads/master");
@@ -84,8 +83,12 @@ public void CommitShouldCreateReflogEntryOnHeadAndOnTargetedDirectReference()
Assert.Equal(identity.Name, reflogEntry.Committer.Name);
Assert.Equal(identity.Email, reflogEntry.Committer.Email);
- var now = DateTimeOffset.Now;
- Assert.InRange(reflogEntry.Committer.When, before, now);
+ // When verifying the timestamp range, give a little more room on the range.
+ // Git or file system datetime truncation seems to cause these stamps to jump up to a second earlier
+ // than we expect. See https://github.com/libgit2/libgit2sharp/issues/1764
+ var low = before - TimeSpan.FromSeconds(1);
+ var high = DateTimeOffset.Now.TruncateMilliseconds() + TimeSpan.FromSeconds(1);
+ Assert.InRange(reflogEntry.Committer.When, low, high);
Assert.Equal(commit.Id, reflogEntry.To);
Assert.Equal(ObjectId.Zero, reflogEntry.From);
@@ -97,7 +100,7 @@ public void CommitShouldCreateReflogEntryOnHeadAndOnTargetedDirectReference()
Assert.Equal(identity.Name, reflogEntry.Committer.Name);
Assert.Equal(identity.Email, reflogEntry.Committer.Email);
- Assert.InRange(reflogEntry.Committer.When, before, now);
+ Assert.InRange(reflogEntry.Committer.When, low, high);
Assert.Equal(commit.Id, reflogEntry.To);
Assert.Equal(ObjectId.Zero, reflogEntry.From);
@@ -160,8 +163,12 @@ public void CommitOnDetachedHeadShouldInsertReflogEntry()
Assert.Equal(identity.Name, reflogEntry.Committer.Name);
Assert.Equal(identity.Email, reflogEntry.Committer.Email);
- var now = DateTimeOffset.Now;
- Assert.InRange(reflogEntry.Committer.When, before, now);
+ // When verifying the timestamp range, give a little more room on the range.
+ // Git or file system datetime truncation seems to cause these stamps to jump up to a second earlier
+ // than we expect. See https://github.com/libgit2/libgit2sharp/issues/1764
+ var low = before - TimeSpan.FromSeconds(1);
+ var high = DateTimeOffset.Now.TruncateMilliseconds() + TimeSpan.FromSeconds(1);
+ Assert.InRange(reflogEntry.Committer.When, low, high);
Assert.Equal(commit.Id, reflogEntry.To);
Assert.Equal(string.Format("commit: {0}", commitMessage), repo.Refs.Log("HEAD").First().Message);
@@ -202,7 +209,7 @@ public void AppendingToReflogDependsOnCoreLogAllRefUpdatesSetting(bool isBare, b
public void UnsignedMethodsWriteCorrectlyToTheReflog()
{
var repoPath = InitNewRepository(true);
- using (var repo = new Repository(repoPath, new RepositoryOptions{ Identity = Constants.Identity }))
+ using (var repo = new Repository(repoPath, new RepositoryOptions { Identity = Constants.Identity }))
{
EnableRefLog(repo);
diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
index cde8f3ddb..e9429d562 100644
--- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
+++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
@@ -471,10 +471,12 @@ protected static void AssertRefLogEntry(IRepository repo, string canonicalName,
Assert.Equal(committer.Email, reflogEntry.Committer.Email);
- // When verifying the timestamp range, give a little more room on the 'before' side.
+ // When verifying the timestamp range, give a little more room on the range.
// Git or file system datetime truncation seems to cause these stamps to jump up to a second earlier
// than we expect. See https://github.com/libgit2/libgit2sharp/issues/1764
- Assert.InRange(reflogEntry.Committer.When, before - TimeSpan.FromSeconds(1), DateTimeOffset.Now);
+ var low = before - TimeSpan.FromSeconds(1);
+ var high = DateTimeOffset.Now.TruncateMilliseconds() + TimeSpan.FromSeconds(1);
+ Assert.InRange(reflogEntry.Committer.When, low, high);
}
protected static void EnableRefLog(IRepository repository, bool enable = true)
From 5085a0c6173cdb2a3fde205330b327a8eb0a26c4 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 18 Mar 2024 22:48:32 -0400
Subject: [PATCH 122/147] Update CHANGES.md for v0.30
---
CHANGES.md | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/CHANGES.md b/CHANGES.md
index ae27d7716..1d68e6169 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,12 @@
# LibGit2Sharp Changes
+## v0.30 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.29.0..0.30.0))
+
+### Changes
+- This release includes [libgit2 v1.7.2](https://github.com/libgit2/libgit2/releases/tag/v1.7.2).
+- Updates for trimming compatibility [#2084](https://github.com/libgit2/libgit2sharp/pull/2084)
+- Updates for .NET 8 [#2085](https://github.com/libgit2/libgit2sharp/pull/2085)
+
## v0.29 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.28.0..0.29.0))
### Changes
@@ -8,7 +15,7 @@
### Additions
- Add proxy options [#2065](https://github.com/libgit2/libgit2sharp/pull/2065)
- - See PR for details, including some breaking changes to `CloneOptions` and `SubmoduleUpdateOptions`
+ - See PR for details, including some breaking changes to `CloneOptions` and `SubmoduleUpdateOptions`
## v0.28 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.27.2..0.28.0))
From 77cfeaffd34b98f966f5efb232446b2884369be6 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Thu, 21 Nov 2024 00:54:31 -0500
Subject: [PATCH 123/147] Remove macos-11
---
.github/workflows/ci.yml | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 35f0241ef..9a7f9a0de 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -38,13 +38,9 @@ jobs:
strategy:
matrix:
arch: [ x64 ]
- os: [ windows-2019, windows-2022, macos-11, macos-12, macos-13 ]
+ os: [ windows-2019, windows-2022, 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
From 66f6940c242b6539c74ec9ebf9a0c6f221dfb9e3 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Thu, 21 Nov 2024 00:56:00 -0500
Subject: [PATCH 124/147] Use private protected
---
LibGit2Sharp/Reference.cs | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/LibGit2Sharp/Reference.cs b/LibGit2Sharp/Reference.cs
index 616b386a9..9530f2378 100644
--- a/LibGit2Sharp/Reference.cs
+++ b/LibGit2Sharp/Reference.cs
@@ -25,11 +25,7 @@ public abstract class Reference : IEquatable, IBelongToARepository
protected Reference()
{ }
- ///
- /// This would be protected+internal, were that supported by C#.
- /// Do not use except in subclasses.
- ///
- internal Reference(IRepository repo, string canonicalName, string targetIdentifier)
+ private protected Reference(IRepository repo, string canonicalName, string targetIdentifier)
{
this.repo = repo;
this.canonicalName = canonicalName;
From a88e2a02e04ed8acc5455df04c1e6cd91ced3265 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Thu, 21 Nov 2024 01:13:13 -0500
Subject: [PATCH 125/147] Use SafeHandles (#2127)
* Remove unneeded cast
* Use SafeHandles
---
LibGit2Sharp/Core/Handles/Libgit2Object.cs | 87 ++-----
LibGit2Sharp/Core/Handles/Objects.cs | 250 ++++++++++++---------
LibGit2Sharp/Core/Handles/Objects.tt | 10 +-
LibGit2Sharp/Network.cs | 4 +-
LibGit2Sharp/Reference.cs | 2 +-
LibGit2Sharp/Repository.cs | 4 +-
6 files changed, 184 insertions(+), 173 deletions(-)
diff --git a/LibGit2Sharp/Core/Handles/Libgit2Object.cs b/LibGit2Sharp/Core/Handles/Libgit2Object.cs
index 892ebde90..a96d99e10 100644
--- a/LibGit2Sharp/Core/Handles/Libgit2Object.cs
+++ b/LibGit2Sharp/Core/Handles/Libgit2Object.cs
@@ -1,13 +1,13 @@
// This activates a lightweight mode which will help put under the light
-// incorrectly released handles by outputing a warning message in the console.
+// incorrectly released handles by outputting a warning message in the console.
//
// This should be activated when tests are being run on the CI server.
//
// Uncomment the line below or add a conditional symbol to activate this mode
-// #define LEAKS_IDENTIFYING
+//#define LEAKS_IDENTIFYING
-// This activates a more throrough mode which will show the stack trace of the
+// This activates a more thorough mode which will show the stack trace of the
// allocation code path for each handle that has been improperly released.
//
// This should be manually activated when some warnings have been raised as
@@ -15,17 +15,17 @@
//
// Uncomment the line below or add a conditional symbol to activate this mode
-// #define LEAKS_TRACKING
+//#define LEAKS_TRACKING
using System;
-using System.Linq;
-using System.Diagnostics;
-using System.Globalization;
-using System.Collections.Generic;
+using Microsoft.Win32.SafeHandles;
#if LEAKS_IDENTIFYING
namespace LibGit2Sharp.Core
{
+ using System.Collections.Generic;
+ using System.Linq;
+
///
/// Holds leaked handle type names reported by
///
@@ -78,30 +78,27 @@ public static IEnumerable TypeNames
namespace LibGit2Sharp.Core.Handles
{
- internal unsafe abstract class Libgit2Object : IDisposable
+#if LEAKS_TRACKING
+ using System.Diagnostics;
+ using System.Globalization;
+#endif
+
+ internal unsafe abstract class Libgit2Object : SafeHandleZeroOrMinusOneIsInvalid
{
#if LEAKS_TRACKING
private readonly string trace;
private readonly Guid id;
#endif
- protected void* ptr;
-
- internal void* Handle
+ internal unsafe Libgit2Object(void* ptr, bool owned)
+ : this(new IntPtr(ptr), owned)
{
- get
- {
- return ptr;
- }
}
- bool owned;
- bool disposed;
-
- internal unsafe Libgit2Object(void* handle, bool owned)
+ internal unsafe Libgit2Object(IntPtr ptr, bool owned)
+ : base(owned)
{
- this.ptr = handle;
- this.owned = owned;
+ SetHandle(ptr);
#if LEAKS_TRACKING
id = Guid.NewGuid();
@@ -111,35 +108,12 @@ internal unsafe Libgit2Object(void* handle, bool owned)
#endif
}
- internal unsafe Libgit2Object(IntPtr ptr, bool owned)
- : this(ptr.ToPointer(), owned)
- {
- }
+ internal IntPtr AsIntPtr() => DangerousGetHandle();
- ~Libgit2Object()
- {
- Dispose(false);
- }
-
- internal bool IsNull
- {
- get
- {
- return ptr == null;
- }
- }
-
- internal IntPtr AsIntPtr()
- {
- return new IntPtr(ptr);
- }
-
- public abstract void Free();
-
- void Dispose(bool disposing)
+ protected override void Dispose(bool disposing)
{
#if LEAKS_IDENTIFYING
- bool leaked = !disposing && ptr != null;
+ bool leaked = !disposing && DangerousGetHandle() != IntPtr.Zero;
if (leaked)
{
@@ -147,17 +121,7 @@ void Dispose(bool disposing)
}
#endif
- if (!disposed)
- {
- if (owned)
- {
- Free();
- }
-
- ptr = null;
- }
-
- disposed = true;
+ base.Dispose(disposing);
#if LEAKS_TRACKING
if (!leaked)
@@ -172,11 +136,6 @@ void Dispose(bool disposing)
}
#endif
}
-
- public void Dispose()
- {
- Dispose(true);
- }
}
}
diff --git a/LibGit2Sharp/Core/Handles/Objects.cs b/LibGit2Sharp/Core/Handles/Objects.cs
index 5f8db722e..7666a7412 100644
--- a/LibGit2Sharp/Core/Handles/Objects.cs
+++ b/LibGit2Sharp/Core/Handles/Objects.cs
@@ -7,7 +7,7 @@ namespace LibGit2Sharp.Core.Handles
internal unsafe class TreeEntryHandle : Libgit2Object
{
internal TreeEntryHandle(git_tree_entry *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -16,21 +16,23 @@ internal TreeEntryHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_tree_entry_free((git_tree_entry*) ptr);
+ NativeMethods.git_tree_entry_free((git_tree_entry*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_tree_entry*(TreeEntryHandle handle)
{
- return (git_tree_entry*) handle.Handle;
+ return (git_tree_entry*)handle.AsIntPtr();
}
}
internal unsafe class ReferenceHandle : Libgit2Object
{
internal ReferenceHandle(git_reference *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -39,21 +41,23 @@ internal ReferenceHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_reference_free((git_reference*) ptr);
+ NativeMethods.git_reference_free((git_reference*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_reference*(ReferenceHandle handle)
{
- return (git_reference*) handle.Handle;
+ return (git_reference*)handle.AsIntPtr();
}
}
internal unsafe class RepositoryHandle : Libgit2Object
{
internal RepositoryHandle(git_repository *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -62,21 +66,23 @@ internal RepositoryHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_repository_free((git_repository*) ptr);
+ NativeMethods.git_repository_free((git_repository*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_repository*(RepositoryHandle handle)
{
- return (git_repository*) handle.Handle;
+ return (git_repository*)handle.AsIntPtr();
}
}
internal unsafe class SignatureHandle : Libgit2Object
{
internal SignatureHandle(git_signature *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -85,21 +91,23 @@ internal SignatureHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_signature_free((git_signature*) ptr);
+ NativeMethods.git_signature_free((git_signature*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_signature*(SignatureHandle handle)
{
- return (git_signature*) handle.Handle;
+ return (git_signature*)handle.AsIntPtr();
}
}
internal unsafe class StatusListHandle : Libgit2Object
{
internal StatusListHandle(git_status_list *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -108,21 +116,23 @@ internal StatusListHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_status_list_free((git_status_list*) ptr);
+ NativeMethods.git_status_list_free((git_status_list*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_status_list*(StatusListHandle handle)
{
- return (git_status_list*) handle.Handle;
+ return (git_status_list*)handle.AsIntPtr();
}
}
internal unsafe class BlameHandle : Libgit2Object
{
internal BlameHandle(git_blame *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -131,21 +141,23 @@ internal BlameHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_blame_free((git_blame*) ptr);
+ NativeMethods.git_blame_free((git_blame*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_blame*(BlameHandle handle)
{
- return (git_blame*) handle.Handle;
+ return (git_blame*)handle.AsIntPtr();
}
}
internal unsafe class DiffHandle : Libgit2Object
{
internal DiffHandle(git_diff *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -154,21 +166,23 @@ internal DiffHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_diff_free((git_diff*) ptr);
+ NativeMethods.git_diff_free((git_diff*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_diff*(DiffHandle handle)
{
- return (git_diff*) handle.Handle;
+ return (git_diff*)handle.AsIntPtr();
}
}
internal unsafe class PatchHandle : Libgit2Object
{
internal PatchHandle(git_patch *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -177,21 +191,23 @@ internal PatchHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_patch_free((git_patch*) ptr);
+ NativeMethods.git_patch_free((git_patch*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_patch*(PatchHandle handle)
{
- return (git_patch*) handle.Handle;
+ return (git_patch*)handle.AsIntPtr();
}
}
internal unsafe class ConfigurationHandle : Libgit2Object
{
internal ConfigurationHandle(git_config *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -200,21 +216,23 @@ internal ConfigurationHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_config_free((git_config*) ptr);
+ NativeMethods.git_config_free((git_config*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_config*(ConfigurationHandle handle)
{
- return (git_config*) handle.Handle;
+ return (git_config*)handle.AsIntPtr();
}
}
internal unsafe class ConflictIteratorHandle : Libgit2Object
{
internal ConflictIteratorHandle(git_index_conflict_iterator *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -223,21 +241,23 @@ internal ConflictIteratorHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_index_conflict_iterator_free((git_index_conflict_iterator*) ptr);
+ NativeMethods.git_index_conflict_iterator_free((git_index_conflict_iterator*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_index_conflict_iterator*(ConflictIteratorHandle handle)
{
- return (git_index_conflict_iterator*) handle.Handle;
+ return (git_index_conflict_iterator*)handle.AsIntPtr();
}
}
internal unsafe class IndexHandle : Libgit2Object
{
internal IndexHandle(git_index *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -246,21 +266,23 @@ internal IndexHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_index_free((git_index*) ptr);
+ NativeMethods.git_index_free((git_index*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_index*(IndexHandle handle)
{
- return (git_index*) handle.Handle;
+ return (git_index*)handle.AsIntPtr();
}
}
internal unsafe class ReflogHandle : Libgit2Object
{
internal ReflogHandle(git_reflog *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -269,21 +291,23 @@ internal ReflogHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_reflog_free((git_reflog*) ptr);
+ NativeMethods.git_reflog_free((git_reflog*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_reflog*(ReflogHandle handle)
{
- return (git_reflog*) handle.Handle;
+ return (git_reflog*)handle.AsIntPtr();
}
}
internal unsafe class TreeBuilderHandle : Libgit2Object
{
internal TreeBuilderHandle(git_treebuilder *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -292,21 +316,23 @@ internal TreeBuilderHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_treebuilder_free((git_treebuilder*) ptr);
+ NativeMethods.git_treebuilder_free((git_treebuilder*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_treebuilder*(TreeBuilderHandle handle)
{
- return (git_treebuilder*) handle.Handle;
+ return (git_treebuilder*)handle.AsIntPtr();
}
}
internal unsafe class PackBuilderHandle : Libgit2Object
{
internal PackBuilderHandle(git_packbuilder *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -315,21 +341,23 @@ internal PackBuilderHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_packbuilder_free((git_packbuilder*) ptr);
+ NativeMethods.git_packbuilder_free((git_packbuilder*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_packbuilder*(PackBuilderHandle handle)
{
- return (git_packbuilder*) handle.Handle;
+ return (git_packbuilder*)handle.AsIntPtr();
}
}
internal unsafe class NoteHandle : Libgit2Object
{
internal NoteHandle(git_note *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -338,21 +366,23 @@ internal NoteHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_note_free((git_note*) ptr);
+ NativeMethods.git_note_free((git_note*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_note*(NoteHandle handle)
{
- return (git_note*) handle.Handle;
+ return (git_note*)handle.AsIntPtr();
}
}
internal unsafe class DescribeResultHandle : Libgit2Object
{
internal DescribeResultHandle(git_describe_result *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -361,21 +391,23 @@ internal DescribeResultHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_describe_result_free((git_describe_result*) ptr);
+ NativeMethods.git_describe_result_free((git_describe_result*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_describe_result*(DescribeResultHandle handle)
{
- return (git_describe_result*) handle.Handle;
+ return (git_describe_result*)handle.AsIntPtr();
}
}
internal unsafe class SubmoduleHandle : Libgit2Object
{
internal SubmoduleHandle(git_submodule *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -384,21 +416,23 @@ internal SubmoduleHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_submodule_free((git_submodule*) ptr);
+ NativeMethods.git_submodule_free((git_submodule*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_submodule*(SubmoduleHandle handle)
{
- return (git_submodule*) handle.Handle;
+ return (git_submodule*)handle.AsIntPtr();
}
}
internal unsafe class AnnotatedCommitHandle : Libgit2Object
{
internal AnnotatedCommitHandle(git_annotated_commit *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -407,21 +441,23 @@ internal AnnotatedCommitHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_annotated_commit_free((git_annotated_commit*) ptr);
+ NativeMethods.git_annotated_commit_free((git_annotated_commit*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_annotated_commit*(AnnotatedCommitHandle handle)
{
- return (git_annotated_commit*) handle.Handle;
+ return (git_annotated_commit*)handle.AsIntPtr();
}
}
internal unsafe class ObjectDatabaseHandle : Libgit2Object
{
internal ObjectDatabaseHandle(git_odb *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -430,21 +466,23 @@ internal ObjectDatabaseHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_odb_free((git_odb*) ptr);
+ NativeMethods.git_odb_free((git_odb*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_odb*(ObjectDatabaseHandle handle)
{
- return (git_odb*) handle.Handle;
+ return (git_odb*)handle.AsIntPtr();
}
}
internal unsafe class RevWalkerHandle : Libgit2Object
{
internal RevWalkerHandle(git_revwalk *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -453,21 +491,23 @@ internal RevWalkerHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_revwalk_free((git_revwalk*) ptr);
+ NativeMethods.git_revwalk_free((git_revwalk*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_revwalk*(RevWalkerHandle handle)
{
- return (git_revwalk*) handle.Handle;
+ return (git_revwalk*)handle.AsIntPtr();
}
}
internal unsafe class RemoteHandle : Libgit2Object
{
internal RemoteHandle(git_remote *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -476,21 +516,23 @@ internal RemoteHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_remote_free((git_remote*) ptr);
+ NativeMethods.git_remote_free((git_remote*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_remote*(RemoteHandle handle)
{
- return (git_remote*) handle.Handle;
+ return (git_remote*)handle.AsIntPtr();
}
}
internal unsafe class ObjectHandle : Libgit2Object
{
internal ObjectHandle(git_object *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -499,21 +541,23 @@ internal ObjectHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_object_free((git_object*) ptr);
+ NativeMethods.git_object_free((git_object*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_object*(ObjectHandle handle)
{
- return (git_object*) handle.Handle;
+ return (git_object*)handle.AsIntPtr();
}
}
internal unsafe class RebaseHandle : Libgit2Object
{
internal RebaseHandle(git_rebase *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -522,21 +566,23 @@ internal RebaseHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_rebase_free((git_rebase*) ptr);
+ NativeMethods.git_rebase_free((git_rebase*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_rebase*(RebaseHandle handle)
{
- return (git_rebase*) handle.Handle;
+ return (git_rebase*)handle.AsIntPtr();
}
}
internal unsafe class OdbStreamHandle : Libgit2Object
{
internal OdbStreamHandle(git_odb_stream *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -545,21 +591,23 @@ internal OdbStreamHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_odb_stream_free((git_odb_stream*) ptr);
+ NativeMethods.git_odb_stream_free((git_odb_stream*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_odb_stream*(OdbStreamHandle handle)
{
- return (git_odb_stream*) handle.Handle;
+ return (git_odb_stream*)handle.AsIntPtr();
}
}
internal unsafe class WorktreeHandle : Libgit2Object
{
internal WorktreeHandle(git_worktree *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -568,14 +616,16 @@ internal WorktreeHandle(IntPtr ptr, bool owned)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.git_worktree_free((git_worktree*) ptr);
+ NativeMethods.git_worktree_free((git_worktree*)AsIntPtr());
+
+ return true;
}
public static implicit operator git_worktree*(WorktreeHandle handle)
{
- return (git_worktree*) handle.Handle;
+ return (git_worktree*)handle.AsIntPtr();
}
}
diff --git a/LibGit2Sharp/Core/Handles/Objects.tt b/LibGit2Sharp/Core/Handles/Objects.tt
index a6d1fa251..93707590e 100644
--- a/LibGit2Sharp/Core/Handles/Objects.tt
+++ b/LibGit2Sharp/Core/Handles/Objects.tt
@@ -73,7 +73,7 @@ for (var i = 0; i < cNames.Length; i++)
internal unsafe class <#= csNames[i] #> : Libgit2Object
{
internal <#= csNames[i] #>(<#= cNames[i] #> *ptr, bool owned)
- : base((void *) ptr, owned)
+ : base(ptr, owned)
{
}
@@ -82,14 +82,16 @@ for (var i = 0; i < cNames.Length; i++)
{
}
- public override void Free()
+ protected override bool ReleaseHandle()
{
- NativeMethods.<#= cNames[i] #>_free((<#= cNames[i] #>*) ptr);
+ NativeMethods.<#= cNames[i] #>_free((<#= cNames[i] #>*)AsIntPtr());
+
+ return true;
}
public static implicit operator <#= cNames[i] #>*(<#= csNames[i] #> handle)
{
- return (<#= cNames[i] #>*) handle.Handle;
+ return (<#= cNames[i] #>*)handle.AsIntPtr();
}
}
diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs
index bd80834bb..ba0a33144 100644
--- a/LibGit2Sharp/Network.cs
+++ b/LibGit2Sharp/Network.cs
@@ -216,11 +216,11 @@ private IEnumerable ListReferencesInternal(string url, CredentialsHan
static RemoteHandle BuildRemoteHandle(RepositoryHandle repoHandle, string url)
{
- Debug.Assert(repoHandle != null && !repoHandle.IsNull);
+ Debug.Assert(repoHandle != null && !repoHandle.IsInvalid);
Debug.Assert(url != null);
RemoteHandle remoteHandle = Proxy.git_remote_create_anonymous(repoHandle, url);
- Debug.Assert(remoteHandle != null && !(remoteHandle.IsNull));
+ Debug.Assert(remoteHandle != null && !remoteHandle.IsInvalid);
return remoteHandle;
}
diff --git a/LibGit2Sharp/Reference.cs b/LibGit2Sharp/Reference.cs
index 9530f2378..9a86195d1 100644
--- a/LibGit2Sharp/Reference.cs
+++ b/LibGit2Sharp/Reference.cs
@@ -35,7 +35,7 @@ private protected Reference(IRepository repo, string canonicalName, string targe
// This overload lets public-facing methods avoid having to use the pointers directly
internal static unsafe T BuildFromPtr(ReferenceHandle handle, Repository repo) where T : Reference
{
- return BuildFromPtr((git_reference*) handle.Handle, repo);
+ return BuildFromPtr((git_reference*)handle.AsIntPtr(), repo);
}
internal static unsafe T BuildFromPtr(git_reference* handle, Repository repo) where T : Reference
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index e23c9cd3b..fc777404e 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -575,7 +575,7 @@ internal GitObject LookupInternal(ObjectId id, GitObjectType type, string knownP
using (ObjectHandle obj = Proxy.git_object_lookup(handle, id, type))
{
- if (obj == null || obj.IsNull)
+ if (obj == null || obj.IsInvalid)
{
return null;
}
@@ -1781,7 +1781,7 @@ public void RevParse(string revision, out Reference reference, out GitObject obj
using (var objH = handles.Item1)
using (var refH = handles.Item2)
{
- reference = refH.IsNull ? null : Reference.BuildFromPtr(refH, this);
+ reference = refH.IsInvalid ? null : Reference.BuildFromPtr(refH, this);
obj = GitObject.BuildFrom(this, Proxy.git_object_id(objH), Proxy.git_object_type(objH), PathFromRevparseSpec(revision));
}
}
From f4fc1440b7d5345d49321dcd242190a55a1df68f Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Thu, 21 Nov 2024 23:53:17 -0500
Subject: [PATCH 126/147] Updates (#2128)
* Remove net6.0
* Add net9.0
* Update supported distros
* Fix centos.stream.9
* Update packages
* Reorder package reference item group
* Remove distro combinations that are missing images
---
.github/workflows/ci.yml | 44 ++++++++------------
LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 14 +++----
LibGit2Sharp/LibGit2Sharp.csproj | 17 ++++----
TrimmingTestApp/TrimmingTestApp.csproj | 2 +-
4 files changed, 33 insertions(+), 44 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9a7f9a0de..6d29a0999 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -21,7 +21,7 @@ jobs:
- name: Install .NET SDK
uses: actions/setup-dotnet@v4.0.0
with:
- dotnet-version: 8.0.x
+ dotnet-version: 9.0.x
- name: Build
run: dotnet build LibGit2Sharp.sln --configuration Release
- name: Upload packages
@@ -38,20 +38,18 @@ jobs:
strategy:
matrix:
arch: [ x64 ]
- os: [ windows-2019, windows-2022, macos-12, macos-13 ]
- tfm: [ net472, net6.0, net8.0 ]
+ os: [ windows-2019, windows-2022, macos-13 ]
+ tfm: [ net472, net8.0, net9.0 ]
exclude:
- - os: macos-12
- tfm: net472
- os: macos-13
tfm: net472
include:
- arch: arm64
os: macos-14
- tfm: net6.0
+ tfm: net8.0
- arch: arm64
os: macos-14
- tfm: net8.0
+ tfm: net9.0
fail-fast: false
steps:
- name: Checkout
@@ -62,8 +60,8 @@ jobs:
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: |
+ 9.0.x
8.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
test-linux:
@@ -73,28 +71,20 @@ jobs:
matrix:
arch: [ amd64 ]
# arch: [ amd64, arm64 ]
- 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' ]
+ distro: [ alpine.3.17, alpine.3.18, alpine.3.19, alpine.3.20, centos.stream.9, debian.12, fedora.40, ubuntu.20.04, ubuntu.22.04, ubuntu.24.04 ]
+ sdk: [ '8.0', '9.0' ]
exclude:
- - distro: alpine.3.13
- sdk: '8.0'
- - distro: alpine.3.14
- 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'
+ - distro: alpine.3.17
+ sdk: '9.0'
+ - distro: alpine.3.18
+ sdk: '9.0'
+ - distro: alpine.3.19
+ sdk: '9.0'
include:
- - sdk: '6.0'
- tfm: net6.0
- sdk: '8.0'
tfm: net8.0
+ - sdk: '9.0'
+ tfm: net9.0
fail-fast: false
steps:
- name: Checkout
@@ -108,5 +98,5 @@ jobs:
run: |
git_command="git config --global --add safe.directory /app"
test_command="dotnet test LibGit2Sharp.sln --configuration Release -p:TargetFrameworks=${{ matrix.tfm }} --logger "GitHubActions" -p:ExtraDefine=LEAKS_IDENTIFYING"
- 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"
+ docker run -t --rm --platform linux/${{ matrix.arch }} -v "$PWD:/app" -e OPENSSL_ENABLE_SHA1_SIGNATURES=1 gittools/build-images:${{ matrix.distro }}-sdk-${{ matrix.sdk }} sh -c "$git_command && $test_command"
diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
index 4d648eead..fb81a76a3 100644
--- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
+++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
@@ -1,7 +1,7 @@
- net472;net6.0;net8.0
+ net472;net8.0;net9.0
@@ -11,12 +11,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index 28404d948..8eadb87df 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -1,8 +1,8 @@
- net472;net6.0
- 10.0
+ net472;net8.0
+ 12.0
true
LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .NET
LibGit2Sharp contributors
@@ -24,10 +24,15 @@
libgit2-$(libgit2_hash.Substring(0,7))
-
+
true
+
+
+
+
+
@@ -38,12 +43,6 @@
-
-
-
-
-
-
diff --git a/TrimmingTestApp/TrimmingTestApp.csproj b/TrimmingTestApp/TrimmingTestApp.csproj
index 9cb7e75b4..3c6d341f6 100644
--- a/TrimmingTestApp/TrimmingTestApp.csproj
+++ b/TrimmingTestApp/TrimmingTestApp.csproj
@@ -1,7 +1,7 @@
- net8.0
+ net9.0
Exe
enable
enable
From d935c4959017e2bbe36124ac58449d7e1b3a659b Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 22 Nov 2024 22:46:19 -0500
Subject: [PATCH 127/147] Fix test warnings
---
LibGit2Sharp.Tests/ConfigurationFixture.cs | 29 ++++++++--------------
LibGit2Sharp.Tests/FilterBranchFixture.cs | 19 ++++++--------
LibGit2Sharp.Tests/ResetIndexFixture.cs | 5 ++--
3 files changed, 21 insertions(+), 32 deletions(-)
diff --git a/LibGit2Sharp.Tests/ConfigurationFixture.cs b/LibGit2Sharp.Tests/ConfigurationFixture.cs
index 999aa0336..aaee77b02 100644
--- a/LibGit2Sharp.Tests/ConfigurationFixture.cs
+++ b/LibGit2Sharp.Tests/ConfigurationFixture.cs
@@ -4,7 +4,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -56,9 +55,7 @@ public void CanAddAndReadMultivarFromTheLocalConfiguration()
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
- Assert.Empty(repo.Config
- .OfType>()
- .Where(x => x.Key == "unittests.plugin"));
+ Assert.DoesNotContain(repo.Config.OfType>(), x => x.Key == "unittests.plugin");
repo.Config.Add("unittests.plugin", "value1", ConfigurationLevel.Local);
repo.Config.Add("unittests.plugin", "value2", ConfigurationLevel.Local);
@@ -78,9 +75,7 @@ public void CanAddAndReadMultivarFromTheGlobalConfiguration()
using (var repo = new Repository(path))
{
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Global));
- Assert.Empty(repo.Config
- .OfType>()
- .Where(x => x.Key == "unittests.plugin"));
+ Assert.DoesNotContain(repo.Config.OfType>(), x => x.Key == "unittests.plugin");
repo.Config.Add("unittests.plugin", "value1", ConfigurationLevel.Global);
repo.Config.Add("unittests.plugin", "value2", ConfigurationLevel.Global);
@@ -157,9 +152,7 @@ public void CanUnsetAllFromTheLocalConfiguration()
repo.Config.UnsetAll("unittests.plugin");
- Assert.Empty(repo.Config
- .OfType>()
- .Where(x => x.Key == "unittests.plugin"));
+ Assert.DoesNotContain(repo.Config.OfType>(), x => x.Key == "unittests.plugin");
}
}
@@ -531,20 +524,20 @@ public void CanSetAndGetSearchPath()
{
string globalPath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
string systemPath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
- string xdgPath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
+ string xdgPath = Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName());
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, globalPath);
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.System, systemPath);
- GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, xdgPath);
+ GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, xdgPath);
Assert.Equal(globalPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global).Single());
Assert.Equal(systemPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.System).Single());
- Assert.Equal(xdgPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Xdg).Single());
+ Assert.Equal(xdgPath, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Xdg).Single());
// reset the search paths to their defaults
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.System, null);
- GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, null);
+ GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Xdg, null);
}
[Fact]
@@ -577,12 +570,12 @@ public void CanResetSearchPaths()
var newPaths = new string[] { Path.Combine(Constants.TemporaryReposPath, Path.GetRandomFileName()) };
// change to the non-default path
- GlobalSettings.SetConfigSearchPaths (ConfigurationLevel.Global, newPaths);
- Assert.Equal (newPaths, GlobalSettings.GetConfigSearchPaths (ConfigurationLevel.Global));
+ GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, newPaths);
+ Assert.Equal(newPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
// set it back to the default
- GlobalSettings.SetConfigSearchPaths (ConfigurationLevel.Global, null);
- Assert.Equal (oldPaths, GlobalSettings.GetConfigSearchPaths (ConfigurationLevel.Global));
+ GlobalSettings.SetConfigSearchPaths(ConfigurationLevel.Global, null);
+ Assert.Equal(oldPaths, GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global));
}
[Fact]
diff --git a/LibGit2Sharp.Tests/FilterBranchFixture.cs b/LibGit2Sharp.Tests/FilterBranchFixture.cs
index 2ca3e507a..0041e7646 100644
--- a/LibGit2Sharp.Tests/FilterBranchFixture.cs
+++ b/LibGit2Sharp.Tests/FilterBranchFixture.cs
@@ -3,7 +3,6 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
-using Xunit.Extensions;
namespace LibGit2Sharp.Tests
{
@@ -162,10 +161,8 @@ public void CanRewriteAuthorOfCommits()
AssertSucceedingButNotError();
- var nonBackedUpRefs = repo.Refs.Where(
- x => !x.CanonicalName.StartsWith("refs/original/") && !x.CanonicalName.StartsWith("refs/notes/"));
- Assert.Empty(repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = nonBackedUpRefs })
- .Where(c => c.Author.Name != "Ben Straub"));
+ var nonBackedUpRefs = repo.Refs.Where(x => !x.CanonicalName.StartsWith("refs/original/") && !x.CanonicalName.StartsWith("refs/notes/"));
+ Assert.DoesNotContain(repo.Commits.QueryBy(new CommitFilter { IncludeReachableFrom = nonBackedUpRefs }), c => c.Author.Name != "Ben Straub");
}
[Fact]
@@ -236,7 +233,7 @@ public void CanRewriteTreesByInjectingTreeEntry()
Assert.Equal(Array.Empty(),
repo.Commits
- .QueryBy(new CommitFilter {IncludeReachableFrom = repo.Branches})
+ .QueryBy(new CommitFilter { IncludeReachableFrom = repo.Branches })
.Where(c => c["README"] != null
&& c["README"].Target.Id != currentReadme.Target.Id)
.ToArray());
@@ -403,9 +400,9 @@ public void CanCustomizeTheNamespaceOfBackedUpRefs(string backupRefsNamespace)
AssertSucceedingButNotError();
- Assert.NotEmpty(repo.Refs.Where(x => x.CanonicalName.StartsWith("refs/original")));
+ Assert.DoesNotContain(repo.Refs, x => x.CanonicalName.StartsWith("refs/original"));
- Assert.Empty(repo.Refs.Where(x => x.CanonicalName.StartsWith("refs/rewritten")));
+ Assert.DoesNotContain(repo.Refs, x => x.CanonicalName.StartsWith("refs/rewritten"));
repo.Refs.RewriteHistory(new RewriteHistoryOptions
{
@@ -418,7 +415,7 @@ public void CanCustomizeTheNamespaceOfBackedUpRefs(string backupRefsNamespace)
AssertSucceedingButNotError();
- Assert.NotEmpty(repo.Refs.Where(x => x.CanonicalName.StartsWith("refs/rewritten")));
+ Assert.DoesNotContain(repo.Refs, x => x.CanonicalName.StartsWith("refs/rewritten"));
}
[Fact]
@@ -494,7 +491,7 @@ public void DoesNotRewriteRefsThatDontChange()
// Ensure br2 is still a merge commit
var parents = repo.Branches["br2"].Tip.Parents.ToList();
Assert.Equal(2, parents.Count());
- Assert.NotEmpty(parents.Where(c => c.Sha.StartsWith("9fd738e")));
+ Assert.DoesNotContain(parents, c => c.Sha.StartsWith("9fd738e"));
Assert.Equal("abc", parents.Single(c => !c.Sha.StartsWith("9fd738e")).Message);
}
@@ -535,7 +532,7 @@ public void CanNotOverWriteBackedUpReferences()
var newOriginalRefs = repo.Refs.FromGlob("refs/original/*").OrderBy(r => r.CanonicalName).ToArray();
Assert.Equal(originalRefs, newOriginalRefs);
- Assert.Empty(repo.Refs.Where(x => x.CanonicalName.StartsWith("refs/original/original/")));
+ Assert.DoesNotContain(repo.Refs, x => x.CanonicalName.StartsWith("refs/original/original/"));
}
[Fact]
diff --git a/LibGit2Sharp.Tests/ResetIndexFixture.cs b/LibGit2Sharp.Tests/ResetIndexFixture.cs
index 97a1eef88..d0228ae2b 100644
--- a/LibGit2Sharp.Tests/ResetIndexFixture.cs
+++ b/LibGit2Sharp.Tests/ResetIndexFixture.cs
@@ -1,4 +1,3 @@
-using System.IO;
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
@@ -62,7 +61,7 @@ public void ResetTheIndexWithTheHeadUnstagesEverything()
repo.Index.Replace(repo.Head.Tip);
RepositoryStatus newStatus = repo.RetrieveStatus();
- Assert.Empty(newStatus.Where(IsStaged));
+ Assert.DoesNotContain(newStatus, IsStaged);
// Assert that no reflog entry is created
Assert.Equal(reflogEntriesCount, repo.Refs.Log(repo.Refs.Head).Count());
@@ -120,7 +119,7 @@ public void CanResetTheIndexWhenARenameExists()
repo.Index.Replace(repo.Lookup("32eab9c"));
RepositoryStatus status = repo.RetrieveStatus();
- Assert.Empty(status.Where(IsStaged));
+ Assert.DoesNotContain(status, IsStaged);
}
}
From 0eed453cabb29e4a4b24eb82e0525ce1fb5df840 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Fri, 22 Nov 2024 22:48:54 -0500
Subject: [PATCH 128/147] Run dotnet format
---
LibGit2Sharp.Tests/BlameFixture.cs | 10 +-
LibGit2Sharp.Tests/CheckoutFixture.cs | 8 +-
LibGit2Sharp.Tests/ConflictFixture.cs | 4 +-
LibGit2Sharp.Tests/DescribeFixture.cs | 4 +-
LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs | 6 +-
.../DiffWorkdirToIndexFixture.cs | 4 +-
LibGit2Sharp.Tests/FileHistoryFixture.cs | 2 +-
LibGit2Sharp.Tests/MergeFixture.cs | 10 +-
LibGit2Sharp.Tests/NoteFixture.cs | 2 +-
LibGit2Sharp.Tests/OdbBackendFixture.cs | 8 +-
.../PatchEntryChangesFixture.cs | 56 +++----
LibGit2Sharp.Tests/RebaseFixture.cs | 4 +-
LibGit2Sharp.Tests/RefSpecFixture.cs | 2 +-
LibGit2Sharp.Tests/ReferenceFixture.cs | 4 +-
LibGit2Sharp.Tests/RemoveFixture.cs | 6 +-
.../RepositoryOptionsFixture.cs | 4 +-
LibGit2Sharp.Tests/ResetHeadFixture.cs | 2 +-
LibGit2Sharp.Tests/RevertFixture.cs | 10 +-
LibGit2Sharp.Tests/SetErrorFixture.cs | 4 +-
LibGit2Sharp.Tests/StashFixture.cs | 18 +--
LibGit2Sharp.Tests/TagFixture.cs | 2 +-
LibGit2Sharp.Tests/TreeDefinitionFixture.cs | 8 +-
LibGit2Sharp/AfterRebaseStepInfo.cs | 2 +-
LibGit2Sharp/BlameHunk.cs | 4 +-
LibGit2Sharp/CertificateSsh.cs | 6 +-
LibGit2Sharp/CertificateX509.cs | 4 +-
LibGit2Sharp/Core/Ensure.cs | 4 +-
LibGit2Sharp/Core/GitBlame.cs | 2 +-
LibGit2Sharp/Core/GitCertificateSshType.cs | 2 +-
LibGit2Sharp/Core/Handles/Objects.cs | 50 +++---
LibGit2Sharp/Core/Handles/Objects.tt | 2 +-
LibGit2Sharp/Core/Opaques.cs | 48 +++---
LibGit2Sharp/Core/Proxy.cs | 144 +++++++++---------
LibGit2Sharp/DiffTargets.cs | 2 +-
LibGit2Sharp/Filter.cs | 2 +-
LibGit2Sharp/FilterSource.cs | 2 +-
LibGit2Sharp/IDiffResult.cs | 2 +-
LibGit2Sharp/Index.cs | 2 +-
LibGit2Sharp/IndexReucEntryCollection.cs | 2 +-
LibGit2Sharp/ObjectId.cs | 4 +-
LibGit2Sharp/Rebase.cs | 2 +-
LibGit2Sharp/RefSpec.cs | 4 +-
LibGit2Sharp/RefSpecCollection.cs | 4 +-
LibGit2Sharp/ReferenceCollection.cs | 2 +-
LibGit2Sharp/Remote.cs | 3 +-
LibGit2Sharp/RemoteCallbacks.cs | 6 +-
LibGit2Sharp/RemoteCollection.cs | 3 +-
LibGit2Sharp/RepositoryExtensions.cs | 2 +-
LibGit2Sharp/RepositoryStatus.cs | 2 +-
LibGit2Sharp/RevertResult.cs | 2 +-
LibGit2Sharp/SimilarityOptions.cs | 12 +-
LibGit2Sharp/SmartSubtransport.cs | 8 +-
LibGit2Sharp/TagCollection.cs | 2 +-
LibGit2Sharp/TransientIndex.cs | 2 +-
LibGit2Sharp/Tree.cs | 3 +-
LibGit2Sharp/Worktree.cs | 2 +-
LibGit2Sharp/WorktreeCollection.cs | 6 +-
57 files changed, 266 insertions(+), 261 deletions(-)
diff --git a/LibGit2Sharp.Tests/BlameFixture.cs b/LibGit2Sharp.Tests/BlameFixture.cs
index da63dc124..8cefcfb45 100644
--- a/LibGit2Sharp.Tests/BlameFixture.cs
+++ b/LibGit2Sharp.Tests/BlameFixture.cs
@@ -62,10 +62,10 @@ public void CanBlameFromVariousTypes()
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
- AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = "HEAD" }));
- AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = repo.Head }));
- AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = repo.Head.Tip }));
- AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = repo.Branches["master"]}));
+ AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions { StartingAt = "HEAD" }));
+ AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions { StartingAt = repo.Head }));
+ AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions { StartingAt = repo.Head.Tip }));
+ AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions { StartingAt = repo.Branches["master"] }));
}
}
@@ -78,7 +78,7 @@ public void CanStopBlame()
// $ git blame .\new.txt
// 9fd738e8 (Scott Chacon 2010-05-24 10:19:19 -0700 1) my new file
// (be3563a comes after 9fd738e8)
- var blame = repo.Blame("new.txt", new BlameOptions {StoppingAt = "be3563a"});
+ var blame = repo.Blame("new.txt", new BlameOptions { StoppingAt = "be3563a" });
Assert.StartsWith("be3563a", blame[0].FinalCommit.Sha);
}
}
diff --git a/LibGit2Sharp.Tests/CheckoutFixture.cs b/LibGit2Sharp.Tests/CheckoutFixture.cs
index 8962cbc1d..045e20e1f 100644
--- a/LibGit2Sharp.Tests/CheckoutFixture.cs
+++ b/LibGit2Sharp.Tests/CheckoutFixture.cs
@@ -269,7 +269,7 @@ public void CanForcefullyCheckoutWithConflictingStagedChanges()
Assert.Throws(() => Commands.Checkout(repo, master.CanonicalName));
// Checkout with force option should succeed.
- Commands.Checkout(repo, master.CanonicalName, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force});
+ Commands.Checkout(repo, master.CanonicalName, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force });
// Assert that master branch is checked out.
Assert.True(repo.Branches["master"].IsCurrentRepositoryHead);
@@ -411,7 +411,7 @@ public void CheckingOutThroughBranchCallsCheckoutProgress()
Branch branch = repo.Branches[otherBranchName];
Commands.Checkout(repo, branch,
- new CheckoutOptions { OnCheckoutProgress = (path, completed, total) => wasCalled = true});
+ new CheckoutOptions { OnCheckoutProgress = (path, completed, total) => wasCalled = true });
Assert.True(wasCalled);
}
@@ -427,7 +427,7 @@ public void CheckingOutThroughRepositoryCallsCheckoutProgress()
PopulateBasicRepository(repo);
bool wasCalled = false;
- Commands.Checkout(repo, otherBranchName, new CheckoutOptions() { OnCheckoutProgress = (path, completed, total) => wasCalled = true});
+ Commands.Checkout(repo, otherBranchName, new CheckoutOptions() { OnCheckoutProgress = (path, completed, total) => wasCalled = true });
Assert.True(wasCalled);
}
@@ -779,7 +779,7 @@ public void CheckoutFromDetachedHead(string commitPointer)
public void CheckoutBranchFromDetachedHead()
{
string path = SandboxStandardTestRepo();
- using (var repo = new Repository(path, new RepositoryOptions{ Identity = Constants.Identity }))
+ using (var repo = new Repository(path, new RepositoryOptions { Identity = Constants.Identity }))
{
// Set the working directory to the current head
ResetAndCleanWorkingDirectory(repo);
diff --git a/LibGit2Sharp.Tests/ConflictFixture.cs b/LibGit2Sharp.Tests/ConflictFixture.cs
index b28270b7e..6317bf431 100644
--- a/LibGit2Sharp.Tests/ConflictFixture.cs
+++ b/LibGit2Sharp.Tests/ConflictFixture.cs
@@ -48,7 +48,7 @@ private static List
-
+
From 95b283b0d228219c4b4d47ab0b761f657dd22168 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 23 Nov 2024 20:00:44 -0500
Subject: [PATCH 133/147] React to ABI changes
---
LibGit2Sharp/ConfigurationLevel.cs | 5 +++++
LibGit2Sharp/Core/GitConfigEntry.cs | 4 ++--
LibGit2Sharp/Core/GitPushOptions.cs | 1 +
LibGit2Sharp/Core/GitWorktree.cs | 4 ++--
LibGit2Sharp/WorktreeCollection.cs | 16 +++++++---------
5 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/LibGit2Sharp/ConfigurationLevel.cs b/LibGit2Sharp/ConfigurationLevel.cs
index 9fd57df28..f0971a1c1 100644
--- a/LibGit2Sharp/ConfigurationLevel.cs
+++ b/LibGit2Sharp/ConfigurationLevel.cs
@@ -5,6 +5,11 @@
///
public enum ConfigurationLevel
{
+ ///
+ /// Worktree specific configuration file; $GIT_DIR/config.worktree
+ ///
+ Worktree = 6,
+
///
/// The local .git/config of the current repository.
///
diff --git a/LibGit2Sharp/Core/GitConfigEntry.cs b/LibGit2Sharp/Core/GitConfigEntry.cs
index 9eaa9e468..7af657894 100644
--- a/LibGit2Sharp/Core/GitConfigEntry.cs
+++ b/LibGit2Sharp/Core/GitConfigEntry.cs
@@ -1,4 +1,3 @@
-using System;
using System.Runtime.InteropServices;
namespace LibGit2Sharp.Core
@@ -8,9 +7,10 @@ internal unsafe struct GitConfigEntry
{
public char* namePtr;
public char* valuePtr;
+ public char* backend_type;
+ public char* origin_path;
public uint include_depth;
public uint level;
public void* freePtr;
- public void* payloadPtr;
}
}
diff --git a/LibGit2Sharp/Core/GitPushOptions.cs b/LibGit2Sharp/Core/GitPushOptions.cs
index ce1a58f7c..ac9a99e1e 100644
--- a/LibGit2Sharp/Core/GitPushOptions.cs
+++ b/LibGit2Sharp/Core/GitPushOptions.cs
@@ -11,5 +11,6 @@ internal class GitPushOptions
public GitProxyOptions ProxyOptions;
public RemoteRedirectMode FollowRedirects = RemoteRedirectMode.Initial;
public GitStrArrayManaged CustomHeaders;
+ public GitStrArrayManaged remote_push_options;
}
}
diff --git a/LibGit2Sharp/Core/GitWorktree.cs b/LibGit2Sharp/Core/GitWorktree.cs
index b3200dd91..6cc3c4d9a 100644
--- a/LibGit2Sharp/Core/GitWorktree.cs
+++ b/LibGit2Sharp/Core/GitWorktree.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
using System.Runtime.InteropServices;
-using System.Text;
namespace LibGit2Sharp.Core
{
@@ -36,6 +34,8 @@ internal class git_worktree_add_options
public int locked;
+ public int checkout_existing;
+
public IntPtr @ref = IntPtr.Zero;
public GitCheckoutOpts checkoutOpts = new GitCheckoutOpts { version = 1 };
diff --git a/LibGit2Sharp/WorktreeCollection.cs b/LibGit2Sharp/WorktreeCollection.cs
index 7bdd5fefa..29023b3dc 100644
--- a/LibGit2Sharp/WorktreeCollection.cs
+++ b/LibGit2Sharp/WorktreeCollection.cs
@@ -1,12 +1,10 @@
-using LibGit2Sharp.Core;
-using LibGit2Sharp.Core.Handles;
-using System;
+using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
-using System.IO;
using System.Linq;
-using System.Text;
+using LibGit2Sharp.Core;
+using LibGit2Sharp.Core.Handles;
namespace LibGit2Sharp
{
@@ -48,7 +46,7 @@ public virtual Worktree this[string name]
}
///
- ///
+ ///
///
///
///
@@ -89,7 +87,7 @@ public virtual Worktree Add(string committishOrBranchSpec, string name, string p
}
///
- ///
+ ///
///
///
///
@@ -112,7 +110,7 @@ public virtual Worktree Add(string name, string path, bool isLocked)
}
///
- ///
+ ///
///
///
///
@@ -122,7 +120,7 @@ public virtual bool Prune(Worktree worktree)
}
///
- ///
+ ///
///
///
///
From 9a11cbd903d85a831237ef2ca790226a5f195b22 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 23 Nov 2024 20:50:36 -0500
Subject: [PATCH 134/147] Update tests
---
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index dd7aef1e1..e91449b02 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -90,17 +90,17 @@ public void SetExtensions()
var extensions = GlobalSettings.GetExtensions();
// Assert that "noop" is supported by default
- Assert.Equal(new[] { "noop", "objectformat" }, extensions);
+ Assert.Equal(new[] { "noop", "objectformat", "worktreeconfig" }, extensions);
// Disable "noop" extensions
GlobalSettings.SetExtensions("!noop");
extensions = GlobalSettings.GetExtensions();
- Assert.Equal(new[] { "objectformat" }, extensions);
+ Assert.Equal(new[] { "objectformat", "worktreeconfig" }, extensions);
// Enable two new extensions (it will reset the configuration and "noop" will be enabled)
GlobalSettings.SetExtensions("partialclone", "newext");
extensions = GlobalSettings.GetExtensions();
- Assert.Equal(new[] { "newext", "noop", "objectformat", "partialclone" }, extensions);
+ Assert.Equal(new[] { "newext", "noop", "objectformat", "partialclone", "worktreeconfig" }, extensions);
}
}
}
From 8ef523da62d26385894ed40364b932d9c7ccbd8a Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sat, 23 Nov 2024 21:06:43 -0500
Subject: [PATCH 135/147] Comment out SSH test for now
---
LibGit2Sharp.Tests/CloneFixture.cs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs
index 9a4cfbb37..831f6779f 100644
--- a/LibGit2Sharp.Tests/CloneFixture.cs
+++ b/LibGit2Sharp.Tests/CloneFixture.cs
@@ -36,9 +36,9 @@ public void CanClone(string url)
}
[Theory]
- [InlineData("https://github.com/libgit2/TestGitRepository",1)]
- [InlineData("https://github.com/libgit2/TestGitRepository",5)]
- [InlineData("https://github.com/libgit2/TestGitRepository",7)]
+ [InlineData("https://github.com/libgit2/TestGitRepository", 1)]
+ [InlineData("https://github.com/libgit2/TestGitRepository", 5)]
+ [InlineData("https://github.com/libgit2/TestGitRepository", 7)]
public void CanCloneShallow(string url, int depth)
{
var scd = BuildSelfCleaningDirectory();
@@ -266,7 +266,7 @@ static Credentials CreateUsernamePasswordCredentials(string user, string pass, b
[SkippableTheory]
[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
- [InlineData("git@github.com:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
+ //[InlineData("git@github.com:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
{
var scd = BuildSelfCleaningDirectory();
From aacf7cd43422a5c1408df3b2052d2cbbb02dd707 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 24 Nov 2024 01:36:29 -0500
Subject: [PATCH 136/147] Add a CloneOptions constructor that takes a
FetchOptions
---
LibGit2Sharp/CloneOptions.cs | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/LibGit2Sharp/CloneOptions.cs b/LibGit2Sharp/CloneOptions.cs
index a315d76fc..12d47c9f3 100644
--- a/LibGit2Sharp/CloneOptions.cs
+++ b/LibGit2Sharp/CloneOptions.cs
@@ -4,12 +4,23 @@
namespace LibGit2Sharp
{
///
- /// Options to define clone behaviour
+ /// Options to define clone behavior
///
public sealed class CloneOptions : IConvertableToGitCheckoutOpts
{
///
- /// Creates default for a non-bare clone
+ /// Creates with specified for a non-bare clone.
+ ///
+ /// The fetch options to use.
+ public CloneOptions(FetchOptions fetchOptions) : this()
+ {
+ Ensure.ArgumentNotNull(fetchOptions, "fetchOptions");
+
+ FetchOptions = fetchOptions;
+ }
+
+ ///
+ /// Creates default for a non-bare clone.
///
public CloneOptions()
{
From 08fafd57295015a30a51257e980217819a12095e Mon Sep 17 00:00:00 2001
From: Enrique Raso Barbero
Date: Tue, 4 Jun 2024 10:43:01 +0200
Subject: [PATCH 137/147] Set GIT_CHECKOUT_FORCE as checkout strategy when
creating a worktree
---
LibGit2Sharp.Tests/WorktreeFixture.cs | 109 +++++++++++++++++++++++++-
LibGit2Sharp/Core/GitWorktree.cs | 6 +-
LibGit2Sharp/WorktreeCollection.cs | 19 ++---
3 files changed, 118 insertions(+), 16 deletions(-)
diff --git a/LibGit2Sharp.Tests/WorktreeFixture.cs b/LibGit2Sharp.Tests/WorktreeFixture.cs
index 5a706515b..e51a79942 100644
--- a/LibGit2Sharp.Tests/WorktreeFixture.cs
+++ b/LibGit2Sharp.Tests/WorktreeFixture.cs
@@ -3,8 +3,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Xunit;
namespace LibGit2Sharp.Tests
@@ -238,7 +236,7 @@ public void CanForcePruneLockedWorktree()
}
[Fact]
- public void CanAddWorktree()
+ public void CanAddWorktree_WithUncommitedChanges()
{
var repoPath = SandboxWorktreeTestRepo();
using (var repo = new Repository(repoPath))
@@ -252,15 +250,96 @@ public void CanAddWorktree()
Assert.False(worktree.IsLocked);
Assert.Equal(3, repo.Worktrees.Count());
+
+ // Check that branch contains same number of files and folders
+ // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
+ Assert.True(repo.RetrieveStatus().IsDirty);
+ var filesInMain = GetFilesOfRepo(repoPath);
+ var filesInBranch = GetFilesOfRepo(path);
+ Assert.NotEqual(filesInMain, filesInBranch);
+
+ repo.Reset(ResetMode.Hard);
+ repo.RemoveUntrackedFiles();
+
+ Assert.False(repo.RetrieveStatus().IsDirty);
+ filesInMain = GetFilesOfRepo(repoPath);
+ filesInBranch = GetFilesOfRepo(path);
+ Assert.Equal(filesInMain, filesInBranch);
+ }
+ }
+
+ [Fact]
+ public void CanAddWorktree_WithCommitedChanges()
+ {
+ var repoPath = SandboxWorktreeTestRepo();
+ using (var repo = new Repository(repoPath))
+ {
+ // stage all changes
+ Commands.Stage(repo, "*");
+ repo.Commit("Apply all changes", Constants.Signature, Constants.Signature);
+
+ Assert.Equal(2, repo.Worktrees.Count());
+
+ var name = "blah";
+ var path = Path.Combine(repo.Info.WorkingDirectory, "..", "worktrees", name);
+ var worktree = repo.Worktrees.Add(name, path, false);
+ Assert.Equal(name, worktree.Name);
+ Assert.False(worktree.IsLocked);
+
+ Assert.Equal(3, repo.Worktrees.Count());
+
+ // Check that branch contains same number of files and folders
+ // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
+ Assert.False(repo.RetrieveStatus().IsDirty);
+ var filesInMain = GetFilesOfRepo(repoPath);
+ var filesInBranch = GetFilesOfRepo(path);
+ Assert.Equal(filesInMain, filesInBranch);
+ }
+ }
+
+ [Fact]
+ public void CanAddLockedWorktree_WithUncommitedChanges()
+ {
+ var repoPath = SandboxWorktreeTestRepo();
+ using (var repo = new Repository(repoPath))
+ {
+ Assert.Equal(2, repo.Worktrees.Count());
+
+ var name = "blah";
+ var path = Path.Combine(repo.Info.WorkingDirectory, "..", "worktrees", name);
+ var worktree = repo.Worktrees.Add(name, path, true);
+ Assert.Equal(name, worktree.Name);
+ Assert.True(worktree.IsLocked);
+
+ Assert.Equal(3, repo.Worktrees.Count());
+
+ // Check that branch contains same number of files and folders
+ // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
+ Assert.True(repo.RetrieveStatus().IsDirty);
+ var filesInMain = GetFilesOfRepo(repoPath);
+ var filesInBranch = GetFilesOfRepo(path);
+ Assert.NotEqual(filesInMain, filesInBranch);
+
+ repo.Reset(ResetMode.Hard);
+ repo.RemoveUntrackedFiles();
+
+ Assert.False(repo.RetrieveStatus().IsDirty);
+ filesInMain = GetFilesOfRepo(repoPath);
+ filesInBranch = GetFilesOfRepo(path);
+ Assert.Equal(filesInMain, filesInBranch);
}
}
[Fact]
- public void CanAddLockedWorktree()
+ public void CanAddLockedWorktree_WithCommitedChanges()
{
var repoPath = SandboxWorktreeTestRepo();
using (var repo = new Repository(repoPath))
{
+ // stage all changes
+ Commands.Stage(repo, "*");
+ repo.Commit("Apply all changes", Constants.Signature, Constants.Signature);
+
Assert.Equal(2, repo.Worktrees.Count());
var name = "blah";
@@ -270,6 +349,13 @@ public void CanAddLockedWorktree()
Assert.True(worktree.IsLocked);
Assert.Equal(3, repo.Worktrees.Count());
+
+ // Check that branch contains same number of files and folders
+ // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
+ Assert.False(repo.RetrieveStatus().IsDirty);
+ var filesInMain = GetFilesOfRepo(repoPath);
+ var filesInBranch = GetFilesOfRepo(path);
+ Assert.Equal(filesInMain, filesInBranch);
}
}
@@ -292,7 +378,22 @@ public void CanAddWorktreeForCommittish()
Assert.Equal(committish, repository.Head.FriendlyName);
}
Assert.Equal(3, repo.Worktrees.Count());
+
+ // Check that branch contains same number of files and folders
+ // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
+ var filesInCommittish = new string[] { "numbers.txt", "super-file.txt" };
+ var filesInBranch = GetFilesOfRepo(path);
+ Assert.Equal(filesInCommittish, filesInBranch);
}
}
+
+ private static IEnumerable GetFilesOfRepo(string repoPath)
+ {
+ return Directory.GetFiles(repoPath, "*", SearchOption.AllDirectories)
+ .Where(fileName => !fileName.StartsWith($"{repoPath}\\.git", StringComparison.InvariantCultureIgnoreCase))
+ .Select(fileName => fileName.Replace($"{repoPath}\\", "", StringComparison.InvariantCultureIgnoreCase))
+ .OrderBy(fileName => fileName, StringComparer.InvariantCultureIgnoreCase)
+ .ToList();
+ }
}
}
diff --git a/LibGit2Sharp/Core/GitWorktree.cs b/LibGit2Sharp/Core/GitWorktree.cs
index 6cc3c4d9a..5e2aca023 100644
--- a/LibGit2Sharp/Core/GitWorktree.cs
+++ b/LibGit2Sharp/Core/GitWorktree.cs
@@ -38,7 +38,11 @@ internal class git_worktree_add_options
public IntPtr @ref = IntPtr.Zero;
- public GitCheckoutOpts checkoutOpts = new GitCheckoutOpts { version = 1 };
+ public GitCheckoutOpts checkoutOpts = new GitCheckoutOpts
+ {
+ version = 1,
+ checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_FORCE
+ };
}
[StructLayout(LayoutKind.Sequential)]
diff --git a/LibGit2Sharp/WorktreeCollection.cs b/LibGit2Sharp/WorktreeCollection.cs
index 29023b3dc..b79623c4c 100644
--- a/LibGit2Sharp/WorktreeCollection.cs
+++ b/LibGit2Sharp/WorktreeCollection.cs
@@ -48,11 +48,10 @@ public virtual Worktree this[string name]
///
///
///
- ///
- ///
- ///
+ /// A committish or branch name./param>
+ /// Name of the worktree.
+ /// Location of the worktree.
///
- ///
public virtual Worktree Add(string committishOrBranchSpec, string name, string path, bool isLocked)
{
if (string.Equals(committishOrBranchSpec, name))
@@ -61,7 +60,7 @@ public virtual Worktree Add(string committishOrBranchSpec, string name, string p
return null;
}
- git_worktree_add_options options = new git_worktree_add_options
+ var options = new git_worktree_add_options
{
version = 1,
locked = Convert.ToInt32(isLocked)
@@ -81,20 +80,18 @@ public virtual Worktree Add(string committishOrBranchSpec, string name, string p
}
}
-
-
return this[name];
}
///
///
///
- ///
- ///
- ///
+ /// A committish or branch name./param>
+ /// Name of the worktree.
+ /// Location of the worktree.
public virtual Worktree Add(string name, string path, bool isLocked)
{
- git_worktree_add_options options = new git_worktree_add_options
+ var options = new git_worktree_add_options
{
version = 1,
locked = Convert.ToInt32(isLocked)
From f145a2c276fefb10d3e20ab92bd398f4251f0b8f Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 24 Nov 2024 02:48:19 -0500
Subject: [PATCH 138/147] Tweaks
---
LibGit2Sharp.Tests/WorktreeFixture.cs | 16 ++++++----------
LibGit2Sharp/WorktreeCollection.cs | 8 ++++----
2 files changed, 10 insertions(+), 14 deletions(-)
diff --git a/LibGit2Sharp.Tests/WorktreeFixture.cs b/LibGit2Sharp.Tests/WorktreeFixture.cs
index e51a79942..224a99dbe 100644
--- a/LibGit2Sharp.Tests/WorktreeFixture.cs
+++ b/LibGit2Sharp.Tests/WorktreeFixture.cs
@@ -1,8 +1,8 @@
-using LibGit2Sharp.Tests.TestHelpers;
-using System;
+using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
namespace LibGit2Sharp.Tests
@@ -252,7 +252,6 @@ public void CanAddWorktree_WithUncommitedChanges()
Assert.Equal(3, repo.Worktrees.Count());
// Check that branch contains same number of files and folders
- // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
Assert.True(repo.RetrieveStatus().IsDirty);
var filesInMain = GetFilesOfRepo(repoPath);
var filesInBranch = GetFilesOfRepo(path);
@@ -289,10 +288,10 @@ public void CanAddWorktree_WithCommitedChanges()
Assert.Equal(3, repo.Worktrees.Count());
// Check that branch contains same number of files and folders
- // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
Assert.False(repo.RetrieveStatus().IsDirty);
var filesInMain = GetFilesOfRepo(repoPath);
var filesInBranch = GetFilesOfRepo(path);
+
Assert.Equal(filesInMain, filesInBranch);
}
}
@@ -314,7 +313,6 @@ public void CanAddLockedWorktree_WithUncommitedChanges()
Assert.Equal(3, repo.Worktrees.Count());
// Check that branch contains same number of files and folders
- // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
Assert.True(repo.RetrieveStatus().IsDirty);
var filesInMain = GetFilesOfRepo(repoPath);
var filesInBranch = GetFilesOfRepo(path);
@@ -351,7 +349,6 @@ public void CanAddLockedWorktree_WithCommitedChanges()
Assert.Equal(3, repo.Worktrees.Count());
// Check that branch contains same number of files and folders
- // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
Assert.False(repo.RetrieveStatus().IsDirty);
var filesInMain = GetFilesOfRepo(repoPath);
var filesInBranch = GetFilesOfRepo(path);
@@ -380,7 +377,6 @@ public void CanAddWorktreeForCommittish()
Assert.Equal(3, repo.Worktrees.Count());
// Check that branch contains same number of files and folders
- // NOTE: There is an open bug - [Repository.Worktrees.Add leaves now worktree empty](https://github.com/libgit2/libgit2sharp/issues/2037)
var filesInCommittish = new string[] { "numbers.txt", "super-file.txt" };
var filesInBranch = GetFilesOfRepo(path);
Assert.Equal(filesInCommittish, filesInBranch);
@@ -390,9 +386,9 @@ public void CanAddWorktreeForCommittish()
private static IEnumerable GetFilesOfRepo(string repoPath)
{
return Directory.GetFiles(repoPath, "*", SearchOption.AllDirectories)
- .Where(fileName => !fileName.StartsWith($"{repoPath}\\.git", StringComparison.InvariantCultureIgnoreCase))
- .Select(fileName => fileName.Replace($"{repoPath}\\", "", StringComparison.InvariantCultureIgnoreCase))
- .OrderBy(fileName => fileName, StringComparer.InvariantCultureIgnoreCase)
+ .Where(fileName => !fileName.StartsWith(Path.Combine(repoPath, ".git")))
+ .Select(fileName => fileName.Replace($"{repoPath}{Path.DirectorySeparatorChar}", ""))
+ .OrderBy(fileName => fileName)
.ToList();
}
}
diff --git a/LibGit2Sharp/WorktreeCollection.cs b/LibGit2Sharp/WorktreeCollection.cs
index b79623c4c..d99e11d7a 100644
--- a/LibGit2Sharp/WorktreeCollection.cs
+++ b/LibGit2Sharp/WorktreeCollection.cs
@@ -46,9 +46,9 @@ public virtual Worktree this[string name]
}
///
- ///
+ /// Creates a worktree.
///
- /// A committish or branch name./param>
+ /// The committish to checkout into the new worktree.
/// Name of the worktree.
/// Location of the worktree.
///
@@ -84,11 +84,11 @@ public virtual Worktree Add(string committishOrBranchSpec, string name, string p
}
///
- ///
+ /// Creates a worktree.
///
- /// A committish or branch name./param>
/// Name of the worktree.
/// Location of the worktree.
+ ///
public virtual Worktree Add(string name, string path, bool isLocked)
{
var options = new git_worktree_add_options
From 704a25bb73b13c9301346286d8120158fc950365 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Sun, 24 Nov 2024 02:50:24 -0500
Subject: [PATCH 139/147] Use safe instead of force
---
LibGit2Sharp/Core/GitWorktree.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/Core/GitWorktree.cs b/LibGit2Sharp/Core/GitWorktree.cs
index 5e2aca023..2e17bc20d 100644
--- a/LibGit2Sharp/Core/GitWorktree.cs
+++ b/LibGit2Sharp/Core/GitWorktree.cs
@@ -41,7 +41,7 @@ internal class git_worktree_add_options
public GitCheckoutOpts checkoutOpts = new GitCheckoutOpts
{
version = 1,
- checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_FORCE
+ checkout_strategy = CheckoutStrategy.GIT_CHECKOUT_SAFE
};
}
From 9014820e3a81cf65bf78a623c36a34e6e3a1aa6e Mon Sep 17 00:00:00 2001
From: Lucas Trzesniewski
Date: Tue, 7 May 2024 18:06:22 +0200
Subject: [PATCH 140/147] Make owner validation configurable
---
.gitignore | 1 +
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 15 ++++++++++
LibGit2Sharp/Core/NativeMethods.cs | 8 ++++++
LibGit2Sharp/Core/Proxy.cs | 32 +++++++++++++++++++++
LibGit2Sharp/GlobalSettings.cs | 13 +++++++++
5 files changed, 69 insertions(+)
diff --git a/.gitignore b/.gitignore
index 32e17b4d0..77452df54 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@ Thumbs.db
*.ncb
*.suo
.vs/
+.idea/
*.sln.ide/
*.tlb
*.tlh
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index e91449b02..17c11083d 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -102,5 +102,20 @@ public void SetExtensions()
extensions = GlobalSettings.GetExtensions();
Assert.Equal(new[] { "newext", "noop", "objectformat", "partialclone", "worktreeconfig" }, extensions);
}
+
+ [Fact]
+ public void OwnerValidation()
+ {
+ // Assert that owner validation is enabled by default
+ Assert.True(GlobalSettings.OwnerValidation);
+
+ // Disable owner validation
+ GlobalSettings.OwnerValidation = false;
+ Assert.False(GlobalSettings.OwnerValidation);
+
+ // Enable it again
+ GlobalSettings.OwnerValidation = true;
+ Assert.True(GlobalSettings.OwnerValidation);
+ }
}
}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index e8e59843e..f6e6d9a31 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -746,6 +746,10 @@ internal static extern int git_libgit2_opts(int option, uint level,
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern int git_libgit2_opts(int option, int enabled);
+ // git_libgit2_opts(GIT_OPT_GET_*, int *enabled)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern unsafe int git_libgit2_opts(int option, int* enabled);
+
// git_libgit2_opts(GIT_OPT_SET_USER_AGENT, const char *path)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern int git_libgit2_opts(int option,
@@ -782,6 +786,10 @@ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, In
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int enabled);
+ // git_libgit2_opts(GIT_OPT_GET_*, int enabled)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern unsafe int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int* enabled);
+
// git_libgit2_opts(GIT_OPT_SET_USER_AGENT, const char *path)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8,
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index cf0a7e3d0..08555eb02 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -3397,6 +3397,8 @@ private enum LibGit2Option
SetOdbLoosePriority, // GIT_OPT_SET_ODB_LOOSE_PRIORITY,
GetExtensions, // GIT_OPT_GET_EXTENSIONS,
SetExtensions, // GIT_OPT_SET_EXTENSIONS
+ GetOwnerValidation, // GIT_OPT_GET_OWNER_VALIDATION
+ SetOwnerValidation, // GIT_OPT_SET_OWNER_VALIDATION
}
///
@@ -3570,6 +3572,36 @@ public static string[] git_libgit2_opts_get_extensions()
}
}
+ ///
+ /// Gets the value of owner validation
+ ///
+ public static unsafe bool git_libgit2_opts_get_owner_validation()
+ {
+ // libgit2 expects non-zero value for true
+ int res, enabled;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.GetOwnerValidation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, &enabled);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetOwnerValidation, &enabled);
+ Ensure.ZeroResult(res);
+ return enabled != 0;
+ }
+
+ ///
+ /// Enable or disable owner validation
+ ///
+ /// true to enable owner validation, false otherwise
+ public static void git_libgit2_opts_set_owner_validation(bool enabled)
+ {
+ // libgit2 expects non-zero value for true
+ int res;
+ if (isOSXArm64)
+ res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.SetOwnerValidation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, enabled ? 1 : 0);
+ else
+ res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetOwnerValidation, enabled ? 1 : 0);
+ Ensure.ZeroResult(res);
+ }
+
#endregion
#region git_worktree_
diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs
index bf7875f96..e11410e28 100644
--- a/LibGit2Sharp/GlobalSettings.cs
+++ b/LibGit2Sharp/GlobalSettings.cs
@@ -204,6 +204,19 @@ public static string NativeLibraryPath
}
}
+ ///
+ /// Controls the status of repository directory owner validation.
+ ///
+ ///
+ /// By default, repository directories must be owned by the current user to be opened. This can be disabled by setting this property to false.
+ /// Note that disabling this can lead to security vulnerabilities (see CVE-2022-24765).
+ ///
+ public static bool OwnerValidation
+ {
+ get => Proxy.git_libgit2_opts_get_owner_validation();
+ set => Proxy.git_libgit2_opts_set_owner_validation(value);
+ }
+
internal static string GetAndLockNativeLibraryPath()
{
nativeLibraryPathLocked = true;
From f2185721892e3fff3978d11d63df1b208497d7aa Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 25 Nov 2024 23:36:47 -0500
Subject: [PATCH 141/147] Undo gitignore change
---
.gitignore | 1 -
1 file changed, 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 77452df54..32e17b4d0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,7 +14,6 @@ Thumbs.db
*.ncb
*.suo
.vs/
-.idea/
*.sln.ide/
*.tlb
*.tlh
From d623e3e1af4c6297a725f1703a01c753cb53c0e8 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 25 Nov 2024 23:48:47 -0500
Subject: [PATCH 142/147] Tweaks
---
LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 10 +++---
LibGit2Sharp/Core/NativeMethods.cs | 20 +++++++-----
LibGit2Sharp/Core/Proxy.cs | 19 +++++++++---
LibGit2Sharp/GlobalSettings.cs | 34 +++++++++++++--------
4 files changed, 53 insertions(+), 30 deletions(-)
diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
index 17c11083d..925efc3d0 100644
--- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
+++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs
@@ -107,15 +107,15 @@ public void SetExtensions()
public void OwnerValidation()
{
// Assert that owner validation is enabled by default
- Assert.True(GlobalSettings.OwnerValidation);
+ Assert.True(GlobalSettings.GetOwnerValidation());
// Disable owner validation
- GlobalSettings.OwnerValidation = false;
- Assert.False(GlobalSettings.OwnerValidation);
+ GlobalSettings.SetOwnerValidation(false);
+ Assert.False(GlobalSettings.GetOwnerValidation());
// Enable it again
- GlobalSettings.OwnerValidation = true;
- Assert.True(GlobalSettings.OwnerValidation);
+ GlobalSettings.SetOwnerValidation(true);
+ Assert.True(GlobalSettings.GetOwnerValidation());
}
}
}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index f6e6d9a31..cbb850b16 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -1,6 +1,8 @@
using System;
using System.IO;
+#if NET
using System.Reflection;
+#endif
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
@@ -743,13 +745,10 @@ internal static extern int git_libgit2_opts(int option, uint level,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string path);
// git_libgit2_opts(GIT_OPT_ENABLE_*, int enabled)
+ // git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, int enabled)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern int git_libgit2_opts(int option, int enabled);
- // git_libgit2_opts(GIT_OPT_GET_*, int *enabled)
- [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe int git_libgit2_opts(int option, int* enabled);
-
// git_libgit2_opts(GIT_OPT_SET_USER_AGENT, const char *path)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern int git_libgit2_opts(int option,
@@ -766,6 +765,10 @@ internal static extern int git_libgit2_opts(int option,
// git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
internal static extern int git_libgit2_opts(int option, out GitStrArray extensions);
+
+ // git_libgit2_opts(GIT_OPT_GET_OWNER_VALIDATION, int *enabled)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
+ internal static extern unsafe int git_libgit2_opts(int option, int* enabled);
#endregion
#region git_libgit2_opts_osxarm64
@@ -783,13 +786,10 @@ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, In
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string path);
// git_libgit2_opts(GIT_OPT_ENABLE_*, int enabled)
+ // git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, int enabled)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int enabled);
- // git_libgit2_opts(GIT_OPT_GET_*, int enabled)
- [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
- internal static extern unsafe int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int* enabled);
-
// git_libgit2_opts(GIT_OPT_SET_USER_AGENT, const char *path)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8,
@@ -806,6 +806,10 @@ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, In
// git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out)
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, out GitStrArray extensions);
+
+ // git_libgit2_opts(GIT_OPT_GET_OWNER_VALIDATION, int *enabled)
+ [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")]
+ internal static extern unsafe int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int* enabled);
#endregion
[DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)]
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 08555eb02..83d35e22c 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -3577,13 +3577,20 @@ public static string[] git_libgit2_opts_get_extensions()
///
public static unsafe bool git_libgit2_opts_get_owner_validation()
{
- // libgit2 expects non-zero value for true
- int res, enabled;
+ int res;
+ int enabled;
+
if (isOSXArm64)
+ {
res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.GetOwnerValidation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, &enabled);
+ }
else
+ {
res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetOwnerValidation, &enabled);
+ }
+
Ensure.ZeroResult(res);
+
return enabled != 0;
}
@@ -3593,15 +3600,19 @@ public static unsafe bool git_libgit2_opts_get_owner_validation()
/// true to enable owner validation, false otherwise
public static void git_libgit2_opts_set_owner_validation(bool enabled)
{
- // libgit2 expects non-zero value for true
int res;
+
if (isOSXArm64)
+ {
res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.SetOwnerValidation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, enabled ? 1 : 0);
+ }
else
+ {
res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetOwnerValidation, enabled ? 1 : 0);
+ }
+
Ensure.ZeroResult(res);
}
-
#endregion
#region git_worktree_
diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs
index e11410e28..9807155e7 100644
--- a/LibGit2Sharp/GlobalSettings.cs
+++ b/LibGit2Sharp/GlobalSettings.cs
@@ -204,19 +204,6 @@ public static string NativeLibraryPath
}
}
- ///
- /// Controls the status of repository directory owner validation.
- ///
- ///
- /// By default, repository directories must be owned by the current user to be opened. This can be disabled by setting this property to false.
- /// Note that disabling this can lead to security vulnerabilities (see CVE-2022-24765).
- ///
- public static bool OwnerValidation
- {
- get => Proxy.git_libgit2_opts_get_owner_validation();
- set => Proxy.git_libgit2_opts_set_owner_validation(value);
- }
-
internal static string GetAndLockNativeLibraryPath()
{
nativeLibraryPathLocked = true;
@@ -430,5 +417,26 @@ public static string GetUserAgent()
{
return Proxy.git_libgit2_opts_get_user_agent();
}
+
+ ///
+ /// Gets the owner validation setting for repository directories.
+ ///
+ ///
+ public static bool GetOwnerValidation()
+ {
+ return Proxy.git_libgit2_opts_get_owner_validation();
+ }
+
+ ///
+ /// Sets whether repository directories should be owned by the current user. The default is to validate ownership.
+ ///
+ ///
+ /// Disabling owner validation can lead to security vulnerabilities (see CVE-2022-24765).
+ ///
+ /// true to enable owner validation; otherwise, false.
+ public static void SetOwnerValidation(bool enabled)
+ {
+ Proxy.git_libgit2_opts_set_owner_validation(enabled);
+ }
}
}
From d89638caed7baca525ac02d0098dfb834310c45a Mon Sep 17 00:00:00 2001
From: Tyrie Vella
Date: Thu, 4 Jan 2024 12:51:40 -0800
Subject: [PATCH 143/147] fix #2071 ObjectDatabase.Write(Stream, long) does
not respect T
---
LibGit2Sharp/ObjectDatabase.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs
index 42b65d7d0..1bad9c907 100644
--- a/LibGit2Sharp/ObjectDatabase.cs
+++ b/LibGit2Sharp/ObjectDatabase.cs
@@ -202,7 +202,7 @@ public virtual ObjectId Write(Stream stream, long numberOfBytesToConsume) whe
throw new ArgumentException("The stream cannot be read from.", nameof(stream));
}
- using (var odbStream = Proxy.git_odb_open_wstream(handle, numberOfBytesToConsume, GitObjectType.Blob))
+ using (var odbStream = Proxy.git_odb_open_wstream(handle, numberOfBytesToConsume, GitObject.TypeToGitKindMap[typeof(T)]))
{
var buffer = new byte[4 * 1024];
long totalRead = 0;
From 2dd7eca45c2f95f24817ba8fc6270989df14f78e Mon Sep 17 00:00:00 2001
From: Tyrie Vella
Date: Thu, 11 Feb 2021 13:28:49 -0800
Subject: [PATCH 144/147] Test and fix for
https://github.com/libgit2/libgit2sharp/issues/1869
---
LibGit2Sharp.Tests/TreeDefinitionFixture.cs | 18 ++++++++++++++++++
LibGit2Sharp/TreeDefinition.cs | 1 +
2 files changed, 19 insertions(+)
diff --git a/LibGit2Sharp.Tests/TreeDefinitionFixture.cs b/LibGit2Sharp.Tests/TreeDefinitionFixture.cs
index 99d866c09..6c0c0a41a 100644
--- a/LibGit2Sharp.Tests/TreeDefinitionFixture.cs
+++ b/LibGit2Sharp.Tests/TreeDefinitionFixture.cs
@@ -587,5 +587,23 @@ public void CanAddAnExistingBlobEntryWithAnExistingTree()
Assert.NotNull(td["1/branch_file.txt"]);
}
}
+
+ [Fact]
+ public void CanRemoveADirectoryWithChildren()
+ {
+ const string blobSha = "a8233120f6ad708f843d861ce2b7228ec4e3dec6";
+ string path = SandboxBareTestRepo();
+ using (var repo = new Repository(path))
+ {
+ TreeDefinition td = new TreeDefinition();
+ var blob = repo.Lookup(blobSha);
+ td.Add("folder/subfolder/file1", blob, Mode.NonExecutableFile);
+ td.Add("folder/file1", blob, Mode.NonExecutableFile);
+ td.Remove("folder");
+ Assert.Null(td["folder"]);
+ Tree t = repo.ObjectDatabase.CreateTree(td);
+ Assert.Null(t["folder"]);
+ }
+ }
}
}
diff --git a/LibGit2Sharp/TreeDefinition.cs b/LibGit2Sharp/TreeDefinition.cs
index 73c21aac7..91389f6e3 100644
--- a/LibGit2Sharp/TreeDefinition.cs
+++ b/LibGit2Sharp/TreeDefinition.cs
@@ -94,6 +94,7 @@ public virtual TreeDefinition Remove(string treeEntryPath)
if (segments.Item2 == null)
{
entries.Remove(segments.Item1);
+ unwrappedTrees.Remove(segments.Item1);
}
if (!unwrappedTrees.ContainsKey(segments.Item1))
From ee53bdd8a9f5cfecfc8750e28a1f5c0d34690ce0 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 2 Dec 2024 22:02:44 -0500
Subject: [PATCH 145/147] Update CHANGES.md for v0.31
---
CHANGES.md | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/CHANGES.md b/CHANGES.md
index 1d68e6169..3f0fc677b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,22 @@
# LibGit2Sharp Changes
+## v0.31 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.30.0..0.31.0))
+
+### Changes
+- This release includes [libgit2 v1.8.4](https://github.com/libgit2/libgit2/releases/tag/v1.8.4).
+- The ppc64le architecture is now supported on Linux.
+- .NET 6 has reached end of support, so LibGit2Sharp now targets `net472` and `net8.0`.
+
+### Additions
+- Adds Depth to FetchOptions allowing for shallow cloning [#2070](https://github.com/libgit2/libgit2sharp/pull/2070)
+- Make owner validation configurable [#2093](https://github.com/libgit2/libgit2sharp/pull/2093)
+- Add a CloneOptions constructor that takes a FetchOptions [#2132](https://github.com/libgit2/libgit2sharp/pull/2132)
+
+### Fixes
+- TreeDefinition.Remove fails to remove unwrapped trees [#1869](https://github.com/libgit2/libgit2sharp/issues/1869)
+- ObjectDatabase.Write(Stream stream...) overload does not respect T [#2071](https://github.com/libgit2/libgit2sharp/issues/2071)
+- Repository.Worktrees.Add leaves now worktree empty [#2037](https://github.com/libgit2/libgit2sharp/issues/2037)
+
## v0.30 - ([diff](https://github.com/libgit2/libgit2sharp/compare/0.29.0..0.30.0))
### Changes
From 827658917a337d508615e78f89b0102ea68fc6d5 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Tue, 3 Dec 2024 17:40:35 -0500
Subject: [PATCH 146/147] Add note about new SSH support
---
CHANGES.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGES.md b/CHANGES.md
index 3f0fc677b..a00b598d7 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -4,6 +4,7 @@
### Changes
- This release includes [libgit2 v1.8.4](https://github.com/libgit2/libgit2/releases/tag/v1.8.4).
+ - SSH is now supported through [libgit2's support for OpenSSH](https://github.com/libgit2/libgit2/pull/6617).
- The ppc64le architecture is now supported on Linux.
- .NET 6 has reached end of support, so LibGit2Sharp now targets `net472` and `net8.0`.
From 50d697881e857ea0c78d63cc7f23fece3f526852 Mon Sep 17 00:00:00 2001
From: Brandon Ording
Date: Mon, 20 Jan 2025 17:49:17 -0500
Subject: [PATCH 147/147] Use arm runner images (#2141)
---
.github/workflows/ci.yml | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6d29a0999..54837ac35 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -66,11 +66,10 @@ jobs:
run: dotnet test LibGit2Sharp.sln --configuration Release --framework ${{ matrix.tfm }} --logger "GitHubActions" /p:ExtraDefine=LEAKS_IDENTIFYING
test-linux:
name: Test / ${{ matrix.distro }} / ${{ matrix.arch }} / ${{ matrix.tfm }}
- runs-on: ubuntu-22.04
+ runs-on: ${{ matrix.runnerImage }}
strategy:
matrix:
- arch: [ amd64 ]
- # arch: [ amd64, arm64 ]
+ arch: [ amd64, arm64 ]
distro: [ alpine.3.17, alpine.3.18, alpine.3.19, alpine.3.20, centos.stream.9, debian.12, fedora.40, ubuntu.20.04, ubuntu.22.04, ubuntu.24.04 ]
sdk: [ '8.0', '9.0' ]
exclude:
@@ -85,15 +84,16 @@ jobs:
tfm: net8.0
- sdk: '9.0'
tfm: net9.0
+ - arch: amd64
+ runnerImage: ubuntu-22.04
+ - arch: arm64
+ runnerImage: ubuntu-22.04-arm
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4.1.2
with:
fetch-depth: 0
- - name: Setup QEMU
- if: matrix.arch == 'arm64'
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- name: Run ${{ matrix.tfm }} tests
run: |
git_command="git config --global --add safe.directory /app"