Merge branch 'kz/merge-fail-early-upon-refresh-failure'
[git.git] / t / t4126-apply-empty.sh
blob56210b5609919dbd625cfe12c49ab7e858534896
1 #!/bin/sh
3 test_description='apply empty'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success setup '
9 >empty &&
10 git add empty &&
11 test_tick &&
12 git commit -m initial &&
13 git commit --allow-empty -m "empty commit" &&
14 git format-patch --always HEAD~ >empty.patch &&
15 test_write_lines a b c d e >empty &&
16 cat empty >expect &&
17 git diff |
18 sed -e "/^diff --git/d" \
19 -e "/^index /d" \
20 -e "s|a/empty|empty.orig|" \
21 -e "s|b/empty|empty|" >patch0 &&
22 sed -e "s|empty|missing|" patch0 >patch1 &&
23 >empty &&
24 git update-index --refresh
27 test_expect_success 'apply empty' '
28 rm -f missing &&
29 test_when_finished "git reset --hard" &&
30 git apply patch0 &&
31 test_cmp expect empty
34 test_expect_success 'apply empty patch fails' '
35 test_when_finished "git reset --hard" &&
36 test_must_fail git apply empty.patch &&
37 test_must_fail git apply - </dev/null
40 test_expect_success 'apply with --allow-empty succeeds' '
41 test_when_finished "git reset --hard" &&
42 git apply --allow-empty empty.patch &&
43 git apply --allow-empty - </dev/null
46 test_expect_success 'apply --index empty' '
47 rm -f missing &&
48 test_when_finished "git reset --hard" &&
49 git apply --index patch0 &&
50 test_cmp expect empty &&
51 git diff --exit-code
54 test_expect_success 'apply create' '
55 rm -f missing &&
56 test_when_finished "git reset --hard" &&
57 git apply patch1 &&
58 test_cmp expect missing
61 test_expect_success 'apply --index create' '
62 rm -f missing &&
63 test_when_finished "git reset --hard" &&
64 git apply --index patch1 &&
65 test_cmp expect missing &&
66 git diff --exit-code
69 test_expect_success !MINGW 'apply with no-contents and a funny pathname' '
70 test_when_finished "rm -fr \"funny \"; git reset --hard" &&
72 mkdir "funny " &&
73 >"funny /empty" &&
74 git add "funny /empty" &&
75 git diff HEAD -- "funny /" >sample.patch &&
76 git diff -R HEAD -- "funny /" >elpmas.patch &&
78 git reset --hard &&
80 git apply --stat --check --apply sample.patch &&
81 test_must_be_empty "funny /empty" &&
83 git apply --stat --check --apply elpmas.patch &&
84 test_path_is_missing "funny /empty" &&
86 git apply -R --stat --check --apply elpmas.patch &&
87 test_must_be_empty "funny /empty" &&
89 git apply -R --stat --check --apply sample.patch &&
90 test_path_is_missing "funny /empty"
93 test_done