@matheusbsbs / matheus-bagliano / commits / 4c025c667e
Fork 0

t4140: test apply with i-t-a paths

apply --cached (as used by add -p) should accept creation and deletion patches to intent-to-add paths in the index. apply --index, however, should always fail because an intent-to-add path never matches the worktree (by definition). Based-on-patch-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Raymond E. Pasco <ray@ameretat.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Raymond E. Pasco committed Aug 8, 2020 at 03:49 UTC 4c025c667ee29dd5e9260f423e8b0b3cc37e5e8c
1 file changed +56
t/t4140-apply-ita.sh new
+56
@@ -0,0 +1,56 @@
1 +#!/bin/sh
2 +
3 +test_description='git apply of i-t-a file'
4 +
5 +. ./test-lib.sh
6 +
7 +test_expect_success setup '
8 + test_write_lines 1 2 3 4 5 >blueprint &&
9 +
10 + cat blueprint >test-file &&
11 + git add -N test-file &&
12 + git diff >creation-patch &&
13 + grep "new file mode 100644" creation-patch &&
14 +
15 + rm -f test-file &&
16 + git diff >deletion-patch &&
17 + grep "deleted file mode 100644" deletion-patch
18 +'
19 +
20 +test_expect_success 'apply creation patch to ita path (--cached)' '
21 + git rm -f test-file &&
22 + cat blueprint >test-file &&
23 + git add -N test-file &&
24 +
25 + git apply --cached creation-patch &&
26 + git cat-file blob :test-file >actual &&
27 + test_cmp blueprint actual
28 +'
29 +
30 +test_expect_success 'apply creation patch to ita path (--index)' '
31 + git rm -f test-file &&
32 + cat blueprint >test-file &&
33 + git add -N test-file &&
34 + rm -f test-file &&
35 +
36 + test_must_fail git apply --index creation-patch
37 +'
38 +
39 +test_expect_success 'apply deletion patch to ita path (--cached)' '
40 + git rm -f test-file &&
41 + cat blueprint >test-file &&
42 + git add -N test-file &&
43 +
44 + git apply --cached deletion-patch &&
45 + test_must_fail git ls-files --stage --error-unmatch test-file
46 +'
47 +
48 +test_expect_success 'apply deletion patch to ita path (--index)' '
49 + cat blueprint >test-file &&
50 + git add -N test-file &&
51 +
52 + test_must_fail git apply --index deletion-patch &&
53 + git ls-files --stage --error-unmatch test-file
54 +'
55 +
56 +test_done