Re: [PATCH] t3920: don't ignore errors of more than one command with `|| true`
- From
René Scharfe <l.s.r@web.de>
- Date
- Nov 21, 2022, 22:56 UTC
- Message-ID
- <eed47577-1e47-2fbb-6344-fd4ae324f6b6@web.de>
- In-Reply-To
- <febcfb0a-c410-fb71-cff9-92acfcb269e2@kdbg.org>
Am 21.11.22 um 18:58 schrieb Johannes Sixt:
Show 5 quoted lines
> It is customary to write `A || true` to ignore a potential error exit of > command A. But when we have a sequence `A && B && C || true && D`, then > a failure of any of A, B, or C skips to D right away. This is not > intended here. Turn the command whose failure is to be ignored into a > compound command to ensure it is the only one that is allowed to fail.
Good catch!
Show 12 quoted lines
> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
> ---
> t/t3920-crlf-messages.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/t/t3920-crlf-messages.sh b/t/t3920-crlf-messages.sh
> index 4c661d4d54..a58522c163 100755
> --- a/t/t3920-crlf-messages.sh
> +++ b/t/t3920-crlf-messages.sh
> @@ -12,7 +12,7 @@ create_crlf_ref () {
> cat >.crlf-orig-$branch.txt &&
> cat .crlf-orig-$branch.txt | append_cr >.crlf-message-$branch.txt &&Useless use of cat.
> grep 'Subject' .crlf-orig-$branch.txt | tr '\n' ' ' | sed 's/[ ]*$//' | tr -d '\n' >.crlf-subject-$branch.txt &&
My knee-jerk reaction to long lines like this is to pull out awk:
awk '/Subject/ {printf "%s", sep $0; sep = " "}' .crlf-orig-$branch.txt >.crlf-subject-$branch.txt &&This is not a faithful conversion because the original trims all spaces from the end of the subject for some reason. That would be:
awk '/Subject/ {s = s $0 " "} END {sub(/ *$/, "", s); printf "%s", s}' .crlf-orig-$branch.txt >.crlf-subject-$branch.txt &&> - grep 'Body' .crlf-message-$branch.txt >.crlf-body-$branch.txt || true &&
> + { grep 'Body' .crlf-message-$branch.txt >.crlf-body-$branch.txt || true; } &&OK, back on topic: Adding CRs explicitly instead of relying on grep to pass them through (which it doesn't on MinGW) also ignores the return value of grep as a side effect of the pipe:
grep 'Body' .crlf-orig-$branch.txt | append_cr >.crlf-body-$branch.txt &&
> LIB_CRLF_BRANCHES="${LIB_CRLF_BRANCHES} ${branch}" &&
> test_tick &&
> hash=$(git commit-tree HEAD^{tree} -p HEAD -F .crlf-message-${branch}.txt) &&