checkout: show bug about failed entries being included in final report

After checkout, git usually reports how many entries were updated at that operation. However, because we count the entries too soon during the checkout process, we may actually include entries that do not get properly checked out in the end. This can lead to an inaccurate final report if the user expects it to show only the *successful* updates. This will be fixed in the next commit, but for now let's document it with a test that cover all checkout modes. Note that `test_checkout_workers` have to be slightly adjusted in order to use the construct `test_checkout_workers ... test_must_fail git checkout`. The function runs the command given to it with an assignment prefix to set the GIT_TRACE2 variable. However, this this assignment has an undefined behavior when the command is a shell function (like `test_must_fail`). As POSIX specifies: If the command name is a function that is not a standard utility implemented as a function, variable assignments shall affect the current execution environment during the execution of the function. It is unspecified: - Whether or not the variable assignments persist after the completion of the function - Whether or not the variables gain the export attribute during the execution of the function Thus, in order to make sure the GIT_TRACE2 value gets visible to the git command executed by `test_must_fail`, export the variable and run git in a subshell. [1]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html (Vol. 3: Shell and Utilities, Section 2.9.1: Simple Commands) Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matheus Tavares committed Jul 14, 2022 at 08:49 UTC 11d14dee43794581ca3a7a93f9a081de711845d4
2 files changed +53 -1
t/lib-parallel-checkout.sh
+5 -1
@@ -25,7 +25,11 @@ test_checkout_workers () {
25
26 local trace_file=trace-test-checkout-workers &&
27 rm -f "$trace_file" &&
28 - GIT_TRACE2="$(pwd)/$trace_file" "$@" 2>&8 &&
28 + (
29 + GIT_TRACE2="$(pwd)/$trace_file" &&
30 + export GIT_TRACE2 &&
31 + "$@" 2>&8
32 + ) &&
33
34 local workers="$(grep "child_start\[..*\] git checkout--worker" "$trace_file" | wc -l)" &&
35 test $workers -eq $expected_workers &&
t/t2080-parallel-checkout-basics.sh
+48
@@ -226,4 +226,52 @@ test_expect_success SYMLINKS 'parallel checkout checks for symlinks in leading d
226 )
227 '
228
229 +# This test is here (and not in e.g. t2022-checkout-paths.sh), because we
230 +# check the final report including sequential, parallel, and delayed entries
231 +# all at the same time. So we must have finer control of the parallel checkout
232 +# variables.
233 +test_expect_failure PERL '"git checkout ." report should not include failed entries' '
234 + write_script rot13-filter.pl "$PERL_PATH" \
235 + <"$TEST_DIRECTORY"/t0021/rot13-filter.pl &&
236 +
237 + test_config_global filter.delay.process \
238 + "\"$(pwd)/rot13-filter.pl\" --always-delay 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 &&
243 +
244 + set_checkout_config 2 0 &&
245 + git init failed_entries &&
246 + (
247 + cd failed_entries &&
248 + cat >.gitattributes <<-EOF &&
249 + *delay* filter=delay
250 + parallel-ineligible* filter=cat
251 + EOF
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 &&
258 + git add -A &&
259 + git commit -m files &&
260 +
261 + a_blob="$(git rev-parse :parallel-ineligible.a)" &&
262 + rm .git/objects/$(test_oid_to_path $a_blob) &&
263 + rm *.a *.b &&
264 +
265 + test_checkout_workers 2 test_must_fail git checkout . 2>err &&
266 +
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
270 + #
271 + grep "Updated 3 paths from the index" err &&
272 + test_stdout_line_count = 3 ls *.b &&
273 + ! ls *.a
274 + )
275 +'
276 +
277 test_done