LibGit2 clone repo using ssh: Invalid version 0 on git_clone_options

情到浓时终转凉″ 提交于 2019-12-02 20:29:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!