]> git.ipfire.org Git - thirdparty/git.git/commit
git diff: improve range handling
authorChris Torek <chris.torek@gmail.com>
Fri, 12 Jun 2020 16:19:59 +0000 (16:19 +0000)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Jun 2020 17:53:44 +0000 (10:53 -0700)
commit8bfcb3a690126e6222f0d4f7012b0f68bb748018
tree23e39a459c38a0cc16a14c17ba87836bc5079f98
parentbafa2d741e9dcc4d70ffcb3943e530635bb8e684
git diff: improve range handling

When git diff is given a symmetric difference A...B, it chooses
some merge base from the two specified commits (as documented).

This fails, however, if there is *no* merge base: instead, you
see the differences between A and B, which is certainly not what
is expected.

Moreover, if additional revisions are specified on the command
line ("git diff A...B C"), the results get a bit weird:

 * If there is a symmetric difference merge base, this is used
   as the left side of the diff.  The last final ref is used as
   the right side.
 * If there is no merge base, the symmetric status is completely
   lost.  We will produce a combined diff instead.

Similar weirdness occurs if you use, e.g., "git diff C A...B D".
Likewise, using multiple two-dot ranges, or tossing extra
revision specifiers into the command line with two-dot ranges,
or mixing two and three dot ranges, all produce nonsense.

To avoid all this, add a routine to catch the range cases and
verify that that the arguments make sense.  As a side effect,
produce a warning showing *which* merge base is being used when
there are multiple choices; die if there is no merge base.

Signed-off-by: Chris Torek <chris.torek@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/diff.c
t/t4068-diff-symmetric.sh [new file with mode: 0755]