git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] new test fails "add -p" for adds on the top line

From
Matt Graham <mdg149@gmail.com>
Date
May 16, 2009, 03:10 UTC
Message-ID
<1c5969370905152010m486a8b85s96334e99e6c54ad5@mail.gmail.com>

add -p doesn't work for some diffs. diffs adding a new line at the top of the file with other adds later in the file are one way to trigger the problem.

during add -p, split the diff and then answer y for all segments. the file won't have been added to the index.

Signed-off-by: Matthew Graham <mdg149@gmail.com>
---
 t/t3701-add-interactive.sh |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index dfc6560..45da6c8 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -163,6 +163,38 @@ test_expect_success FILEMODE 'stage mode but not hunk' '
 	git diff          file | grep "+content"
 '

+# Write the patch file with a new line at the top and bottom
+cat >patch <<EOF
+index 180b47c..b6f2c08 100644
+--- a/file
++++ b/file
+@@ -1,2 +1,4 @@
++firstline
+ baseline
+ content
++lastline
+EOF
+# Expected output, similar to the patch but w/ diff at the top
+cat >expected <<EOF
+diff --git a/file b/file
+index b6f2c08..61b9053 100755
+--- a/file
++++ b/file
+@@ -1,2 +1,4 @@
++firstline
+ baseline
+ content
++lastline
+EOF
+# Test splitting the first patch, then adding both
+test_expect_failure '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 &&
+	test_cmp expected diff
+'
+
 # end of tests disabled when filemode is not usable

 test_done
-- 
1.6.3.9.g6345
Next: Nanako Shiraishi
Message 1 of 8 in “new test fails "add -p" for adds on the top line”
  1. new test fails "add -p" for adds on the top lineMatt Graham, May 16, 2009
  2. Nanako ShiraishiMay 16, 2009
  3. Thomas RastMay 16, 2009
  4. Junio C HamanoMay 16, 2009
  5. Sverre RabbelierMay 16, 2009
  6. Junio C HamanoMay 16, 2009
  7. Sverre RabbelierMay 16, 2009
  8. Junio C HamanoMay 16, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.