1

I want to use labgit2sharp to replace the command -- "git pull“ to pull my code from my gitlab. but it is not successful by using the following code:

using (var repo = new Repository(remotePath))
{
    LibGit2Sharp.PullOptions options = new LibGit2Sharp.PullOptions();
    options.FetchOptions = new FetchOptions();
    options.FetchOptions.CredentialsProvider = new CredentialsHandler(
        (url, usernameFromUrl, types) =>
            new UsernamePasswordCredentials()
            {
                Username = "username",
                Password = "password"
            });
    repo.Network.Pull(new LibGit2Sharp.Signature("username", emailaddress, new DateTimeOffset(DateTime.Now)), options)
}

Could you help me? I want to know all the steps from the beginning. Thanks very much!

Noam Hacker
  • 4,233
  • 7
  • 32
  • 53
崔重阳
  • 13
  • 2
  • 1
    What are you using for `remotePath`? This has to be a local file path, not your remote Git source. Also post the error/stack trace that you are getting. – SushiHangover Mar 17 '16 at 14:08
  • ok,thanks!but there has a error:Type initializer exception – 崔重阳 Mar 17 '16 at 15:36
  • how can i solve it? or i lack some steps? – 崔重阳 Mar 17 '16 at 15:38
  • Post your exception stack trace in your question – SushiHangover Mar 17 '16 at 15:50
  • - $exception {"“LibGit2Sharp.Core.NativeMethods”的类型初始值设定项引发异常。"} System.TypeInitializationException - InnerException {"无法加载 DLL“git2-785d8c4”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。"} System.Exception {System.DllNotFoundException} – 崔重阳 Mar 17 '16 at 16:28
  • The native `libgit2` library `git2-785d8c4` is not being found, have you installed the native libgit2 library (via Nuget or source & building it manually)? http://stackoverflow.com/a/35029888/4984832 https://github.com/libgit2/libgit2 – SushiHangover Mar 17 '16 at 17:32
  • yes ! i am. i have installed nuget – 崔重阳 Mar 18 '16 at 03:31
  • Do you have the `git2-785d8c4` (`.dll`/`.dylib`/`.so`) native library that the C# library is trying to load? – SushiHangover Mar 18 '16 at 04:11
  • i have git2-785d8c4.dll,and when i try to load it ,it show that unable to add reference about it,and make sure this file is accessible and is a valid assembly or COM. – 崔重阳 Mar 18 '16 at 09:16
  • It is a **native** library, not a CIL-based one, since it ends in `.dll`, I am assuming you have the correct one and you are on Windows OS? If so, during the build process is it not being copied to the output directory with the CIL-based assembies (your program files and libgit2sharp.dll)? – SushiHangover Mar 18 '16 at 15:06

1 Answers1

1

Network.Pull is no more used. Please try using LibGit2Sharp.Commands.Pull()