git - LibGit2 实现 'git pull'

标签 git libgit2

我选择了以下 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/

相关文章:

c++ - 如何在 C++ 中使用 libgit2 检查是否需要 pull?

c++ - git_clone 报错信息 Assertion failed : git_atomic_get(&git__n_inits) > 0

git - 令人困惑的错误来自 | xargs sed

git2go 获取远程标签

ruby - 如何在内存中创建一个git仓库?

c - 获取受提交影响的文件和目录

用于维护衍生叉的 Git 工作流

git - 在 git 中重命名 Remote 是否安全?

svn - 如何将GIT存储库与SVN同步?

git - Grunt-shell 将命令输出保存为变量