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

[PATCH 3/7] t3701: add a test for the different `add -p` prompts

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 6, 2019, 13:08 UTC
Message-ID
<a8bd214c905ff76d3651eec05766ad5b774847e8.1575637705.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.172.git.1575637705.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

The `git add -p` command offers different prompts for regular diff hunks vs mode change pseudo hunks vs diffs deleting files.

Let's cover this in the regresion test suite, in preparation for re-implementing `git add -p` in C.

For the mode change prompt, we use a trick that lets this test case pass even on systems without executable bit, i.e. where `core.filemode = false` (such as Windows): we first add the file to the index with `git add --chmod=+x`, and then call `git add -p` with `core.filemode` forced to `true`. The file on disk has no executable bit set, therefore we will see a mode change.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 t/t3701-add-interactive.sh | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index 793ce28297..c90aaa25b0 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -105,7 +105,6 @@ test_expect_success 'revert works (commit)' '
 	grep "unchanged *+3/-0 file" output
 '
 
-
 test_expect_success 'setup expected' '
 	cat >expected <<-\EOF
 	EOF
@@ -274,6 +273,24 @@ test_expect_success FILEMODE 'stage mode and hunk' '
 
 # end of tests disabled when filemode is not usable
 
+test_expect_success 'different prompts for mode change/deleted' '
+	git reset --hard &&
+	>file &&
+	>deleted &&
+	git add --chmod=+x file deleted &&
+	echo changed >file &&
+	rm deleted &&
+	test_write_lines n n n |
+	git -c core.filemode=true add -p >actual &&
+	sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
+	cat >expect <<-\EOF &&
+	(1/1) Stage deletion [y,n,q,a,d,?]?
+	(1/2) Stage mode change [y,n,q,a,d,j,J,g,/,?]?
+	(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]?
+	EOF
+	test_cmp expect actual.filtered
+'
+
 test_expect_success 'setup again' '
 	git reset --hard &&
 	test_chmod +x file &&
-- 
gitgitgadget
Previous: Jeff KingNext: Johannes Schindelin via GitGitGadget
Message 6 of 15 in “add -i: close some regression test gaps”
  1. 0/7 add -i: close some regression test gapsJohannes Schindelin via GitGitGadget, Dec 6, 2019
  2. 1/7 t3701: add a test for advanced split-hunk editingJohannes Schindelin via GitGitGadget, Dec 6, 2019
  3. 2/7 t3701: avoid depending on the TTY prerequisiteJohannes Schindelin via GitGitGadget, Dec 6, 2019
  4. SZEDER GáborDec 16, 2019
  5. Jeff KingDec 17, 2019
  6. 3/7 t3701: add a test for the different `add -p` promptsJohannes Schindelin via GitGitGadget, Dec 6, 2019
  7. 5/7 t3701: verify that the diff.algorithm config setting is handledJohannes Schindelin via GitGitGadget, Dec 6, 2019
  8. 4/7 t3701: verify the shown messages when nothing can be addedJohannes Schindelin via GitGitGadget, Dec 6, 2019
  9. 7/7 apply --allow-overlap: fix a corner caseJohannes Schindelin via GitGitGadget, Dec 6, 2019
  10. Junio C HamanoDec 6, 2019
  11. Johannes SchindelinDec 6, 2019
  12. Junio C HamanoDec 6, 2019
  13. Johannes SchindelinDec 6, 2019
  14. 6/7 git add -p: use non-zero exit code when the diff generation failedJohannes Schindelin via GitGitGadget, Dec 6, 2019
  15. Junio C HamanoDec 6, 2019

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.