From 85d41fedc4a4c7ca1dc6f6682f722ef5d28d2968 Mon Sep 17 00:00:00 2001 From: Andrei Balint Date: Tue, 9 Apr 2024 17:23:25 +0300 Subject: [PATCH] Studio STUD-6_8_8_3_2: add libgit2 feature info This is useful in order to differentiate for example between WinHttp and Schannel --- LibGit2Sharp/Core/NativeMethods.cs | 1 + LibGit2Sharp/GlobalSettings.cs | 39 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 15d6462e0..aca1ae144 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -96,6 +96,7 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor { Trace.TraceInformation("Using git with schannel"); libraryName = libraryName + "_schannel"; + GlobalSettings.SetHttpBackend(HttpsBackend.Schannel); } // Use GlobalSettings.NativeLibraryPath when set. diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs index 06b2e6773..52e2b128f 100644 --- a/LibGit2Sharp/GlobalSettings.cs +++ b/LibGit2Sharp/GlobalSettings.cs @@ -21,6 +21,7 @@ public static class GlobalSettings private static string nativeLibraryPath; private static bool nativeLibraryPathLocked; private static readonly string nativeLibraryDefaultPath = null; + private static HttpsBackend httpsBackend = HttpsBackend.WinHttp; static GlobalSettings() { @@ -420,5 +421,43 @@ public static string GetUserAgent() { return Proxy.git_libgit2_opts_get_user_agent(); } + + /// + /// Check libgit supported features + /// + public static bool HasFeature(LibGitFeature feature) + { + return feature switch + { + LibGitFeature.DefaultCredentials => httpsBackend == HttpsBackend.WinHttp, + _ => false + }; + } + + internal static void SetHttpBackend(HttpsBackend backend) + { + httpsBackend = backend; + } + } + + /// + /// List of supported libgit features + /// + public enum LibGitFeature + { + /// + /// Not used + /// + None, + /// + /// When supported, returning 'null' from the credentials manager acts as fallback attempt like using Windows authentication for WinHttp transport + /// + DefaultCredentials + } + + internal enum HttpsBackend + { + WinHttp, + Schannel } }