rebase: use correct base for --keep-base when a branch is given
[alt-git.git] / t / t4122-apply-symlink-inside.sh
blobaa52de401b96ec1e6c7f2c2c6ec87ef4d0d393e7
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-lib.sh
9 test_expect_success setup '
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 &&
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 &&
26 git format-patch --binary -1 --stdout >test.patch
30 test_expect_success apply '
32 git checkout test &&
33 git diff --exit-code test &&
34 git diff --exit-code --cached test &&
35 git apply --index test.patch
39 test_expect_success 'check result' '
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"
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 &&
60 mkdir arch/i386/dir &&
61 >arch/i386/dir/file &&
62 ln -s ../i386/dir arch/x86_64/dir &&
64 test_must_fail git apply patch &&
65 test_must_fail git apply --cached patch &&
66 test_must_fail git apply --index patch
70 test_expect_success SYMLINKS 'do not follow symbolic link (setup)' '
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 &&
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 &&
87 cat add_symlink.patch add_file.patch >patch &&
88 cat add_symlink.patch del_file.patch >tricky_del &&
90 mkdir arch/i386/dir
93 test_expect_success SYMLINKS 'do not follow symbolic link (same input)' '
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 &&
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 &&
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 &&
113 >arch/i386/dir/file &&
114 git add arch/i386/dir/file &&
116 test_must_fail git apply tricky_del &&
117 test_path_is_file arch/i386/dir/file &&
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 &&
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
129 test_expect_success SYMLINKS 'do not follow symbolic link (existing)' '
131 # existing symbolic link
132 git reset --hard &&
133 ln -s ../i386/dir arch/x86_64/dir &&
134 git add arch/x86_64/dir &&
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 &&
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 &&
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 &&
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
157 test_done