Skip to content

Commit f67182b

Browse files
mdggitster
authored andcommitted
Splitting a hunk that adds a line at the top fails in "add -p"
Splitting a hunk into two in add -p doesn't work for a diff that adds a new line at the top of the file with other add in the same hunk. Signed-off-by: Matthew Graham <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4774780 commit f67182b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

t/t3701-add-interactive.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,36 @@ test_expect_success FILEMODE 'stage mode but not hunk' '
165165

166166
# end of tests disabled when filemode is not usable
167167

168+
# Write the patch file with a new line at the top and bottom
169+
cat >patch <<EOF
170+
index 180b47c..b6f2c08 100644
171+
--- a/file
172+
+++ b/file
173+
@@ -1,2 +1,4 @@
174+
+firstline
175+
baseline
176+
content
177+
+lastline
178+
EOF
179+
# Expected output, similar to the patch but w/ diff at the top
180+
cat >expected <<EOF
181+
diff --git a/file b/file
182+
index b6f2c08..61b9053 100755
183+
--- a/file
184+
+++ b/file
185+
@@ -1,2 +1,4 @@
186+
+firstline
187+
baseline
188+
content
189+
+lastline
190+
EOF
191+
# Test splitting the first patch, then adding both
192+
test_expect_failure 'add first line works' '
193+
git commit -am "clear local changes" &&
194+
git apply patch &&
195+
(echo s; echo y; echo y) | git add -p file &&
196+
git diff --cached > diff &&
197+
test_cmp expected diff
198+
'
199+
168200
test_done

0 commit comments

Comments
 (0)