既然已经实现了ssh支持,有人可以告诉我如何编写push()
函数吗?我通过本地文件系统取得了一些成功,但是当我尝试ssh时,我只得到一个segfault。
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;
}
我相信我做得不对,但我找不到任何例子来看看它是如何完成的。
更新: 好的,我认为我需要一些身份验证才能连接,所以我最终得到了这个。这里没有段错误。我仍然在 git_remote_connect 上得到一个错误:Early EOF。我究竟做错了什么 ?