Re: [PATCH 1/2] t3701: avoid one-shot export for shell functions
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 22, 2024, 23:57 UTC
- Message-ID
- <xmqqa5i96kvg.fsf@gitster.g>
- In-Reply-To
- <xmqqsew16lg9.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 32 quoted lines
> Rubén Justo <rjusto@gmail.com> writes:
>
>> The common construct:
>>
>> VAR=VAL command args
>>
>> it's a common way to define one-shot variables within the scope of
>> executing a "command".
>
> "it's a" -> "is a".
> "define" -> "set and export".
>
>> However, when "command" is a function which in turn executes the
>> "command", the behavior varies depending on the shell:
>>
>> ** Bash 5.2.21 **
>>
>> $ f () { bash -c 'echo A=$A'; }
>> $ A=1 f
>> A=1
>>
>> ** dash 0.5.12-9 **
>>
>> $ f () { bash -c 'echo A=$A'; }
>> $ A=1 f
>> A=1
>>
>> ** dash 0.5.10.2-6 **
>>
>> $ f () { bash -c 'echo A=$A'; }
>> $ A=1 f
>> A=Another thing. Let's insert a paragraph perhaps like this here.
Note that POSIX explicitly says the effect of this construct
used on a shell function is unspecified.Show 5 quoted lines
>> One of our CI jobs on GitHub Actions uses Ubuntu 20.04 running dash >> 0.5.10.2-6, so we failed the test t3701:51; the "git add -p" being >> tested did not get our custom GIT_PAGER, which broke the test. >> >> Work it around by explicitly exporting the variable in a subshell.
That way, we won't give a wrong impression that we can safely start using the construct in future once dash 0.5.10.2-6 goes away.