t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t2080-parallel-checkout-basics.sh
blob59e5570cb2d52298ba1c1045d2baef025fd86baf
1 #!/bin/sh
3 test_description='parallel-checkout basics
5 Ensure that parallel-checkout basically works on clone and checkout, spawning
6 the required number of workers and correctly populating both the index and the
7 working tree.
10 TEST_NO_CREATE_REPO=1
11 TEST_PASSES_SANITIZE_LEAK=true
12 . ./test-lib.sh
13 . "$TEST_DIRECTORY/lib-parallel-checkout.sh"
15 # Test parallel-checkout with a branch switch containing a variety of file
16 # creations, deletions, and modifications, involving different entry types.
17 # The branches B1 and B2 have the following paths:
19 # B1 B2
20 # a/a (file) a (file)
21 # b (file) b/b (file)
23 # c/c (file) c (symlink)
24 # d (symlink) d/d (file)
26 # e/e (file) e (submodule)
27 # f (submodule) f/f (file)
29 # g (submodule) g (symlink)
30 # h (symlink) h (submodule)
32 # Additionally, the following paths are present on both branches, but with
33 # different contents:
35 # i (file) i (file)
36 # j (symlink) j (symlink)
37 # k (submodule) k (submodule)
39 # And the following paths are only present in one of the branches:
41 # l/l (file) -
42 # - m/m (file)
44 test_expect_success 'setup repo for checkout with various types of changes' '
45 test_config_global protocol.file.allow always &&
47 git init sub &&
49 cd sub &&
50 git checkout -b B2 &&
51 echo B2 >file &&
52 git add file &&
53 git commit -m file &&
55 git checkout -b B1 &&
56 echo B1 >file &&
57 git add file &&
58 git commit -m file
59 ) &&
61 git init various &&
63 cd various &&
65 git checkout -b B1 &&
66 mkdir a c e &&
67 echo a/a >a/a &&
68 echo b >b &&
69 echo c/c >c/c &&
70 test_ln_s_add c d &&
71 echo e/e >e/e &&
72 git submodule add ../sub f &&
73 git submodule add ../sub g &&
74 test_ln_s_add c h &&
76 echo "B1 i" >i &&
77 test_ln_s_add c j &&
78 git submodule add -b B1 ../sub k &&
79 mkdir l &&
80 echo l/l >l/l &&
82 git add . &&
83 git commit -m B1 &&
85 git checkout -b B2 &&
86 git rm -rf :^.gitmodules :^k &&
87 mkdir b d f &&
88 echo a >a &&
89 echo b/b >b/b &&
90 test_ln_s_add b c &&
91 echo d/d >d/d &&
92 git submodule add ../sub e &&
93 echo f/f >f/f &&
94 test_ln_s_add b g &&
95 git submodule add ../sub h &&
97 echo "B2 i" >i &&
98 test_ln_s_add b j &&
99 git -C k checkout B2 &&
100 mkdir m &&
101 echo m/m >m/m &&
103 git add . &&
104 git commit -m B2 &&
106 git checkout --recurse-submodules B1
110 for mode in sequential parallel sequential-fallback
112 case $mode in
113 sequential) workers=1 threshold=0 expected_workers=0 ;;
114 parallel) workers=2 threshold=0 expected_workers=2 ;;
115 sequential-fallback) workers=2 threshold=100 expected_workers=0 ;;
116 esac
118 test_expect_success "$mode checkout" '
119 repo=various_$mode &&
120 cp -R -P various $repo &&
122 # The just copied files have more recent timestamps than their
123 # associated index entries. So refresh the cached timestamps
124 # to avoid an "entry not up-to-date" error from `git checkout`.
125 # We only have to do this for the submodules as `git checkout`
126 # will already refresh the superproject index before performing
127 # the up-to-date check.
129 git -C $repo submodule foreach "git update-index --refresh" &&
131 set_checkout_config $workers $threshold &&
132 test_checkout_workers $expected_workers \
133 git -C $repo checkout --recurse-submodules B2 &&
134 verify_checkout $repo
136 done
138 for mode in parallel sequential-fallback
140 case $mode in
141 parallel) workers=2 threshold=0 expected_workers=2 ;;
142 sequential-fallback) workers=2 threshold=100 expected_workers=0 ;;
143 esac
145 test_expect_success "$mode checkout on clone" '
146 test_config_global protocol.file.allow always &&
147 repo=various_${mode}_clone &&
148 set_checkout_config $workers $threshold &&
149 test_checkout_workers $expected_workers \
150 git clone --recurse-submodules --branch B2 various $repo &&
151 verify_checkout $repo
153 done
155 # Just to be paranoid, actually compare the working trees' contents directly.
156 test_expect_success 'compare the working trees' '
157 rm -rf various_*/.git &&
158 rm -rf various_*/*/.git &&
160 # We use `git diff` instead of `diff -r` because the latter would
161 # follow symlinks, and not all `diff` implementations support the
162 # `--no-dereference` option.
164 git diff --no-index various_sequential various_parallel &&
165 git diff --no-index various_sequential various_parallel_clone &&
166 git diff --no-index various_sequential various_sequential-fallback &&
167 git diff --no-index various_sequential various_sequential-fallback_clone
170 # Currently, each submodule is checked out in a separated child process, but
171 # these subprocesses must also be able to use parallel checkout workers to
172 # write the submodules' entries.
173 test_expect_success 'submodules can use parallel checkout' '
174 set_checkout_config 2 0 &&
175 git init super &&
177 cd super &&
178 git init sub &&
179 test_commit -C sub A &&
180 test_commit -C sub B &&
181 git submodule add ./sub &&
182 git commit -m sub &&
183 rm sub/* &&
184 test_checkout_workers 2 git checkout --recurse-submodules .
188 test_expect_success 'parallel checkout respects --[no]-force' '
189 set_checkout_config 2 0 &&
190 git init dirty &&
192 cd dirty &&
193 mkdir D &&
194 test_commit D/F &&
195 test_commit F &&
197 rm -rf D &&
198 echo changed >D &&
199 echo changed >F.t &&
201 # We expect 0 workers because there is nothing to be done
202 test_checkout_workers 0 git checkout HEAD &&
203 test_path_is_file D &&
204 grep changed D &&
205 grep changed F.t &&
207 test_checkout_workers 2 git checkout --force HEAD &&
208 test_path_is_dir D &&
209 grep D/F D/F.t &&
210 grep F F.t
214 test_expect_success SYMLINKS 'parallel checkout checks for symlinks in leading dirs' '
215 set_checkout_config 2 0 &&
216 git init symlinks &&
218 cd symlinks &&
219 mkdir D untracked &&
220 # Commit 2 files to have enough work for 2 parallel workers
221 test_commit D/A &&
222 test_commit D/B &&
223 rm -rf D &&
224 ln -s untracked D &&
226 test_checkout_workers 2 git checkout --force HEAD &&
227 ! test -h D &&
228 grep D/A D/A.t &&
229 grep D/B D/B.t
233 # This test is here (and not in e.g. t2022-checkout-paths.sh), because we
234 # check the final report including sequential, parallel, and delayed entries
235 # all at the same time. So we must have finer control of the parallel checkout
236 # variables.
237 test_expect_success '"git checkout ." report should not include failed entries' '
238 test_config_global filter.delay.process \
239 "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" &&
240 test_config_global filter.delay.required true &&
241 test_config_global filter.cat.clean cat &&
242 test_config_global filter.cat.smudge cat &&
243 test_config_global filter.cat.required true &&
245 set_checkout_config 2 0 &&
246 git init failed_entries &&
248 cd failed_entries &&
249 cat >.gitattributes <<-EOF &&
250 *delay* filter=delay
251 parallel-ineligible* filter=cat
253 echo a >missing-delay.a &&
254 echo a >parallel-ineligible.a &&
255 echo a >parallel-eligible.a &&
256 echo b >success-delay.b &&
257 echo b >parallel-ineligible.b &&
258 echo b >parallel-eligible.b &&
259 git add -A &&
260 git commit -m files &&
262 a_blob="$(git rev-parse :parallel-ineligible.a)" &&
263 rm .git/objects/$(test_oid_to_path $a_blob) &&
264 rm *.a *.b &&
266 test_checkout_workers 2 test_must_fail git checkout . 2>err &&
268 # All *.b entries should succeed and all *.a entries should fail:
269 # - missing-delay.a: the delay filter will drop this path
270 # - parallel-*.a: the blob will be missing
272 grep "Updated 3 paths from the index" err &&
273 test_stdout_line_count = 3 ls *.b &&
274 ! ls *.a
278 test_done