eclipse-jgit / jgit

JGit, the Java implementation of git
https://www.eclipse.org/jgit/
Other
92 stars 31 forks source link

Jgit's diff3 is a curious mix of git's diff3 and zdiff3 styles #39

Open wetneb opened 4 months ago

wetneb commented 4 months ago

Version

6.9.0.202403050737-r

Operating System

Linux/Unix, MacOS, Windows

Bug description

As a follow-up to #38, I am bringing a case where jgit's diff3 output differs from git's diff3 output. Consider the following files:

Base

a
b
c
d

Ours

a
H
E
c
d

Theirs

a
F
E
c
d

Actual behavior

When merging those with jgit in diff3 mode, I get:

a
<<<<<<< ours
H
||||||| base
=======
F
>>>>>>> theirs
E
c
d

The problem here is that the b from the base revision is not visible anymore. Granted, the output can be explained with the interpretation that both sides replaced b by E (which is therefore done outside of the conflict), and then the conflict itself is only about determining whether to insert H or F before that. But it defeats the purpose of the diff3 style a little, since the contents of the base revision are obscured.

Expected behavior

Using git's diff3 output, we get:

a
<<<<<<< ours
H
E
||||||| base
b
=======
F
E
>>>>>>> theirs
c
d

Although the conflict hunk is larger, I find that more helpful because the contents of the base revision are clear.

Using git's zdiff3 output, we get:

a
<<<<<<< ours
H
||||||| base
b
=======
F
>>>>>>> theirs
E
c
d

That's pretty ideal, and would be worth supporting by jgit, but perhaps rather as a separate mode (called, say, zdiff3)?

Relevant log output

No response

Other information

See this helpful blog post about the differences between diff3 and zdiff3: https://ductile.systems/zdiff3/