clone: use OPT_STRING_LIST for --reference
[git/mingw/j6t.git] / t / t4122-apply-symlink-inside.sh
blob1779c0a5687c471b1e6d2e78a8509b9ca6c31307
1 #!/bin/sh
3 test_description='apply to deeper directory without getting fooled with symlink'
4 . ./test-lib.sh
6 lecho () {
7 for l_
8 do
9 echo "$l_"
10 done
13 test_expect_success setup '
15 mkdir -p arch/i386/boot arch/x86_64 &&
16 lecho 1 2 3 4 5 >arch/i386/boot/Makefile &&
17 test_ln_s_add ../i386/boot arch/x86_64/boot &&
18 git add . &&
19 test_tick &&
20 git commit -m initial &&
21 git branch test &&
23 rm arch/x86_64/boot &&
24 mkdir arch/x86_64/boot &&
25 lecho 2 3 4 5 6 >arch/x86_64/boot/Makefile &&
26 git add . &&
27 test_tick &&
28 git commit -a -m second &&
30 git format-patch --binary -1 --stdout >test.patch
34 test_expect_success apply '
36 git checkout test &&
37 git diff --exit-code test &&
38 git diff --exit-code --cached test &&
39 git apply --index test.patch
43 test_expect_success 'check result' '
45 git diff --exit-code master &&
46 git diff --exit-code --cached master &&
47 test_tick &&
48 git commit -m replay &&
49 T1=$(git rev-parse "master^{tree}") &&
50 T2=$(git rev-parse "HEAD^{tree}") &&
51 test "z$T1" = "z$T2"
55 test_expect_success SYMLINKS 'do not read from beyond symbolic link' '
56 git reset --hard &&
57 mkdir -p arch/x86_64/dir &&
58 >arch/x86_64/dir/file &&
59 git add arch/x86_64/dir/file &&
60 echo line >arch/x86_64/dir/file &&
61 git diff >patch &&
62 git reset --hard &&
64 mkdir arch/i386/dir &&
65 >arch/i386/dir/file &&
66 ln -s ../i386/dir arch/x86_64/dir &&
68 test_must_fail git apply patch &&
69 test_must_fail git apply --cached patch &&
70 test_must_fail git apply --index patch
74 test_expect_success SYMLINKS 'do not follow symbolic link (setup)' '
76 rm -rf arch/i386/dir arch/x86_64/dir &&
77 git reset --hard &&
78 ln -s ../i386/dir arch/x86_64/dir &&
79 git add arch/x86_64/dir &&
80 git diff HEAD >add_symlink.patch &&
81 git reset --hard &&
83 mkdir arch/x86_64/dir &&
84 >arch/x86_64/dir/file &&
85 git add arch/x86_64/dir/file &&
86 git diff HEAD >add_file.patch &&
87 git diff -R HEAD >del_file.patch &&
88 git reset --hard &&
89 rm -fr arch/x86_64/dir &&
91 cat add_symlink.patch add_file.patch >patch &&
92 cat add_symlink.patch del_file.patch >tricky_del &&
94 mkdir arch/i386/dir
97 test_expect_success SYMLINKS 'do not follow symbolic link (same input)' '
99 # same input creates a confusing symbolic link
100 test_must_fail git apply patch 2>error-wt &&
101 test_i18ngrep "beyond a symbolic link" error-wt &&
102 test_path_is_missing arch/x86_64/dir &&
103 test_path_is_missing arch/i386/dir/file &&
105 test_must_fail git apply --index patch 2>error-ix &&
106 test_i18ngrep "beyond a symbolic link" error-ix &&
107 test_path_is_missing arch/x86_64/dir &&
108 test_path_is_missing arch/i386/dir/file &&
109 test_must_fail git ls-files --error-unmatch arch/x86_64/dir &&
110 test_must_fail git ls-files --error-unmatch arch/i386/dir &&
112 test_must_fail git apply --cached patch 2>error-ct &&
113 test_i18ngrep "beyond a symbolic link" error-ct &&
114 test_must_fail git ls-files --error-unmatch arch/x86_64/dir &&
115 test_must_fail git ls-files --error-unmatch arch/i386/dir &&
117 >arch/i386/dir/file &&
118 git add arch/i386/dir/file &&
120 test_must_fail git apply tricky_del &&
121 test_path_is_file arch/i386/dir/file &&
123 test_must_fail git apply --index tricky_del &&
124 test_path_is_file arch/i386/dir/file &&
125 test_must_fail git ls-files --error-unmatch arch/x86_64/dir &&
126 git ls-files --error-unmatch arch/i386/dir &&
128 test_must_fail git apply --cached tricky_del &&
129 test_must_fail git ls-files --error-unmatch arch/x86_64/dir &&
130 git ls-files --error-unmatch arch/i386/dir
133 test_expect_success SYMLINKS 'do not follow symbolic link (existing)' '
135 # existing symbolic link
136 git reset --hard &&
137 ln -s ../i386/dir arch/x86_64/dir &&
138 git add arch/x86_64/dir &&
140 test_must_fail git apply add_file.patch 2>error-wt-add &&
141 test_i18ngrep "beyond a symbolic link" error-wt-add &&
142 test_path_is_missing arch/i386/dir/file &&
144 mkdir arch/i386/dir &&
145 >arch/i386/dir/file &&
146 test_must_fail git apply del_file.patch 2>error-wt-del &&
147 test_i18ngrep "beyond a symbolic link" error-wt-del &&
148 test_path_is_file arch/i386/dir/file &&
149 rm arch/i386/dir/file &&
151 test_must_fail git apply --index add_file.patch 2>error-ix-add &&
152 test_i18ngrep "beyond a symbolic link" error-ix-add &&
153 test_path_is_missing arch/i386/dir/file &&
154 test_must_fail git ls-files --error-unmatch arch/i386/dir &&
156 test_must_fail git apply --cached add_file.patch 2>error-ct-file &&
157 test_i18ngrep "beyond a symbolic link" error-ct-file &&
158 test_must_fail git ls-files --error-unmatch arch/i386/dir
161 test_done