]> git.ipfire.org Git - thirdparty/git.git/blob - t/t4122-apply-symlink-inside.sh
Merge branch 'es/maintenance-of-bare-repositories'
[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-lib.sh
8
9 test_expect_success setup '
10
11 mkdir -p arch/i386/boot arch/x86_64 &&
12 test_write_lines 1 2 3 4 5 >arch/i386/boot/Makefile &&
13 test_ln_s_add ../i386/boot arch/x86_64/boot &&
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 &&
21 test_write_lines 2 3 4 5 6 >arch/x86_64/boot/Makefile &&
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
30 test_expect_success apply '
31
32 git checkout test &&
33 git diff --exit-code test &&
34 git diff --exit-code --cached test &&
35 git apply --index test.patch
36
37 '
38
39 test_expect_success 'check result' '
40
41 git diff --exit-code main &&
42 git diff --exit-code --cached main &&
43 test_tick &&
44 git commit -m replay &&
45 T1=$(git rev-parse "main^{tree}") &&
46 T2=$(git rev-parse "HEAD^{tree}") &&
47 test "z$T1" = "z$T2"
48
49 '
50
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
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
157 test_done