Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGit2Sharp how to resolve a conflict?

Using libgit2sharp I am merging changes from two users:

public void Merge(string branchName)
{
    using (Repository repo = new Repository(this._settings.Directory))
    {
        var branch = repo.Branches[branchName];
        MergeOptions opts = new MergeOptions() { FileConflictStrategy = CheckoutFileConflictStrategy.Merge };
        repo.Merge(branch, this._signature, opts);

        if (repo.Index.Conflicts.Count() > 0)
        {
             //TODO: resolve conflicts
        } 
    }
}

Even if the strategy is set to merge the conflics still appear. I found no way to resolve the conflict. The Conflict object have no Resolve method.

Is there a way to resolve a conflict from code apart from removing file or renaming it? Is there any auto resolve functionality?

Thank you for any help!

like image 718
Pavel Korsukov Avatar asked Nov 19 '15 19:11

Pavel Korsukov


1 Answers

LibGit2Sharp does do an automerge. If you are seeing conflicts, then the files are unmergeable. An example of an unmergeable conflict is when both branches change the same region of the same file.

In this case, LibGit2Sharp will write the file to the working directory, with markup around the conflicting region. For example, if some file foo.txt has a conflict, it may look like:

<<<<<<< HEAD
this is a change in HEAD
=======
this is a change in the other branch
>>>>>>> other branch

To resolve the conflict, place the content that you want to accept in the working directory, then stage it using Repository.Index.Add("foo.txt").

like image 131
Edward Thomson Avatar answered Sep 21 '22 04:09

Edward Thomson