git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rubén Justo" <rjusto@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>
Subject: [PATCH v2 1/2] t3701: avoid one-shot export for shell functions
Date: Tue, 23 Jul 2024 02:42:10 +0200	[thread overview]
Message-ID: <af444f9c-7f40-4afa-98dc-0b503642b58c@gmail.com> (raw)
In-Reply-To: <7c9ec43d-f52f-49b7-b1f3-fe3c85554006@gmail.com>

The common construct:

    VAR=VAL command args

is a common way to set and export one-shot variables within the scope of
executing a "command".

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=

Note that POSIX is not specific about this behavior:

http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_01

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.

Signed-off-by: Rubén Justo <rjusto@gmail.com>
---
 t/t3701-add-interactive.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
index c60589cb94..1b8617e0c1 100755
--- a/t/t3701-add-interactive.sh
+++ b/t/t3701-add-interactive.sh
@@ -616,7 +616,11 @@ test_expect_success TTY 'P handles SIGPIPE when writing to pager' '
 	test_when_finished "rm -f huge_file; git reset" &&
 	printf "\n%2500000s" Y >huge_file &&
 	git add -N huge_file &&
-	test_write_lines P q | GIT_PAGER="head -n 1" test_terminal git add -p
+	test_write_lines P q | (
+		GIT_PAGER="head -n 1" &&
+		export GIT_PAGER &&
+		test_terminal git add -p
+	)
 '
 
 test_expect_success 'split hunk "add -p (edit)"' '
-- 
2.45.1

  reply	other threads:[~2024-07-23  0:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23  0:39 [PATCH v2 0/2] add-p P fixups Rubén Justo
2024-07-23  0:42 ` Rubén Justo [this message]
2024-07-23  0:42 ` [PATCH v2 2/2] pager: make wait_for_pager a no-op for "cat" Rubén Justo
2024-07-23  0:54 ` [PATCH v2 0/2] add-p P fixups Junio C Hamano
2024-07-23  9:15 ` Phillip Wood
2024-07-23 16:52   ` Junio C Hamano
2024-07-23 22:08   ` Rubén Justo
2024-07-24 15:21     ` phillip.wood123
2024-07-24 16:12       ` Rubén Justo
2024-07-25  9:45         ` Phillip Wood
2024-07-25 12:16           ` Rubén Justo
2024-07-25 13:42             ` [PATCH 0/4] squash fixups in rj/add-p-pager Rubén Justo
2024-07-25 13:44               ` [PATCH 1/4] add-patch: test for 'p' command Rubén Justo
2024-07-25 13:44               ` [PATCH 2/4] pager: do not close fd 2 unnecessarily Rubén Justo
2024-07-25 13:44               ` [PATCH 3/4] pager: introduce wait_for_pager Rubén Justo
2024-07-25 13:44               ` [PATCH 4/4] add-patch: render hunks through the pager Rubén Justo
2024-07-25 15:24           ` [PATCH v2 0/2] add-p P fixups Junio C Hamano
2024-07-25 16:41             ` Re* " Rubén Justo
2024-07-25 16:43               ` [PATCH 1/2] pager: introduce wait_for_pager Rubén Justo
2024-07-25 16:43               ` [PATCH 2/2] add-patch: render hunks through the pager Rubén Justo
2024-07-26 18:36                 ` Junio C Hamano
2024-07-27  1:40                   ` Junio C Hamano
2024-07-27 14:33                     ` Rubén Justo
2024-07-26 18:24               ` Re* [PATCH v2 0/2] add-p P fixups Junio C Hamano
2024-07-26 19:22                 ` Rubén Justo
2024-07-26 19:48                   ` Junio C Hamano
2024-07-26 20:16                     ` Rubén Justo
2024-07-28  9:11                       ` Rubén Justo
2024-07-29 18:45                         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af444f9c-7f40-4afa-98dc-0b503642b58c@gmail.com \
    --to=rjusto@gmail.com \
    --cc=43e045e5-4c92-4c5f-b183-d63c5b510023@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).