Skip to content

Commit 4d9e7c1

Browse files
Denton-Lgitster
authored andcommitted
t3701: stop using env in force_color()
In a future patch, we plan on making the test_must_fail()-family of functions accept only git commands. Even though force_color() wraps an invocation of `env git`, test_must_fail() will not be able to figure this out since it will assume that force_color() is just some random function which is disallowed. Instead of using `env` in force_color() (which does not support shell functions), export the environment variables in a subshell. Write the invocation as `force_color test_must_fail git ...` since shell functions are now supported. Signed-off-by: Denton Liu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4a0fcf9 commit 4d9e7c1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

t/t3701-add-interactive.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ diff_cmp () {
3131
# indicates a dumb terminal, so we set that variable, too.
3232

3333
force_color () {
34-
env GIT_PAGER_IN_USE=true TERM=vt100 "$@"
34+
# The first element of $@ may be a shell function, as a result POSIX
35+
# does not guarantee that "one-shot assignment" will not persist after
36+
# the function call. Thus, we prevent these variables from escaping
37+
# this function's context with this subshell.
38+
(
39+
GIT_PAGER_IN_USE=true &&
40+
TERM=vt100 &&
41+
export GIT_PAGER_IN_USE TERM &&
42+
"$@"
43+
)
3544
}
3645

3746
test_expect_success 'setup (initial)' '
@@ -604,7 +613,7 @@ test_expect_success 'detect bogus diffFilter output' '
604613
echo content >test &&
605614
test_config interactive.diffFilter "sed 1d" &&
606615
printf y >y &&
607-
test_must_fail force_color git add -p <y
616+
force_color test_must_fail git add -p <y
608617
'
609618

610619
test_expect_success 'diff.algorithm is passed to `git diff-files`' '

0 commit comments

Comments
 (0)