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
12 .
"$TEST_DIRECTORY/lib-parallel-checkout.sh"
14 # Test parallel-checkout with a branch switch containing a variety of file
15 # creations, deletions, and modifications, involving different entry types.
16 # The branches B1 and B2 have the following paths:
22 # c/c (file) c (symlink)
23 # d (symlink) d/d (file)
25 # e/e (file) e (submodule)
26 # f (submodule) f/f (file)
28 # g (submodule) g (symlink)
29 # h (symlink) h (submodule)
31 # Additionally, the following paths are present on both branches, but with
35 # j (symlink) j (symlink)
36 # k (submodule) k (submodule)
38 # And the following paths are only present in one of the branches:
43 test_expect_success
'setup repo for checkout with various types of changes' '
44 test_config_global protocol.file.allow always &&
71 git submodule add ../sub f &&
72 git submodule add ../sub g &&
77 git submodule add -b B1 ../sub k &&
85 git rm -rf :^.gitmodules :^k &&
91 git submodule add ../sub e &&
94 git submodule add ../sub h &&
98 git -C k checkout B2 &&
105 git checkout --recurse-submodules B1
109 for mode
in sequential parallel sequential-fallback
112 sequential
) workers
=1 threshold
=0 expected_workers
=0 ;;
113 parallel
) workers
=2 threshold
=0 expected_workers
=2 ;;
114 sequential-fallback
) workers
=2 threshold
=100 expected_workers
=0 ;;
117 test_expect_success
"$mode checkout" '
118 repo=various_$mode &&
119 cp -R -P various $repo &&
121 # The just copied files have more recent timestamps than their
122 # associated index entries. So refresh the cached timestamps
123 # to avoid an "entry not up-to-date" error from `git checkout`.
124 # We only have to do this for the submodules as `git checkout`
125 # will already refresh the superproject index before performing
126 # the up-to-date check.
128 git -C $repo submodule foreach "git update-index --refresh" &&
130 set_checkout_config $workers $threshold &&
131 test_checkout_workers $expected_workers \
132 git -C $repo checkout --recurse-submodules B2 &&
133 verify_checkout $repo
137 for mode
in parallel sequential-fallback
140 parallel
) workers
=2 threshold
=0 expected_workers
=2 ;;
141 sequential-fallback
) workers
=2 threshold
=100 expected_workers
=0 ;;
144 test_expect_success
"$mode checkout on clone" '
145 test_config_global protocol.file.allow always &&
146 repo=various_${mode}_clone &&
147 set_checkout_config $workers $threshold &&
148 test_checkout_workers $expected_workers \
149 git clone --recurse-submodules --branch B2 various $repo &&
150 verify_checkout $repo
154 # Just to be paranoid, actually compare the working trees' contents directly.
155 test_expect_success
'compare the working trees' '
156 rm -rf various_*/.git &&
157 rm -rf various_*/*/.git &&
159 # We use `git diff` instead of `diff -r` because the latter would
160 # follow symlinks, and not all `diff` implementations support the
161 # `--no-dereference` option.
163 git diff --no-index various_sequential various_parallel &&
164 git diff --no-index various_sequential various_parallel_clone &&
165 git diff --no-index various_sequential various_sequential-fallback &&
166 git diff --no-index various_sequential various_sequential-fallback_clone
169 # Currently, each submodule is checked out in a separated child process, but
170 # these subprocesses must also be able to use parallel checkout workers to
171 # write the submodules' entries.
172 test_expect_success
'submodules can use parallel checkout' '
173 set_checkout_config 2 0 &&
178 test_commit -C sub A &&
179 test_commit -C sub B &&
180 git submodule add ./sub &&
183 test_checkout_workers 2 git checkout --recurse-submodules .
187 test_expect_success
'parallel checkout respects --[no]-force' '
188 set_checkout_config 2 0 &&
200 # We expect 0 workers because there is nothing to be done
201 test_checkout_workers 0 git checkout HEAD &&
202 test_path_is_file D &&
206 test_checkout_workers 2 git checkout --force HEAD &&
207 test_path_is_dir D &&
213 test_expect_success SYMLINKS
'parallel checkout checks for symlinks in leading dirs' '
214 set_checkout_config 2 0 &&
219 # Commit 2 files to have enough work for 2 parallel workers
225 test_checkout_workers 2 git checkout --force HEAD &&
232 # This test is here (and not in e.g. t2022-checkout-paths.sh), because we
233 # check the final report including sequential, parallel, and delayed entries
234 # all at the same time. So we must have finer control of the parallel checkout
236 test_expect_success
'"git checkout ." report should not include failed entries' '
237 test_config_global filter.delay.process \
238 "test-tool rot13-filter --always-delay --log=delayed.log clean smudge delay" &&
239 test_config_global filter.delay.required true &&
240 test_config_global filter.cat.clean cat &&
241 test_config_global filter.cat.smudge cat &&
242 test_config_global filter.cat.required true &&
244 set_checkout_config 2 0 &&
245 git init failed_entries &&
248 cat >.gitattributes <<-EOF &&
250 parallel-ineligible* filter=cat
252 echo a >missing-delay.a &&
253 echo a >parallel-ineligible.a &&
254 echo a >parallel-eligible.a &&
255 echo b >success-delay.b &&
256 echo b >parallel-ineligible.b &&
257 echo b >parallel-eligible.b &&
259 git commit -m files &&
261 a_blob="$(git rev-parse :parallel-ineligible.a)" &&
262 rm .git/objects/$(test_oid_to_path $a_blob) &&
265 test_checkout_workers 2 test_must_fail git checkout . 2>err &&
267 # All *.b entries should succeed and all *.a entries should fail:
268 # - missing-delay.a: the delay filter will drop this path
269 # - parallel-*.a: the blob will be missing
271 grep "Updated 3 paths from the index" err &&
272 test_stdout_line_count = 3 ls *.b &&