如何使用libgit2通过ssh推git仓库 [英] How to push git repository through ssh using libgit2

查看:421
本文介绍了如何使用libgit2通过ssh推git仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一直以来,在​​ SSH 支持已经实施,可能有人告诉我怎么写推()功能?我有一些成功通过本地文件系统推但当我尝试在 SSH 我只得到一个段错误

Since, the ssh support is already implemented, could anybody show me how to write a push() function? I had some success pushing through the local file system but when I try the ssh I only get a 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;
}

我相信,我不这样做是正确的,但我找不到任何的例子来看看它是如何做。

I believe I'm not doing it right but I couldn't find any example to see how it's done.

更新:确定我计算过,我需要一些身份验证连接,所以我结束了这一点。否段错误在这里。我仍然得到git_remote_connect错误,但:早期EOF 。我在做什么错了?

UPDATE: Ok I figured that I need some authentication to connect, so I ended up with this. No segfault here. I still get an Error on git_remote_connect though : Early EOF. What am I doing wrong ?

推荐答案

cred_acquire_cb 函数没有返回任何东西。这可能会导致一个问题。它应该成功返回0或1的错误。

Your cred_acquire_cb function is not returning anything. That might be causing a problem. It should return 0 on success, or -1 on error.

这篇关于如何使用libgit2通过ssh推git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆