]>
Commit | Line | Data |
---|---|---|
27128996 GG |
1 | #!/bin/sh |
2 | ||
3 | test_description='directory traversal respects user config | |
4 | ||
5 | This test verifies the traversal of the directory tree when the traversal begins | |
6 | outside the repository. Two instances for which this can occur are tested: | |
7 | ||
8 | 1) The user manually sets the worktree. For this instance, the test sets | |
9 | the worktree two levels above the `.git` directory and checks whether we | |
10 | are able to add to the index those files that are in either (1) the | |
11 | manually configured worktree directory or (2) the standard worktree | |
12 | location with respect to the `.git` directory (i.e. ensuring that the | |
13 | encountered `.git` directory is not treated as belonging to a foreign | |
14 | nested repository). | |
15 | 2) The user manually sets the `git_dir` while the working directory is | |
16 | outside the repository. The test checks that files inside the | |
17 | repository can be added to the index. | |
18 | ' | |
19 | ||
3e3b9321 | 20 | TEST_PASSES_SANITIZE_LEAK=true |
27128996 GG |
21 | . ./test-lib.sh |
22 | ||
23 | test_expect_success '1a: setup--config worktree' ' | |
24 | mkdir test1 && | |
25 | ( | |
26 | cd test1 && | |
27 | test_create_repo repo && | |
28 | git --git-dir="repo/.git" config core.worktree "$(pwd)" && | |
29 | ||
30 | mkdir -p outside-tracked outside-untracked && | |
31 | mkdir -p repo/inside-tracked repo/inside-untracked && | |
32 | >file-tracked && | |
33 | >file-untracked && | |
34 | >outside-tracked/file && | |
35 | >outside-untracked/file && | |
36 | >repo/file-tracked && | |
37 | >repo/file-untracked && | |
38 | >repo/inside-tracked/file && | |
39 | >repo/inside-untracked/file && | |
40 | ||
41 | cat >expect-tracked-unsorted <<-EOF && | |
42 | ../file-tracked | |
43 | ../outside-tracked/file | |
44 | file-tracked | |
45 | inside-tracked/file | |
46 | EOF | |
47 | ||
48 | cat >expect-untracked-unsorted <<-EOF && | |
49 | ../file-untracked | |
50 | ../outside-untracked/file | |
51 | file-untracked | |
52 | inside-untracked/file | |
53 | EOF | |
54 | ||
55 | cat >expect-all-dir-unsorted <<-EOF && | |
56 | ../file-untracked | |
57 | ../file-tracked | |
58 | ../outside-untracked/ | |
59 | ../outside-tracked/ | |
60 | ./ | |
61 | EOF | |
62 | ||
63 | cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted && | |
64 | ||
65 | cat >.gitignore <<-EOF | |
66 | .gitignore | |
67 | actual-* | |
68 | expect-* | |
69 | EOF | |
70 | ) | |
71 | ' | |
72 | ||
73 | test_expect_success '1b: pre-add all' ' | |
74 | ( | |
75 | cd test1 && | |
76 | local parent_dir="$(pwd)" && | |
77 | git -C repo ls-files -o --exclude-standard "$parent_dir" >actual-all-unsorted && | |
78 | sort actual-all-unsorted >actual-all && | |
79 | sort expect-all-unsorted >expect-all && | |
80 | test_cmp expect-all actual-all | |
81 | ) | |
82 | ' | |
83 | ||
84 | test_expect_success '1c: pre-add dir all' ' | |
85 | ( | |
86 | cd test1 && | |
87 | local parent_dir="$(pwd)" && | |
88 | git -C repo ls-files -o --directory --exclude-standard "$parent_dir" >actual-all-dir-unsorted && | |
89 | sort actual-all-dir-unsorted >actual-all && | |
90 | sort expect-all-dir-unsorted >expect-all && | |
91 | test_cmp expect-all actual-all | |
92 | ) | |
93 | ' | |
94 | ||
95 | test_expect_success '1d: post-add tracked' ' | |
96 | ( | |
97 | cd test1 && | |
98 | local parent_dir="$(pwd)" && | |
99 | ( | |
100 | cd repo && | |
101 | git add file-tracked && | |
102 | git add inside-tracked && | |
103 | git add ../outside-tracked && | |
104 | git add "$parent_dir/file-tracked" && | |
105 | git ls-files "$parent_dir" >../actual-tracked-unsorted | |
106 | ) && | |
107 | sort actual-tracked-unsorted >actual-tracked && | |
108 | sort expect-tracked-unsorted >expect-tracked && | |
109 | test_cmp expect-tracked actual-tracked | |
110 | ) | |
111 | ' | |
112 | ||
113 | test_expect_success '1e: post-add untracked' ' | |
114 | ( | |
115 | cd test1 && | |
116 | local parent_dir="$(pwd)" && | |
117 | git -C repo ls-files -o --exclude-standard "$parent_dir" >actual-untracked-unsorted && | |
118 | sort actual-untracked-unsorted >actual-untracked && | |
119 | sort expect-untracked-unsorted >expect-untracked && | |
120 | test_cmp expect-untracked actual-untracked | |
121 | ) | |
122 | ' | |
123 | ||
124 | test_expect_success '2a: setup--set git-dir' ' | |
125 | mkdir test2 && | |
126 | ( | |
127 | cd test2 && | |
128 | test_create_repo repo && | |
129 | # create two foreign repositories that should remain untracked | |
130 | test_create_repo repo-outside && | |
131 | test_create_repo repo/repo-inside && | |
132 | ||
133 | mkdir -p repo/inside-tracked repo/inside-untracked && | |
134 | >repo/file-tracked && | |
135 | >repo/file-untracked && | |
136 | >repo/inside-tracked/file && | |
137 | >repo/inside-untracked/file && | |
138 | >repo-outside/file && | |
139 | >repo/repo-inside/file && | |
140 | ||
141 | cat >expect-tracked-unsorted <<-EOF && | |
142 | repo/file-tracked | |
143 | repo/inside-tracked/file | |
144 | EOF | |
145 | ||
146 | cat >expect-untracked-unsorted <<-EOF && | |
147 | repo/file-untracked | |
148 | repo/inside-untracked/file | |
149 | repo/repo-inside/ | |
150 | repo-outside/ | |
151 | EOF | |
152 | ||
153 | cat >expect-all-dir-unsorted <<-EOF && | |
154 | repo/ | |
155 | repo-outside/ | |
156 | EOF | |
157 | ||
158 | cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted && | |
159 | ||
160 | cat >.gitignore <<-EOF | |
161 | .gitignore | |
162 | actual-* | |
163 | expect-* | |
164 | EOF | |
165 | ) | |
166 | ' | |
167 | ||
168 | test_expect_success '2b: pre-add all' ' | |
169 | ( | |
170 | cd test2 && | |
171 | git --git-dir=repo/.git ls-files -o --exclude-standard >actual-all-unsorted && | |
172 | sort actual-all-unsorted >actual-all && | |
173 | sort expect-all-unsorted >expect-all && | |
174 | test_cmp expect-all actual-all | |
175 | ) | |
176 | ' | |
177 | ||
178 | test_expect_success '2c: pre-add dir all' ' | |
179 | ( | |
180 | cd test2 && | |
181 | git --git-dir=repo/.git ls-files -o --directory --exclude-standard >actual-all-dir-unsorted && | |
182 | sort actual-all-dir-unsorted >actual-all && | |
183 | sort expect-all-dir-unsorted >expect-all && | |
184 | test_cmp expect-all actual-all | |
185 | ) | |
186 | ' | |
187 | ||
188 | test_expect_success '2d: post-add tracked' ' | |
189 | ( | |
190 | cd test2 && | |
191 | git --git-dir=repo/.git add repo/file-tracked && | |
192 | git --git-dir=repo/.git add repo/inside-tracked && | |
193 | git --git-dir=repo/.git ls-files >actual-tracked-unsorted && | |
194 | sort actual-tracked-unsorted >actual-tracked && | |
195 | sort expect-tracked-unsorted >expect-tracked && | |
196 | test_cmp expect-tracked actual-tracked | |
197 | ) | |
198 | ' | |
199 | ||
200 | test_expect_success '2e: post-add untracked' ' | |
201 | ( | |
202 | cd test2 && | |
203 | git --git-dir=repo/.git ls-files -o --exclude-standard >actual-untracked-unsorted && | |
204 | sort actual-untracked-unsorted >actual-untracked && | |
205 | sort expect-untracked-unsorted >expect-untracked && | |
206 | test_cmp expect-untracked actual-untracked | |
207 | ) | |
208 | ' | |
209 | ||
210 | test_expect_success '3a: setup--add repo dir' ' | |
211 | mkdir test3 && | |
212 | ( | |
213 | cd test3 && | |
214 | test_create_repo repo && | |
215 | ||
216 | mkdir -p repo/inside-tracked repo/inside-ignored && | |
217 | >repo/file-tracked && | |
218 | >repo/file-ignored && | |
219 | >repo/inside-tracked/file && | |
220 | >repo/inside-ignored/file && | |
221 | ||
222 | cat >.gitignore <<-EOF && | |
223 | .gitignore | |
224 | actual-* | |
225 | expect-* | |
226 | *ignored | |
227 | EOF | |
228 | ||
229 | cat >expect-tracked-unsorted <<-EOF && | |
230 | repo/file-tracked | |
231 | repo/inside-tracked/file | |
232 | EOF | |
233 | ||
234 | cat >expect-ignored-unsorted <<-EOF | |
235 | repo/file-ignored | |
236 | repo/inside-ignored/ | |
237 | .gitignore | |
238 | actual-ignored-unsorted | |
239 | expect-ignored-unsorted | |
240 | expect-tracked-unsorted | |
241 | EOF | |
242 | ) | |
243 | ' | |
244 | ||
245 | test_expect_success '3b: ignored' ' | |
246 | ( | |
247 | cd test3 && | |
248 | git --git-dir=repo/.git ls-files -io --directory --exclude-standard >actual-ignored-unsorted && | |
249 | sort actual-ignored-unsorted >actual-ignored && | |
250 | sort expect-ignored-unsorted >expect-ignored && | |
251 | test_cmp expect-ignored actual-ignored | |
252 | ) | |
253 | ' | |
254 | ||
255 | test_expect_success '3c: add repo' ' | |
256 | ( | |
257 | cd test3 && | |
258 | git --git-dir=repo/.git add repo && | |
259 | git --git-dir=repo/.git ls-files >actual-tracked-unsorted && | |
260 | sort actual-tracked-unsorted >actual-tracked && | |
261 | sort expect-tracked-unsorted >expect-tracked && | |
262 | test_cmp expect-tracked actual-tracked | |
263 | ) | |
264 | ' | |
265 | ||
266 | test_done |