1

I'll try to merge a branch to another but I've a MergeConflictException all time. So I try to stage all repository.Index.Conflicts but without any change.

string[] conflictArray = new string[10000];
try {
    repository.Merge(branch[selected], GitHelper.getSignature(), options);
} catch(MergeConflictException e) {
    if (repository.Index.Conflicts.Count() > 0) {

        foreach (var c in repository.Index.Conflicts) {
            repository.Index.Stage(c.Theirs.Path);
        }

    }
}

I' search a lot to have any help, I read MergeFixture.cs from LibGit2Sharp.Tests.

EDIT: sorry I don't tell you why i'm working on this but I'm student and my teachers gave to me this project to do with .NET 3.5 so I use latest 3.5 release of LibGit2Sharp.

Daethe
  • 26
  • 6
  • What do you mean "without any change"? Are you committing after the merge resolution? Note, however, that if you get a merge conflict, you need to resolve it. If you stage all these files without resolving the conflicts you'll include the conflict markers in them. The right thing to do there is either give up or ask the user depending on what kind of program you're writing. – Carlos Martín Nieto Apr 29 '16 at 16:33
  • I show this before asking question : http://stackoverflow.com/questions/33812895/libgit2sharp-how-to-resolve-a-conflict I tell 'without any change' because i've already the same exception each time. So can you help me how to resolve conflict ? – Daethe Apr 29 '16 at 16:46
  • Why do you upload commented code? This is confusing. – Jose Rodriguez Apr 29 '16 at 16:48
  • I remove commented code, I forgot to remove them and i'm sorry for my english, I'm french. I search to resolve conflict but I've to use Ancestor or not ? – Daethe Apr 29 '16 at 16:59

1 Answers1

4

MergeConflictException is admittedly a misleading name. It doesn't mean that there was a merge conflict. That's not exceptional, that's normal, and it doesn't raise an exception. It means that there was a conflict writing the files during merge. (But more on this in a second.)

In fact, you have files in your working directory that have been modified and were impacted by the merge. You can perform a merge if you have files modified in your working directory if that file wasn't changed in the branch you're merging or in the current branch (relative to the common ancestor).

But what you almost certainly want to do is to only start a merge when you do not have any changes in your working directory. Please stash or commit your changes before merging. If you believe that you truly do not have any chanes in your working directory, then correct your line endings.

(Note that MergeConflictException doesn't exist anymore, it's been renamed to help avoid this confusion.)

Community
  • 1
  • 1
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • I use the latest version of .Net 3.5 LibGit2Sharp because the project is based on the prerequisite given by my teachers. I have to interface and integrate its capabilities to Git . I tried to list all the conflicts path but I noticed Ancestor and Theirs are similar but Ours is null. All of this conflicts happened with deleted files. It's normal ? – Daethe May 01 '16 at 00:54
  • If you have a conflict where `Ours` is null then that was deleted in your branch and modified in the other. Perfectly normal. – Edward Thomson May 01 '16 at 13:33