Merge conflicts
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.
Supporting a view similiar to #57 for merge conflicts would also be good.
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 --onelinewill show the conflicting commits. It'll error out if it's not in the middle of a merge.git status --porcelainwill 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..0000000contains enough info to grab the contents of the file that produced the conflict. In this case, we can rungit show 2a46cea file1.txt.
@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.
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:
- Get an overview of remaining conflicting hunks
- 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.
What about VSCode-like approach?
Very handy and easy to use.
There is already a plugin in Vimscript for it.
@Shatur95 I would also like more of a buffer oriented style like in vscode intead of the common 3 split diff thing.
That sounds good too. Just thought this merge feature initially came from someone asking for a 2 way diffing merge view. :)
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