Re: [PATCH 11/12] t0610: fix non-portable variable assignment
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Apr 5, 2024, 16:44 UTC
- Message-ID
- <ZhAqamxWZNlMKxWJ@ncase>
- In-Reply-To
- <xmqqmsq7yezc.fsf@gitster.g>
On Fri, Apr 05, 2024 at 09:02:47AM -0700, Junio C Hamano wrote:
Show 25 quoted lines
> Patrick Steinhardt <ps@pks.im> writes:
>
> > test_expect_perms () {
> > local perms="$1"
> > local file="$2"
> > - local actual=$(ls -l "$file") &&
> > + local actual
> >
> > + actual=$(ls -l "$file") &&
>
> Isn't this the same as what ebee5580 (parallel-checkout: avoid dash
> local bug in tests, 2021-06-06) fixed?
>
> The rule for variable assignment is mishandled when local is
> involved by some shells.
>
> perms=$1
> file=$2
> actual=$(ls -l "$file")
>
> would be perfectly fine, and should be fine with "local" prefixed on
> these lines, but the last one with local without "" qround $(...)
> incorrectly makes the substitution subject to field splitting.
>
> I think the right fix should look rather like this, instead.Ah, interesting, thanks for the pointer! I'll send v2 of this series early next week.
Patrick
Show 21 quoted lines
> t/t0610-reftable-basics.sh | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git i/t/t0610-reftable-basics.sh w/t/t0610-reftable-basics.sh
> index 686781192e..894896933e 100755
> --- i/t/t0610-reftable-basics.sh
> +++ w/t/t0610-reftable-basics.sh
> @@ -81,9 +81,9 @@ test_expect_success 'init: reinitializing reftable with files backend fails' '
> '
>
> test_expect_perms () {
> - local perms="$1"
> - local file="$2"
> - local actual=$(ls -l "$file") &&
> + local perms="$1" &&
> + local file="$2" &&
> + local actual="$(ls -l "$file")" &&
>
> case "$actual" in
> $perms*)
>