Skip to content

Commit a8bd214

Browse files
committed
t3701: add a test for the different add -p prompts
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 <[email protected]>
1 parent ed870d3 commit a8bd214

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

t/t3701-add-interactive.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ test_expect_success 'revert works (commit)' '
105105
grep "unchanged *+3/-0 file" output
106106
'
107107

108-
109108
test_expect_success 'setup expected' '
110109
cat >expected <<-\EOF
111110
EOF
@@ -274,6 +273,24 @@ test_expect_success FILEMODE 'stage mode and hunk' '
274273

275274
# end of tests disabled when filemode is not usable
276275

276+
test_expect_success 'different prompts for mode change/deleted' '
277+
git reset --hard &&
278+
>file &&
279+
>deleted &&
280+
git add --chmod=+x file deleted &&
281+
echo changed >file &&
282+
rm deleted &&
283+
test_write_lines n n n |
284+
git -c core.filemode=true add -p >actual &&
285+
sed -n "s/^\(([0-9/]*) Stage .*?\).*/\1/p" actual >actual.filtered &&
286+
cat >expect <<-\EOF &&
287+
(1/1) Stage deletion [y,n,q,a,d,?]?
288+
(1/2) Stage mode change [y,n,q,a,d,j,J,g,/,?]?
289+
(2/2) Stage this hunk [y,n,q,a,d,K,g,/,e,?]?
290+
EOF
291+
test_cmp expect actual.filtered
292+
'
293+
277294
test_expect_success 'setup again' '
278295
git reset --hard &&
279296
test_chmod +x file &&

0 commit comments

Comments
 (0)