gpt4 book ai didi

git - LibGit2 实现 'git pull'

转载 作者:行者123 更新时间:2023-12-04 15:00:56 25 4
gpt4 key购买 nike

我选择了以下 pull 算法:

  1. 获取()
  2. 获取当前 head 提交
  3. 获取所有未 merge 的提交(实现取自此处:How can I check if pull is needed using libgit2 in c++?)
  4. 从步骤 3.
  5. 获取第一个未 merge 的提交(它是最新的)
  6. merge 提交。从 LastFetchedCommit(第 4 步)到 headCommit(第 2 步)。

1-4 完美运行

我有 5 个问题:

git_merge_commits(&rezPointer, repo.pointer , commitFrom.pointer, commitInto.pointer, &mrgOptions)

我正在尝试 pull 相对于本地 repo 有 2 个额外提交的远程 repo 。

错误:

Error Domain=lib.git_index_write_tree failed: Failed to write tree. the index file is not backed up by an existing repository Code=-1 "Failed to write tree. the index file is not backed up by an existing repository" UserInfo={NSLocalizedDescription=Failed to write tree. the index file is not backed up by an existing repository, NSLocalizedFailureReason=git_index_write_tree failed.}

我是不是做错了什么?

最佳答案

这可能如 issue 2668 中所述

If I call git_index_write_tree(), it fails with Failed to write tree. The index file is not backed up by an existing repository.

这就是git_index_write_tree_to()是为了。

但这不是关于裸与非裸的问题,而是关于你是否向存储库请求索引或者你是否创建了一个没有任何关联的索引。

有点像issue 5015 ,其中明确设置并使用了对索引的引用(没有错误消息):

    git_repository *src, *dst;                                                                                         
git_index *index;
git_oid id;

git_libgit2_init();

err = git_repository_open(&src, "src");
err = git_repository_open(&dst, "dst");
err = git_repository_index(&index, src);

err = git_index_write_tree_to(&id, index, dst);

关于git - LibGit2 实现 'git pull',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66959726/

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