I'm working on a Ruby script that needs to do some merging. 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.
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? 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.