Sync with 2.44.1
[git/gitster.git] / t / t4122-apply-symlink-inside.sh
blob2089d84f64577b2b0ac6fdd762cfec8bd259c96c
1 #!/bin/sh
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
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success setup '
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 &&
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 &&
27 git format-patch --binary -1 --stdout >test.patch
31 test_expect_success apply '
33 git checkout test &&
34 git diff --exit-code test &&
35 git diff --exit-code --cached test &&
36 git apply --index test.patch
40 test_expect_success 'check result' '
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"
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 &&
61 mkdir arch/i386/dir &&
62 >arch/i386/dir/file &&
63 ln -s ../i386/dir arch/x86_64/dir &&
65 test_must_fail git apply patch &&
66 test_must_fail git apply --cached patch &&
67 test_must_fail git apply --index patch
71 test_expect_success SYMLINKS 'do not follow symbolic link (setup)' '
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 &&
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 &&
88 cat add_symlink.patch add_file.patch >patch &&
89 cat add_symlink.patch del_file.patch >tricky_del &&
91 mkdir arch/i386/dir
94 test_expect_success SYMLINKS 'do not follow symbolic link (same input)' '
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 &&
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 &&
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 &&
114 >arch/i386/dir/file &&
115 git add arch/i386/dir/file &&
117 test_must_fail git apply tricky_del &&
118 test_path_is_file arch/i386/dir/file &&
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 &&
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
130 test_expect_success SYMLINKS 'do not follow symbolic link (existing)' '
132 # existing symbolic link
133 git reset --hard &&
134 ln -s ../i386/dir arch/x86_64/dir &&
135 git add arch/x86_64/dir &&
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 &&
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 &&
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 &&
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
158 test_done