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
11 TEST_PASSES_SANITIZE_LEAK
=true
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:
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
36 # j (symlink) j (symlink)
37 # k (submodule) k (submodule)
39 # And the following paths are only present in one of the branches:
44 test_expect_success
'setup repo for checkout with various types of changes' '
45 test_config_global protocol.file.allow always &&
72 git submodule add ../sub f &&
73 git submodule add ../sub g &&
78 git submodule add -b B1 ../sub k &&
86 git rm -rf :^.gitmodules :^k &&
92 git submodule add ../sub e &&
95 git submodule add ../sub h &&
99 git -C k checkout B2 &&
106 git checkout --recurse-submodules B1
110 for mode
in sequential parallel sequential-fallback
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 ;;
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
138 for mode
in parallel sequential-fallback
141 parallel
) workers
=2 threshold
=0 expected_workers
=2 ;;
142 sequential-fallback
) workers
=2 threshold
=100 expected_workers
=0 ;;
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
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 &&
179 test_commit -C sub A &&
180 test_commit -C sub B &&
181 git submodule add ./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 &&
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 &&
207 test_checkout_workers 2 git checkout --force HEAD &&
208 test_path_is_dir D &&
214 test_expect_success SYMLINKS
'parallel checkout checks for symlinks in leading dirs' '
215 set_checkout_config 2 0 &&
220 # Commit 2 files to have enough work for 2 parallel workers
226 test_checkout_workers 2 git checkout --force HEAD &&
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
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 &&
249 cat >.gitattributes <<-EOF &&
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 &&
260 git commit -m files &&
262 a_blob="$(git rev-parse :parallel-ineligible.a)" &&
263 rm .git/objects/$(test_oid_to_path $a_blob) &&
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 &&