gpt4 book ai didi

c - 如何推送(使用 libgit2)

转载 作者:太空狗 更新时间:2023-10-29 17:22:47 25 4
gpt4 key购买 nike

如何使用 libgit2 进行推送? (就像控制台上的 git push origin master)

我想使用 C 版本。克隆、打开、将文件添加到索引并像魅力一样提交工作(参见 code )。

test-bare-repository 是本地的。

不幸的是,引用资料和文档对我没有帮助。示例非常罕见且大多已过时( like thisgit_push_new() 函数似乎已消失)。

我猜了几个小时,我想我已经尝试了所有有意义的代码片段组合 referenceexamples .

编辑:我担心 libgit2 根本不可能做到这一点。任何人都可以向我推荐能够证明/伪造我的恐惧的引用资料吗?

互联网/邮件列表中有一些消息来源([1][2])表示暂时无法使用 libgit2 进行推送,但很快就会有可能。然而,这些来源已经过时了。

引用包含一些与推送相关的功能(至少按名称)。但似乎没有一个能按照我想要的方式工作:(

最佳答案

实现该技巧的代码是:

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

当然,您应该进行一些错误检查,为了简洁起见,我省略了这些检查。

关于c - 如何推送(使用 libgit2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28055919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com