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