简体   繁体   English

处理Rugged中的合并冲突

[英]Dealing with merge conflicts in Rugged

I'm working on a Ruby script that needs to do some merging. 我正在研究一个需要进行合并的Ruby脚本。 What I'd like to do is, given a target reference and a commit to merge attempt to merge them, and if there are merge conflicts give control back to the user to resolve them, basically exactly like git merge does, so the user can deal with conflicts, then call git my-merge --continue and continue where we left off. 我想做的是,给定目标引用并提交合并尝试合并它们,如果存在合并冲突,则将控制权交还给用户解决它们,基本上就像git merge一样,所以用户可以处理冲突,然后调用git my-merge --continue继续并继续我们离开的地方。

What I have so far is this: 到目前为止我所拥有的是:

merge_index = @repo.merge_commits(@commit, target_tip, options)
unless merge_index.conflicts?
options = {
    :committer => @commit.committer,
    :author => @commit.author,
    :parents => [target_tip, @commit],
    :message => merge_message,
    :update_ref => @target.canonical_name,
    :tree => merge_index.write_tree(@repo)
}

commit = Rugged::Commit.create(@repo, options)
else
    # Here's where my unwritten code goes 
end

Here comes the question: Given the merge_index that I have with some conflicts, how do I get my working directory into the state represented by it so I can return to shell and let the user resolve them? 这里有一个问题:鉴于我对一些冲突的merge_index ,我如何让我的工作目录进入由它表示的状态,以便我可以返回shell并让用户解决它们? It seems I cannot write it out (it will complain that it cannot write out an index that isn't fully merged) and I don't see an obvious way to set my current index to it. 我似乎无法写出来(它会抱怨它无法写出一个未完全合并的索引)而且我没有看到一种明显的方法来设置我当前的索引。

The merge index is the result of the merge. 合并索引是合并的结果。 If you want that to be the status of the repository, you need to write that index to be the index of the repository, like with 如果您希望将其作为存储库的状态,则需要将该索引编写为存储库的索引,例如

repo.index = merge_index
merge_index.write()

you can then use checkout as usual, which will create the conflict markers on the files in the worktree. 然后,您可以像往常一样使用checkout,这将在工作树中的文件上创建冲突标记。

libgit2 itself has git_merge() does does this for you; libgit2本身有git_merge()会为你做这件事; you might want to look into making that available through rugged if you do not want to perform the steps in your code. 如果您不想执行代码中的步骤,您可能希望通过坚固耐用来实现可用性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM