neogit icon indicating copy to clipboard operation
neogit copied to clipboard

Merge conflicts

Open TimUntersberger opened this issue 4 years ago • 8 comments

Being able to quickly look at all of the conflicts in a file would greatly improve the merge experience. I imagine an interface similar to the diff view, with additional functionality where needed.

TimUntersberger avatar Mar 15 '21 12:03 TimUntersberger

Supporting a view similiar to #57 for merge conflicts would also be good.

TimUntersberger avatar Mar 25 '21 10:03 TimUntersberger

This might be enough info to attempt implementing a merge feature.

When trying to merge branches and there appears to be a conflict, there seems to at least 3 ways to detect this:

  • git merge <branch> exit status will be 1. Some error text is also sent via stdin.
  • git log --merge --oneline will show the conflicting commits. It'll error out if it's not in the middle of a merge.
  • git status --porcelain will return items marked with "UU" indicating the file is unmerged.

After determining we're in the middle of a merge, we can use git diff show a list of conflicting files & hunks.

For example:

diff --cc file1.txt
index f201d7f,2a46cea..0000000
--- a/file1.txt
+++ b/file1.txt
@@@ -1,7 -1,5 +1,12 @@@
++<<<<<<< HEAD
 +Changes are
 +an unavoidable
 +part of
 +life
++=======
+ Conflicts
+ Happens
++>>>>>>> develop

  Hello
  World!

This gives us a definitive list of files and hunks to visit to resolve the merge conflict. It shouldn't be too difficult to implement a "jump to next conflict" feature. Maybe this info can be presented somewhat like the status buffer to keep a consistent look & feel?

To bring up the diff interface, we need the contents of the two versions of the file where the conflict happened:

  • Ours/local version Take the on-disk/working-tree version and cleanup to strip out the conflict markers & text. This should bring across any merged content that did not produce any conflict

  • Theirs/remote version The file diff header index f201d7f,2a46cea..0000000 contains enough info to grab the contents of the file that produced the conflict. In this case, we can run git show 2a46cea file1.txt.

Odie avatar Mar 27 '21 06:03 Odie

@Odie nice work!

I guess now we really just have to think about the ui/ux stuff. What are you expectations for something like this?

Maybe this info can be presented somewhat like the status buffer to keep a consistent look & feel?

I think something like this would be cool! I don't know how we would support expanding the viewed code upwards/downwards though.

TimUntersberger avatar Mar 27 '21 13:03 TimUntersberger

I think something like this would be cool! I don't know how we would support expanding the viewed code upwards/downwards though.

Maybe it can be a 3 pane operation. One pane can be like the status view, where the purpose is to:

  1. Get an overview of remaining conflicting hunks
  2. Select and navigate to the conflicted hunk/lines (especially useful for jumping to a specific file)

The other two panes would be to display the file diffs when the conflicted lines are navigated to. A hot key would be available to jump to the next conflict. It’d take the user to another file if there are no more conflicts in the current file.

Odie avatar Mar 27 '21 14:03 Odie

What about VSCode-like approach? изображение Very handy and easy to use.

There is already a plugin in Vimscript for it.

Shatur avatar Apr 06 '21 21:04 Shatur

@Shatur95 I would also like more of a buffer oriented style like in vscode intead of the common 3 split diff thing.

TimUntersberger avatar Apr 07 '21 18:04 TimUntersberger

That sounds good too. Just thought this merge feature initially came from someone asking for a 2 way diffing merge view. :)

Odie avatar Apr 08 '21 01:04 Odie

Diffview now has support for merge conflicts similar to the VSCode approach, so from Neogit's side, all which remains to do is reporting of the merge failure rather than "Git command failed press $ ...", as well as showing then inline conflict diff like with modified files

ten3roberts avatar Sep 20 '22 21:09 ten3roberts