]>
Commit | Line | Data |
---|---|---|
64cab591 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='apply to deeper directory without getting fooled with symlink' | |
8f37854b | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
6 | ||
ab1f6926 | 7 | TEST_PASSES_SANITIZE_LEAK=true |
64cab591 JH |
8 | . ./test-lib.sh |
9 | ||
889c6f0e | 10 | test_expect_success setup ' |
64cab591 JH |
11 | |
12 | mkdir -p arch/i386/boot arch/x86_64 && | |
b65c0588 | 13 | test_write_lines 1 2 3 4 5 >arch/i386/boot/Makefile && |
889c6f0e | 14 | test_ln_s_add ../i386/boot arch/x86_64/boot && |
64cab591 JH |
15 | git add . && |
16 | test_tick && | |
17 | git commit -m initial && | |
18 | git branch test && | |
19 | ||
20 | rm arch/x86_64/boot && | |
21 | mkdir arch/x86_64/boot && | |
b65c0588 | 22 | test_write_lines 2 3 4 5 6 >arch/x86_64/boot/Makefile && |
64cab591 JH |
23 | git add . && |
24 | test_tick && | |
25 | git commit -a -m second && | |
26 | ||
27 | git format-patch --binary -1 --stdout >test.patch | |
28 | ||
29 | ' | |
30 | ||
889c6f0e | 31 | test_expect_success apply ' |
64cab591 JH |
32 | |
33 | git checkout test && | |
64cab591 JH |
34 | git diff --exit-code test && |
35 | git diff --exit-code --cached test && | |
36 | git apply --index test.patch | |
37 | ||
38 | ' | |
39 | ||
889c6f0e | 40 | test_expect_success 'check result' ' |
64cab591 | 41 | |
8f37854b JS |
42 | git diff --exit-code main && |
43 | git diff --exit-code --cached main && | |
64cab591 JH |
44 | test_tick && |
45 | git commit -m replay && | |
8f37854b | 46 | T1=$(git rev-parse "main^{tree}") && |
64cab591 JH |
47 | T2=$(git rev-parse "HEAD^{tree}") && |
48 | test "z$T1" = "z$T2" | |
49 | ||
50 | ' | |
51 | ||
fdc2c3a9 JH |
52 | test_expect_success SYMLINKS 'do not read from beyond symbolic link' ' |
53 | git reset --hard && | |
54 | mkdir -p arch/x86_64/dir && | |
55 | >arch/x86_64/dir/file && | |
56 | git add arch/x86_64/dir/file && | |
57 | echo line >arch/x86_64/dir/file && | |
58 | git diff >patch && | |
59 | git reset --hard && | |
60 | ||
61 | mkdir arch/i386/dir && | |
62 | >arch/i386/dir/file && | |
63 | ln -s ../i386/dir arch/x86_64/dir && | |
64 | ||
65 | test_must_fail git apply patch && | |
66 | test_must_fail git apply --cached patch && | |
67 | test_must_fail git apply --index patch | |
68 | ||
69 | ' | |
70 | ||
e0d201b6 JH |
71 | test_expect_success SYMLINKS 'do not follow symbolic link (setup)' ' |
72 | ||
73 | rm -rf arch/i386/dir arch/x86_64/dir && | |
74 | git reset --hard && | |
75 | ln -s ../i386/dir arch/x86_64/dir && | |
76 | git add arch/x86_64/dir && | |
77 | git diff HEAD >add_symlink.patch && | |
78 | git reset --hard && | |
79 | ||
80 | mkdir arch/x86_64/dir && | |
81 | >arch/x86_64/dir/file && | |
82 | git add arch/x86_64/dir/file && | |
83 | git diff HEAD >add_file.patch && | |
84 | git diff -R HEAD >del_file.patch && | |
85 | git reset --hard && | |
86 | rm -fr arch/x86_64/dir && | |
87 | ||
88 | cat add_symlink.patch add_file.patch >patch && | |
89 | cat add_symlink.patch del_file.patch >tricky_del && | |
90 | ||
91 | mkdir arch/i386/dir | |
92 | ' | |
93 | ||
94 | test_expect_success SYMLINKS 'do not follow symbolic link (same input)' ' | |
95 | ||
96 | # same input creates a confusing symbolic link | |
97 | test_must_fail git apply patch 2>error-wt && | |
6789275d | 98 | test_grep "beyond a symbolic link" error-wt && |
e0d201b6 JH |
99 | test_path_is_missing arch/x86_64/dir && |
100 | test_path_is_missing arch/i386/dir/file && | |
101 | ||
102 | test_must_fail git apply --index patch 2>error-ix && | |
6789275d | 103 | test_grep "beyond a symbolic link" error-ix && |
e0d201b6 JH |
104 | test_path_is_missing arch/x86_64/dir && |
105 | test_path_is_missing arch/i386/dir/file && | |
106 | test_must_fail git ls-files --error-unmatch arch/x86_64/dir && | |
107 | test_must_fail git ls-files --error-unmatch arch/i386/dir && | |
108 | ||
109 | test_must_fail git apply --cached patch 2>error-ct && | |
6789275d | 110 | test_grep "beyond a symbolic link" error-ct && |
e0d201b6 JH |
111 | test_must_fail git ls-files --error-unmatch arch/x86_64/dir && |
112 | test_must_fail git ls-files --error-unmatch arch/i386/dir && | |
113 | ||
114 | >arch/i386/dir/file && | |
115 | git add arch/i386/dir/file && | |
116 | ||
117 | test_must_fail git apply tricky_del && | |
118 | test_path_is_file arch/i386/dir/file && | |
119 | ||
120 | test_must_fail git apply --index tricky_del && | |
121 | test_path_is_file arch/i386/dir/file && | |
122 | test_must_fail git ls-files --error-unmatch arch/x86_64/dir && | |
123 | git ls-files --error-unmatch arch/i386/dir && | |
124 | ||
125 | test_must_fail git apply --cached tricky_del && | |
126 | test_must_fail git ls-files --error-unmatch arch/x86_64/dir && | |
127 | git ls-files --error-unmatch arch/i386/dir | |
128 | ' | |
129 | ||
130 | test_expect_success SYMLINKS 'do not follow symbolic link (existing)' ' | |
131 | ||
132 | # existing symbolic link | |
133 | git reset --hard && | |
134 | ln -s ../i386/dir arch/x86_64/dir && | |
135 | git add arch/x86_64/dir && | |
136 | ||
137 | test_must_fail git apply add_file.patch 2>error-wt-add && | |
6789275d | 138 | test_grep "beyond a symbolic link" error-wt-add && |
e0d201b6 JH |
139 | test_path_is_missing arch/i386/dir/file && |
140 | ||
141 | mkdir arch/i386/dir && | |
142 | >arch/i386/dir/file && | |
143 | test_must_fail git apply del_file.patch 2>error-wt-del && | |
6789275d | 144 | test_grep "beyond a symbolic link" error-wt-del && |
e0d201b6 JH |
145 | test_path_is_file arch/i386/dir/file && |
146 | rm arch/i386/dir/file && | |
147 | ||
148 | test_must_fail git apply --index add_file.patch 2>error-ix-add && | |
6789275d | 149 | test_grep "beyond a symbolic link" error-ix-add && |
e0d201b6 JH |
150 | test_path_is_missing arch/i386/dir/file && |
151 | test_must_fail git ls-files --error-unmatch arch/i386/dir && | |
152 | ||
153 | test_must_fail git apply --cached add_file.patch 2>error-ct-file && | |
6789275d | 154 | test_grep "beyond a symbolic link" error-ct-file && |
e0d201b6 JH |
155 | test_must_fail git ls-files --error-unmatch arch/i386/dir |
156 | ' | |
157 | ||
64cab591 | 158 | test_done |