Skip to content

Commit ebd8fa7

Browse files
committed
Merge branch 'jk/diff-highlight-identical-pairs'
The handling of the incomplete lines at the end by "git diff-highlight" has been fixed. * jk/diff-highlight-identical-pairs: contrib/diff-highlight: do not highlight identical pairs
2 parents 41688c1 + 598f40c commit ebd8fa7

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

contrib/diff-highlight/DiffHighlight.pm

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,18 @@ sub highlight_line {
273273
# or suffix (disregarding boring bits like whitespace and colorization).
274274
sub is_pair_interesting {
275275
my ($a, $pa, $sa, $b, $pb, $sb) = @_;
276+
277+
# We hit this case if the prefix consumed the entire line, meaning
278+
# that two lines are identical. This generally shouldn't happen,
279+
# since it implies the diff isn't minimal (you could shrink the hunk by
280+
# making this a context line). But you can see it when the line
281+
# content is the same, but the trailing newline is dropped, like:
282+
#
283+
# -foo
284+
# +foo
285+
# \No newline at end of file
286+
return 0 if $pa == @$a || $pb == @$b;
287+
276288
my $prefix_a = join('', @$a[0..($pa-1)]);
277289
my $prefix_b = join('', @$b[0..($pb-1)]);
278290
my $suffix_a = join('', @$a[($sa+1)..$#$a]);

contrib/diff-highlight/t/t9400-diff-highlight.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,15 @@ test_expect_success 'diff-highlight handles --graph with leading dash' '
340340
test_cmp expect actual
341341
'
342342

343+
test_expect_success 'highlight diff that removes final newline' '
344+
printf "content\n" >a &&
345+
printf "content" >b &&
346+
dh_test a b <<-\EOF
347+
@@ -1 +1 @@
348+
-content
349+
+content
350+
\ No newline at end of file
351+
EOF
352+
'
353+
343354
test_done

0 commit comments

Comments
 (0)