commit-reach(repo_in_merge_bases_many): optionally expect missing commits
[git.git] / t / t2205-add-worktree-config.sh
blob98265ba1b495eb91df0fa60467ebf0ac932cf1b5
1 #!/bin/sh
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
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.
20 TEST_PASSES_SANITIZE_LEAK=true
21 . ./test-lib.sh
23 test_expect_success '1a: setup--config worktree' '
24 mkdir test1 &&
26 cd test1 &&
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 &&
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 &&
41 cat >expect-tracked-unsorted <<-EOF &&
42 ../file-tracked
43 ../outside-tracked/file
44 file-tracked
45 inside-tracked/file
46 EOF
48 cat >expect-untracked-unsorted <<-EOF &&
49 ../file-untracked
50 ../outside-untracked/file
51 file-untracked
52 inside-untracked/file
53 EOF
55 cat >expect-all-dir-unsorted <<-EOF &&
56 ../file-untracked
57 ../file-tracked
58 ../outside-untracked/
59 ../outside-tracked/
61 EOF
63 cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted &&
65 cat >.gitignore <<-EOF
66 .gitignore
67 actual-*
68 expect-*
69 EOF
73 test_expect_success '1b: pre-add all' '
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
84 test_expect_success '1c: pre-add dir all' '
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
95 test_expect_success '1d: post-add tracked' '
97 cd test1 &&
98 local parent_dir="$(pwd)" &&
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
113 test_expect_success '1e: post-add untracked' '
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
124 test_expect_success '2a: setup--set git-dir' '
125 mkdir test2 &&
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 &&
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 &&
142 repo/file-tracked
143 repo/inside-tracked/file
146 cat >expect-untracked-unsorted <<-EOF &&
147 repo/file-untracked
148 repo/inside-untracked/file
149 repo/repo-inside/
150 repo-outside/
153 cat >expect-all-dir-unsorted <<-EOF &&
154 repo/
155 repo-outside/
158 cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted &&
160 cat >.gitignore <<-EOF
161 .gitignore
162 actual-*
163 expect-*
168 test_expect_success '2b: pre-add all' '
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
178 test_expect_success '2c: pre-add dir all' '
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
188 test_expect_success '2d: post-add tracked' '
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
200 test_expect_success '2e: post-add untracked' '
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
210 test_expect_success '3a: setup--add repo dir' '
211 mkdir test3 &&
213 cd test3 &&
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 &&
223 .gitignore
224 actual-*
225 expect-*
226 *ignored
229 cat >expect-tracked-unsorted <<-EOF &&
230 repo/file-tracked
231 repo/inside-tracked/file
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
245 test_expect_success '3b: ignored' '
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
255 test_expect_success '3c: add repo' '
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
266 test_done