我试图使用LibGit2使用以下代码克隆存储库:
#include <string>
#include <iostream>
#include "main.h"
#include "git2.h"
using namespace std;
int creds(git_cred **out, const char *url, const char *username_from_url,
unsigned int allowed_types, void *payload) {
cout << "Calling creds" << endl;
return git_credential_ssh_key_new(out, username_from_url,
"path_to_home/.ssh/id_rsa.pub", "path_to_home/.ssh/id_rsa", "password");
}
int main() {
git_libgit2_init();
string url = "git@github.com:Black-Photon/Git-Testing.git";
git_repository *repo = nullptr;
git_clone_options ops = GIT_CLONE_OPTIONS_INIT;
ops.fetch_opts.callbacks.credentials = creds;
int err = git_clone(&repo, url.c_str(), "path_to_home/Documents/temp/Git-Testing", &ops);
cout << giterr_last()->message << endl;
git_libgit2_shutdown();
}但是,我得到的输出是:
Calling creds
Calling creds
Calling creds
...暗示它不接受SSH密钥和密码。但是,当我在普通Git中使用相同的密钥和密码时:
git clone git@github.com:Black-Photon/Git-Testing.git
Cloning into 'Git-Testing'...
Enter passphrase for key 'path_to_home/.ssh/id_rsa': password
remote: Enumerating objects: 23, done.
remote: Counting objects: 100% (23/23), done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 29 (delta 0), reused 13 (delta 0), pack-reused 6
Receiving objects: 100% (29/29), 4.58 KiB | 426.00 KiB/s, done.正常工作。为什么它不能使用LibGit2?
我使用的是LibGit2版本0.99.0。我尝试使用id_rsa中的“保持”和“删除”空的最后一行,之前在LibGit2版本0.26.0中,给出了一个不同的消息:Failed to authenticate SSH session: Callback returned error。我也尝试过使用具有相同结果的git_credential_ssh_key_memory_new。
发布于 2020-03-18 19:31:25
正在使用的SSH库1.8.0已经过时,必须更新为1.9.0。
https://stackoverflow.com/questions/60364214
复制相似问题