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

它主要来自 libgit2 push.c 示例,但我收到错误

Error pushing [-1] - authentication required but no callback set

我想通过 ssh 密钥进行身份验证,但我不知道必须在 git_push_options 回调中设置哪些选项才能实现这一点。我看到有人读出了 .ssh 目录,但我希望有更简单的方法。或者最好只使用 exec 在 shell 上运行命令 git push 并停止打扰 libgit2 的推送。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)