summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgit-add--interactive.perl11
-rwxr-xr-xt/t3701-add-interactive.sh31
2 files changed, 34 insertions, 8 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index b5f01160c5..4a1e71d2e4 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++;
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 24ed3f4a22..e5c66f7500 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -237,14 +237,15 @@ test_expect_success 'setup patch' '
baseline
content
+lastline
+ \ No newline at end of file
EOF
'
-# Expected output, similar to the patch but w/ diff at the top
+# Expected output, diff is similar to the patch but w/ diff at the top
test_expect_success 'setup expected' '
- cat >expected <<-\EOF
- diff --git a/file b/file
- index b6f2c08..61b9053 100755
+ echo diff --git a/file b/file >expected &&
+ cat patch |sed "/^index/s/ 100644/ 100755/" >>expected &&
+ cat >expected-output <<-\EOF
--- a/file
+++ b/file
@@ -1,2 +1,4 @@
@@ -252,16 +253,30 @@ test_expect_success 'setup expected' '
baseline
content
+lastline
+ \ No newline at end of file
+ @@ -1,2 +1,3 @@
+ +firstline
+ baseline
+ content
+ @@ -1,2 +2,3 @@
+ baseline
+ content
+ +lastline
+ \ No newline at end of file
EOF
'
# Test splitting the first patch, then adding both
-test_expect_success 'add first line works' '
+test_expect_success C_LOCALE_OUTPUT 'add first line works' '
git commit -am "clear local changes" &&
git apply patch &&
- (echo s; echo y; echo y) | git add -p file &&
- git diff --cached > diff &&
- diff_cmp expected diff
+ printf "%s\n" s y y | git add -p file 2>error |
+ sed -n -e "s/^Stage this hunk[^@]*\(@@ .*\)/\1/" \
+ -e "/^[-+@ \\\\]"/p >output &&
+ test_must_be_empty error &&
+ git diff --cached >diff &&
+ diff_cmp expected diff &&
+ test_cmp expected-output output
'
test_expect_success 'setup expected' '