]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4122-apply-symlink-inside.sh
The third batch
[thirdparty/git.git] / t / t4122-apply-symlink-inside.sh
1 #!/bin/sh
2
3 test_description='apply to deeper directory without getting fooled with symlink'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 test_expect_success setup '
11
12 mkdir -p arch/i386/boot arch/x86_64 &&
13 test_write_lines 1 2 3 4 5 >arch/i386/boot/Makefile &&
14 test_ln_s_add ../i386/boot arch/x86_64/boot &&
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 &&
22 test_write_lines 2 3 4 5 6 >arch/x86_64/boot/Makefile &&
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
31 test_expect_success apply '
32
33 git checkout test &&
34 git diff --exit-code test &&
35 git diff --exit-code --cached test &&
36 git apply --index test.patch
37
38 '
39
40 test_expect_success 'check result' '
41
42 git diff --exit-code main &&
43 git diff --exit-code --cached main &&
44 test_tick &&
45 git commit -m replay &&
46 T1=$(git rev-parse "main^{tree}") &&
47 T2=$(git rev-parse "HEAD^{tree}") &&
48 test "z$T1" = "z$T2"
49
50 '
51
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
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 &&
98 test_grep "beyond a symbolic link" error-wt &&
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 &&
103 test_grep "beyond a symbolic link" error-ix &&
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 &&
110 test_grep "beyond a symbolic link" error-ct &&
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 &&
138 test_grep "beyond a symbolic link" error-wt-add &&
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 &&
144 test_grep "beyond a symbolic link" error-wt-del &&
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 &&
149 test_grep "beyond a symbolic link" error-ix-add &&
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 &&
154 test_grep "beyond a symbolic link" error-ct-file &&
155 test_must_fail git ls-files --error-unmatch arch/i386/dir
156 '
157
158 test_done