Re: [PATCH 08/12] t0008: silence error in subshell when using `grep -v`
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Apr 13, 2026, 17:28 UTC
- Message-ID
- <xmqqjyuaixcv.fsf@gitster.g>
- In-Reply-To
- <20260413-b4-pks-tests-with-set-e-v1-8-5b83763a0e84@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 6 quoted lines
> In t0008 we use `grep -v` in a subshell, but expect that this command > will sometimes not match anything. This would cause grep(1) to return an > error code, but given that we don't run with `set -e` we swallow this > error. > > We're about to enable `set -e`. Prepare for this by ignoring any errors.
It is curious that true is explicitly spelled out, unlike the earlier steps in the series that used ":" in "|| :".
Loss of extra spaces around the statement inside $() is a good touch.
Show 20 quoted lines
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> t/t0008-ignores.sh | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh
> index e716b5cdfa..1218005b54 100755
> --- a/t/t0008-ignores.sh
> +++ b/t/t0008-ignores.sh
> @@ -122,8 +122,8 @@ test_expect_success_multiple () {
> fi
> testname="$1" expect_all="$2" code="$3"
>
> - expect_verbose=$( echo "$expect_all" | grep -v '^:: ' )
> - expect=$( echo "$expect_verbose" | sed -e 's/.* //' )
> + expect_verbose=$(echo "$expect_all" | grep -v '^:: ' || true)
> + expect=$(echo "$expect_verbose" | sed -e 's/.* //')
>
> test_expect_success $prereq "$testname${no_index_opt:+ with $no_index_opt}" '
> expect "$expect" &&