0

I apologize in advance because I'm extremely new to libgit2/git. I was trying to clone a git repository using ssh, and I'm getting an error below:

Error code: -1 Invalid version 0 on git_clone_options

I replaced some paths with arbitrary variables for privacy. I just believe I'm doing the steps improperly.

cred_acquire_cb(git_cred** cred, const char* url, const char* username_from_url, unsigned int allowed_types, void* payload)
{
return git_cred_ssh_key_new(cred, "git", URL, pathToPublicKey, passPhrase);
}

git_repository* repo;
git_remote** remote;
g_options.remote_callbacks.certificate_check;
g_options.remote_callbacks.credentials = cred_acquire_cb;
g_options.remote_cb_payload = pathToCopyTo;
printError(git_clone(&repo, sshURL, pathToCopyTo, &g_options));
user3485650
  • 29
  • 1
  • 4

1 Answers1

2

The various git_*_options structures need to be initialized explicitly. (You cannot have them simply pointing to uninitialized memory.) You can do so quite easily, either using the handy initializer:

git_clone_options options = GIT_CLONE_OPTIONS_INIT;
options.remote_callbacks.credentials = cred_acquire_cb;

Or you can call a simple function to do it for you:

git_clone_options options;
git_clone_init_options(&options, GIT_CLONE_OPTIONS_VERSION);
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • Also works for `git_checkout_options` using `GIT_CHECKOUT_OPTIONS_INIT` – Abdelilah El Aissaoui Oct 16 '17 at 07:19
  • Any insight on how to do this now? It does not appear that `remote_callback.credentials` is a property of the clone options any longer. But maybe I am just not understanding the documentation. https://libgit2.org/libgit2/#HEAD/type/git_clone_options – Thenlie Oct 22 '22 at 04:45
  • 1
    @Thenlie they're in the fetch options now -- `options.fetch_opts.remote_callbacks.credentials` – Edward Thomson Oct 24 '22 at 08:52
  • Thank you so much for the response. You are spot on. – Thenlie Oct 24 '22 at 19:58