如何使用libgit2通过ssh推送git存储库

既然已经实现了ssh支持,有人可以告诉我如何编写push()函数吗? 我在推动本地文件系统方面取得了一些成功,但是当我尝试ssh时,我只得到一个段错误。

 int cred_acquire_cb(git_cred** cred,const char* url,unsigned int allowed_types, void* payload){ check_error(git_cred_ssh_keyfile_passphrase_new(cred,"./bitbucket.pub","./bitbucket",NULL),"keyfile passphrase"); } int main(int argc, const char *argv[]) { char* repo_path="./hello/.git"; char* remote_name="origin"; git_repository* repo; git_remote* remote; git_push* push; bool cred_acquire_called; int error; check_error(git_repository_open(&repo, repo_path),"open repo"); check_error(git_remote_load(&remote,repo,remote_name),"load a remote"); git_remote_set_cred_acquire_cb(remote, (git_cred_acquire_cb)cred_acquire_cb, &cred_acquire_called); check_error(git_remote_connect(remote, GIT_DIRECTION_PUSH),"connect remote"); check_error(git_push_new(&push, remote),"new push object"); check_error(git_push_add_refspec(push,"refs/heads/master:refs/heads/master"),"add push refspec"); check_error(git_push_finish(push),"finish pushing"); check_error(git_push_unpack_ok(push),"unpacked OK? "); git_push_free(push); git_remote_free(remote); git_repository_free(repo); return 0; } 

我相信我做得不对,但我找不到任何例子来看看它是如何完成的。

更新:好的我认为我需要一些身份validation来连接,所以我最终得到了这个。 这里没有段落错误 。 我仍然在git_remote_connect上遇到错误: 早期EOF 。 我究竟做错了什么 ?

您的cred_acquire_cb函数没有返回任何内容。 这可能会导致问题。 它应该在成功时返回0,或者在出错时返回-1。