LibGit2 clone repo using ssh: Invalid version 0 on

2019-03-06 13:04发布

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));

标签: git ssh libgit2
1条回答
你好瞎i
2楼-- · 2019-03-06 13:46

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);
查看更多
登录 后发表回答