summaryrefslogtreecommitdiff
path: root/t
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 /t
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 't')
-rwxr-xr-xt/t3701-add-interactive.sh31
1 files changed, 23 insertions, 8 deletions
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 24ed3f4..e5c66f7 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' '