如何使用libgit2进行推送?(就像控制台上的git push origin master )
我想使用C版本。克隆、打开、向索引中添加文件和提交文件就像一种魅力(请参见代码)。
测试裸存储库是本地的。
不幸的是,参考资料和文件对我没有帮助。例子非常罕见,而且大多已经过时(像这样,git_push_new()函数似乎已经消失了)。
我猜想现在已经有几个小时了,我想我尝试了来自参考文献和示例的所有有意义的代码片段组合。
编辑:我担心libgit2根本不可能做到这一点。有谁能建议我引用那些能使我恐惧的话呢?
在互联网/邮件列表中有一些消息来源([1],[2])说,目前不可能使用libgit2,但很快就有可能。然而,这些资料来源已相当过时。
引用包含一些与推送相关的函数(至少按名称计算)。但似乎没有一个像我想的那样工作:
发布于 2015-02-11 10:24:44
实现这一目的的代码是:
bool push(git_repository *repository)
{
// get the remote.
git_remote* remote = NULL;
git_remote_lookup( &remote, repository, "origin" );
// connect to remote
git_remote_connect( remote, GIT_DIRECTION_PUSH );
// add a push refspec
git_remote_add_push( remote, "refs/heads/master:refs/heads/master" );
// configure options
git_push_options options;
git_push_init_options( &options, GIT_PUSH_OPTIONS_VERSION );
// do the push
git_remote_upload( remote, NULL, &options );
git_remote_free( remote );
return true;
}当然,为了简洁起见,您应该做一些我省略的错误检查。
https://stackoverflow.com/questions/28055919
复制相似问题