c++ - libgit2 - 为 ssh 键设置回调
问题描述
我正在尝试使用此代码推送到远程仓库
void repository::push() {
char *refspec = strdup(this->current_branch().name().c_str());
const git_strarray refspecs = {
&refspec,
1
};
git_push_options options;
git_remote* remote = nullptr;
lg2_error(git_remote_lookup(&remote, repo_, "origin" ), "Unable to lookup remote", "");
lg2_error(git_push_init_options(&options, GIT_PUSH_OPTIONS_VERSION ), "Error initializing push", "");
lg2_error(git_remote_push(remote, &refspecs, &options), "Error pushing", "");
printf("pushed\n");
}
它主要来自 libgit2push.c
示例,但我得到了错误
Error pushing [-1] - authentication required but no callback set
我想通过 ssh 密钥进行身份验证,但我无法弄清楚我必须在git_push_options
回调中设置哪些选项才能做到这一点。我已经看到线程是人们读出.ssh
目录而没有什么,但我希望有一个更简单的方法。或者最好只使用在 shell 上exec
运行命令git push
并停止使用 libgit2 的推送。
解决方案
推荐阅读
- java - 无法在片段中的 RecyclerView 中获取 onClick 事件
- string - 基于字典的模糊匹配
- angularjs - 使用应用控制器从 URL 获取参数
- c++ - 如何检查文件复制和写入是否成功
- c# - TreeView - 禁止空节点重命名
- android - 我的应用程序在 android studio 3.1.3 中以发布模式等待调试器
- jquery - 无法在 Laravel 中发出 ajax 请求
- node.js - 简单的 UnhandledPromiseRejectionWarning
- javascript - 获取替换中发生替换的点
- c# - DataSet 设置相同值时防止修改标志