"invalid version 0 on git_proxy_options" thrown when natives are built from source
Hi, I'm currently trying to make a custom build that uses libssh2 instead of exec for SSH, since I don't want OpenSSH windows to spawn as my program makes requests. I changed this flag, then followed through the rest of the compilation steps both for native binaries and lg2s.
I then tried pulling, not on a proxy, using this code:
var fOptions = new FetchOptions ();
fOptions.Prune = UpdaterMod.settings.pruneOld;
var mOptions = new MergeOptions ();
mOptions.CommitOnSuccess = true;
mOptions.FileConflictStrategy = UpdaterMod.settings.onFileConflict;
var sig = new Signature (new Identity (modName, email), DateTimeOffset.Now);
try {
string logHolder = "";
Commands.Fetch (repo, remote.Name, refSpecs, fOptions, logHolder);
if (logHolder.Length > 0)
LogMsg (logHolder, LogMode.Warn);
}
catch (Exception e) {
LogMsg ($"Could not fetch data from remote repo: {e.Message}", LogMode.Error);
return;
}
Expected behavior
The program should attempt to pull without trying to use a proxy.
Actual behavior
The caught exception contains the message in the title.
System information
Windows 10 10.0.19045
AMD Ryzen 5 3600
Other useful information
This issue persists when the flag is switched back to exec
Having the same problem when building from source on FreeBSD (and using non-vendored libgit2). Can't figure where does 0 come from.
Putting a debugging output into
public static unsafe void git_submodule_update(SubmoduleHandle submodule, bool init, ref GitSubmoduleUpdateOptions options)
reveals that C# side passes 1 correctly. It might have something to do with libgit2 itself. There was a suspiciously similar bug report: https://github.com/libgit2/libgit2/issues/6172
Okay, here's my research. I added the following debugging output:
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 83d35e22..ddcff5ef 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -3010,6 +3010,7 @@ public static unsafe void git_submodule_add_to_index(SubmoduleHandle submodule,
public static unsafe void git_submodule_update(SubmoduleHandle submodule, bool init, ref GitSubmoduleUpdateOptions options)
{
+ Console.WriteLine($"======> git_submodule_update proxy version {options.FetchOptions.ProxyOptions.Version}");
var res = NativeMethods.git_submodule_update(submodule, init, ref options);
Ensure.ZeroResult(res);
}
When running dotnet test --filter LibGit2Sharp.Tests.SubmoduleFixture.CanUpdateSubmodule it correctly prints
======> git_submodule_update proxy version 1
Then I compiled libgit2 with debugging symbols enabled and pointed libgit2sharp to it. When breaking on git_submodule_update in GDB on the same test I see this:
Thread 8 ".NET Long Running T" hit Breakpoint 1, git_submodule_update (sm=0x4921358940, init=0, _update_options=0x7fffdf3f1d68) at /usr/local/poudriere/ports/default/devel/libgit2/work/libgit2-1.9.1/src/libgit2/submodule.c:1362
1362 git_config *config = NULL;
(gdb) bt
#0 git_submodule_update (sm=0x4921358940, init=0, _update_options=0x7fffdf3f1d68) at /usr/local/poudriere/ports/default/devel/libgit2/work/libgit2-1.9.1/src/libgit2/submodule.c:1362
#1 0x0000000806782740 in ?? ()
#2 0x00007fffdf3f1ce0 in ?? ()
#3 0x000000000055ffc9 in ?? ()
#4 0x0000000802669b68 in ?? () from /usr/local/share/dotnet/shared/Microsoft.NETCore.App/9.0.9/libcoreclr.so
#5 0x00007fffdf3f2858 in ?? ()
#6 0x0000000806639598 in ?? ()
#7 0x00007fffdf3f1ce0 in ?? ()
#8 0x0000000806782740 in ?? ()
#9 0x00007fffdf3f1fd0 in ?? ()
#10 0x00000008067825d0 in ?? ()
#11 0x0000000806639598 in ?? ()
#12 0x000000080185e000 in ?? ()
#13 0x000000080663a508 in ?? ()
#14 0x0000004922d71720 in ?? () at /usr/local/poudriere/ports/default/devel/libgit2/work/libgit2-1.9.1/src/libgit2/submodule.c:1354 from /usr/home/arr/projects/libgit2sharp/artifacts/bin/LibGit2Sharp.Tests/debug_net9.0/libgit2-3f4182d.so
#15 0x0000000806639598 in ?? ()
#16 0x0000000000000000 in ?? ()
(gdb) print *_update_options
$1 = {version = 1, checkout_opts = {version = 1, checkout_strategy = 1, disable_filters = 0, dir_mode = 0, file_mode = 0, file_open_flags = 0, notify_flags = 4, notify_cb = 0x8027a3024, notify_payload = 0x0, progress_cb = 0x8027a3064, progress_payload = 0x0,
paths = {strings = 0x0, count = 0}, baseline = 0x0, baseline_index = 0x0, target_directory = 0x0, ancestor_label = 0x0, our_label = 0x0, their_label = 0x0, perfdata_cb = 0x0, perfdata_payload = 0x0}, fetch_opts = {version = 1, callbacks = {version = 1,
sideband_progress = 0x0, completion = 0x0, credentials = 0x0, certificate_check = 0x0, transfer_progress = 0x0, update_tips = 0x8027a30a4, pack_progress = 0x0, push_transfer_progress = 0x0, push_update_reference = 0x0, push_negotiation = 0x0,
transport = 0x0, remote_ready = 0x0, payload = 0x0, resolve_url = 0x0, update_refs = 0x100000000}, prune = GIT_FETCH_PRUNE_UNSPECIFIED, update_fetchhead = 0, download_tags = GIT_REMOTE_DOWNLOAD_TAGS_AUTO, proxy_opts = {version = 0, type = GIT_PROXY_NONE,
url = 0x0, credentials = 0x0, certificate_check = 0x0, payload = 0x200000000}, depth = 0, follow_redirects = 0, custom_headers = {strings = 0x0, count = 0}}, allow_fetch = -2000680448}
Note the contents of _update_options appears to be correct, except for proxy_opts. The offending version=0 is there, which is causing further breakage.
I'm not a C# expert, but maybe there is some marshaling mistake at the libgit2sharp level?
Each version of LibGit2Sharp uses a specific version of libgit2 by referencing a specific version of the LibGit2Sharp.NativeBinaries package.
If you are trying to build your own native binaries, you need to ensure you're using the matching version of libgit2 to have any chance of success. Currently LibGit2Sharp is using v1.8.4.