问题
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));
回答1:
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);
来源:https://stackoverflow.com/questions/30467877/libgit2-clone-repo-using-ssh-invalid-version-0-on-git-clone-options