3 test_description
='directory traversal respects user config
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:
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
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.
20 TEST_PASSES_SANITIZE_LEAK
=true
23 test_expect_success
'1a: setup--config worktree' '
27 test_create_repo repo &&
28 git --git-dir="repo/.git" config core.worktree "$(pwd)" &&
30 mkdir -p outside-tracked outside-untracked &&
31 mkdir -p repo/inside-tracked repo/inside-untracked &&
34 >outside-tracked/file &&
35 >outside-untracked/file &&
37 >repo/file-untracked &&
38 >repo/inside-tracked/file &&
39 >repo/inside-untracked/file &&
41 cat >expect-tracked-unsorted <<-EOF &&
43 ../outside-tracked/file
48 cat >expect-untracked-unsorted <<-EOF &&
50 ../outside-untracked/file
55 cat >expect-all-dir-unsorted <<-EOF &&
63 cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted &&
65 cat >.gitignore <<-EOF
73 test_expect_success
'1b: pre-add all' '
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
84 test_expect_success
'1c: pre-add dir all' '
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
95 test_expect_success
'1d: post-add tracked' '
98 local parent_dir="$(pwd)" &&
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
107 sort actual-tracked-unsorted >actual-tracked &&
108 sort expect-tracked-unsorted >expect-tracked &&
109 test_cmp expect-tracked actual-tracked
113 test_expect_success
'1e: post-add untracked' '
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
124 test_expect_success
'2a: setup--set git-dir' '
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 &&
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 &&
141 cat >expect-tracked-unsorted <<-EOF &&
143 repo/inside-tracked/file
146 cat >expect-untracked-unsorted <<-EOF &&
148 repo/inside-untracked/file
153 cat >expect-all-dir-unsorted <<-EOF &&
158 cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted &&
160 cat >.gitignore <<-EOF
168 test_expect_success
'2b: pre-add all' '
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
178 test_expect_success
'2c: pre-add dir all' '
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
188 test_expect_success
'2d: post-add tracked' '
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
200 test_expect_success
'2e: post-add untracked' '
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
210 test_expect_success
'3a: setup--add repo dir' '
214 test_create_repo repo &&
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 &&
222 cat >.gitignore <<-EOF &&
229 cat >expect-tracked-unsorted <<-EOF &&
231 repo/inside-tracked/file
234 cat >expect-ignored-unsorted <<-EOF
238 actual-ignored-unsorted
239 expect-ignored-unsorted
240 expect-tracked-unsorted
245 test_expect_success
'3b: ignored' '
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
255 test_expect_success
'3c: add repo' '
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