1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-25 04:16:09 +02:00
git/t/lib-parallel-checkout.sh
Matheus Tavares 11d14dee43 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>
2022-07-14 10:19:27 -07:00

50 lines
1.2 KiB
Bash

# Helpers for tests invoking parallel-checkout
# Parallel checkout tests need full control of the number of workers
unset GIT_TEST_CHECKOUT_WORKERS
set_checkout_config () {
if test $# -ne 2
then
BUG "usage: set_checkout_config <workers> <threshold>"
fi &&
test_config_global checkout.workers $1 &&
test_config_global checkout.thresholdForParallelism $2
}
# Run "${@:2}" and check that $1 checkout workers were used
test_checkout_workers () {
if test $# -lt 2
then
BUG "too few arguments to test_checkout_workers"
fi &&
local expected_workers=$1 &&
shift &&
local trace_file=trace-test-checkout-workers &&
rm -f "$trace_file" &&
(
GIT_TRACE2="$(pwd)/$trace_file" &&
export GIT_TRACE2 &&
"$@" 2>&8
) &&
local workers="$(grep "child_start\[..*\] git checkout--worker" "$trace_file" | wc -l)" &&
test $workers -eq $expected_workers &&
rm "$trace_file"
} 8>&2 2>&4
# Verify that both the working tree and the index were created correctly
verify_checkout () {
if test $# -ne 1
then
BUG "usage: verify_checkout <repository path>"
fi &&
git -C "$1" diff-index --ignore-submodules=none --exit-code HEAD -- &&
git -C "$1" status --porcelain >"$1".status &&
test_must_be_empty "$1".status
}