Raw
1 #!/bin/sh
2
3 test_description='apply empty'
4
5 . ./test-lib.sh
6
7 test_expect_success setup '
8 >empty &&
9 git add empty &&
10 test_tick &&
11 git commit -m initial &&
12 git commit --allow-empty -m "empty commit" &&
13 git format-patch --always HEAD~ >empty.patch &&
14 test_write_lines a b c d e >empty &&
15 cat empty >expect &&
16 git diff |
17 sed -e "/^diff --git/d" \
18 -e "/^index /d" \
19 -e "s|a/empty|empty.orig|" \
20 -e "s|b/empty|empty|" >patch0 &&
21 sed -e "s|empty|missing|" patch0 >patch1 &&
22 >empty &&
23 git update-index --refresh
24 '
25
26 test_expect_success 'apply empty' '
27 rm -f missing &&
28 test_when_finished "git reset --hard" &&
29 git apply patch0 &&
30 test_cmp expect empty
31 '
32
33 test_expect_success 'apply empty patch fails' '
34 test_when_finished "git reset --hard" &&
35 test_must_fail git apply empty.patch &&
36 test_must_fail git apply - </dev/null
37 '
38
39 test_expect_success 'apply with --allow-empty succeeds' '
40 test_when_finished "git reset --hard" &&
41 git apply --allow-empty empty.patch &&
42 git apply --allow-empty - </dev/null
43 '
44
45 test_expect_success 'apply --index empty' '
46 rm -f missing &&
47 test_when_finished "git reset --hard" &&
48 git apply --index patch0 &&
49 test_cmp expect empty &&
50 git diff --exit-code
51 '
52
53 test_expect_success 'apply create' '
54 rm -f missing &&
55 test_when_finished "git reset --hard" &&
56 git apply patch1 &&
57 test_cmp expect missing
58 '
59
60 test_expect_success 'apply --index create' '
61 rm -f missing &&
62 test_when_finished "git reset --hard" &&
63 git apply --index patch1 &&
64 test_cmp expect missing &&
65 git diff --exit-code
66 '
67
68 test_expect_success !MINGW 'apply with no-contents and a funny pathname' '
69 test_when_finished "rm -fr \"funny \"; git reset --hard" &&
70
71 mkdir "funny " &&
72 >"funny /empty" &&
73 git add "funny /empty" &&
74 git diff HEAD -- "funny /" >sample.patch &&
75 git diff -R HEAD -- "funny /" >elpmas.patch &&
76
77 git reset --hard &&
78
79 git apply --stat --check --apply sample.patch &&
80 test_must_be_empty "funny /empty" &&
81
82 git apply --stat --check --apply elpmas.patch &&
83 test_path_is_missing "funny /empty" &&
84
85 git apply -R --stat --check --apply elpmas.patch &&
86 test_must_be_empty "funny /empty" &&
87
88 git apply -R --stat --check --apply sample.patch &&
89 test_path_is_missing "funny /empty"
90 '
91
92 test_done