summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorPhillip Wood <phillip.wood@dunelm.org.uk>2018-03-05 10:56:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-05 18:45:41 (GMT)
commitb3e0fcfe429204ccdf1f6977c55127171d65a8e5 (patch)
treee06dcb66e45993aa3e2c0bc775ce1826f8b85331 /git-add--interactive.perl
parent2b8ea7f3c7d8dfd4f1eddaef6688b51f8106767e (diff)
downloadgit-b3e0fcfe429204ccdf1f6977c55127171d65a8e5.zip
git-b3e0fcfe429204ccdf1f6977c55127171d65a8e5.tar.gz
git-b3e0fcfe429204ccdf1f6977c55127171d65a8e5.tar.bz2
add -p: fix counting when splitting and coalescing
When a file has no trailing new line at the end diff records this by appending "\ No newline at end of file" below the last line of the file. This line should not be counted in the hunk header. Fix the splitting and coalescing code to count files without a trailing new line properly and change one of the tests to test splitting without a trailing new line. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl11
1 files changed, 11 insertions, 0 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index b5f0116..4a1e71d 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -793,6 +793,11 @@ sub split_hunk {
while (++$i < @$text) {
my $line = $text->[$i];
my $display = $display->[$i];
+ if ($line =~ /^\\/) {
+ push @{$this->{TEXT}}, $line;
+ push @{$this->{DISPLAY}}, $display;
+ next;
+ }
if ($line =~ /^ /) {
if ($this->{ADDDEL} &&
!defined $next_hunk_start) {
@@ -891,6 +896,9 @@ sub merge_hunk {
$n_cnt++;
push @line, $line;
next;
+ } elsif ($line =~ /^\\/) {
+ push @line, $line;
+ next;
}
last if ($o1_ofs <= $ofs);
@@ -909,6 +917,9 @@ sub merge_hunk {
$n_cnt++;
push @line, $line;
next;
+ } elsif ($line =~ /^\\/) {
+ push @line, $line;
+ next;
}
$ofs++;
$o_cnt++;