]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4126-apply-empty.sh
The third batch
[thirdparty/git.git] / t / t4126-apply-empty.sh
CommitLineData
032bea55
JH
1#!/bin/sh
2
3test_description='apply empty'
4
ab1f6926 5TEST_PASSES_SANITIZE_LEAK=true
032bea55
JH
6. ./test-lib.sh
7
8test_expect_success setup '
9 >empty &&
10 git add empty &&
11 test_tick &&
12 git commit -m initial &&
324eb77e
JZ
13 git commit --allow-empty -m "empty commit" &&
14 git format-patch --always HEAD~ >empty.patch &&
08495412 15 test_write_lines a b c d e >empty &&
032bea55
JH
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
25'
26
27test_expect_success 'apply empty' '
032bea55 28 rm -f missing &&
324eb77e 29 test_when_finished "git reset --hard" &&
032bea55
JH
30 git apply patch0 &&
31 test_cmp expect empty
32'
33
324eb77e
JZ
34test_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
38'
39
40test_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
44'
45
032bea55 46test_expect_success 'apply --index empty' '
032bea55 47 rm -f missing &&
324eb77e 48 test_when_finished "git reset --hard" &&
032bea55
JH
49 git apply --index patch0 &&
50 test_cmp expect empty &&
51 git diff --exit-code
52'
53
54test_expect_success 'apply create' '
032bea55 55 rm -f missing &&
324eb77e 56 test_when_finished "git reset --hard" &&
032bea55
JH
57 git apply patch1 &&
58 test_cmp expect missing
59'
60
61test_expect_success 'apply --index create' '
032bea55 62 rm -f missing &&
324eb77e 63 test_when_finished "git reset --hard" &&
032bea55
JH
64 git apply --index patch1 &&
65 test_cmp expect missing &&
66 git diff --exit-code
67'
68
776ffd1a
JH
69test_expect_success !MINGW 'apply with no-contents and a funny pathname' '
70 test_when_finished "rm -fr \"funny \"; git reset --hard" &&
71
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 &&
5ea01760 77
776ffd1a 78 git reset --hard &&
5ea01760 79
776ffd1a
JH
80 git apply --stat --check --apply sample.patch &&
81 test_must_be_empty "funny /empty" &&
5ea01760 82
776ffd1a
JH
83 git apply --stat --check --apply elpmas.patch &&
84 test_path_is_missing "funny /empty" &&
5ea01760 85
776ffd1a
JH
86 git apply -R --stat --check --apply elpmas.patch &&
87 test_must_be_empty "funny /empty" &&
012c8b30 88
776ffd1a
JH
89 git apply -R --stat --check --apply sample.patch &&
90 test_path_is_missing "funny /empty"
5ea01760
JH
91'
92
032bea55 93test_done