libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.17k stars 886 forks source link

`LibGit2SharpException` when cloning repository within a Docker container #2067

Closed ghost closed 10 months ago

ghost commented 10 months ago

Reproduction steps

Running the following code within a Docker container: Repository.Clone(_config["GitDownloader:Repository"], path, _cloneOptions);

Expected behavior

Cloning the specified repository correctly.

Actual behavior

Throws a LibGit2SharpException exception whose stack trace is the following one:

at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 172
at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) in /_/LibGit2Sharp/Core/Proxy.cs:line 278
at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in /_/LibGit2Sharp/Repository.cs:line 793

Version of LibGit2Sharp (release number or SHA1)

0.28.0

Operating system(s) tested; .NET runtime tested

Works properly on MacOS 14.1.1 with .NET 8.0 Doesn't work on mcr.microsoft.com/dotnet/aspnet:8.0 container with .NET 8.0

bording commented 10 months ago

What is the actual exception error message?

My guess for the problem is that the way you are creating the docker image is resulting in the correct native binaries not being included in the image.

ghost commented 10 months ago

I forgot to mention that the exception's message is the following one: Object reference not set to an instance of an object.

ghost commented 10 months ago

The way I am building the docker image is by taking the complete build directory and copying it into the Docker build using the command COPY.

bording commented 10 months ago

I forgot to mention that the exception's message is the following one: Object reference not set to an instance of an object.

Based on that, I would check and see if the way you obtaining the values you're passing into Repository.Clone is working when you're running from inside your container. Sound like you're passing a null value in.

ghost commented 10 months ago

I've checked the values passed to Repository.Clone and all of them are valid. This seems to be a strange situation since the same build works correctly on my machine, but once it is Dockerized, it fails.

ghost commented 10 months ago

I tried executing the code on a Linux machine and it seems to be throwing the same exception.

bording commented 10 months ago

At this point I'd really need more to go on to be able help further. If you could provide a repo that has a sample project that to reproduce the issue, that would be perfect.

ghost commented 10 months ago

In the end it seems it was due to a missing environment variable by my side which didn't full fill the CloneOptions correctly. So there's nothing wrong with libgit2sharp! Sorry for that!

bording commented 10 months ago

Glad to hear you figured it out!