test-lib-functions: mark 'test_commit' variables as 'local'

Some variables in 'test_commit' have names that are common enough that
it is very likely that test authors might use them in a test. If they do
so and use 'test_commit' between setting such a variable and using it,
the variable value from 'test_commit' will leak back into the test and
most likely break it.

Prevent that by marking all variables in 'test_commit' as 'local'. This
allow a subsequent commit to use a 'tag' variable.

Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Philippe Blain 2022-10-21 15:13:31 +00:00 committed by Junio C Hamano
parent 1fc3c0ad40
commit 455f0adf57

View File

@ -273,13 +273,13 @@ debug () {
# <file>, <contents>, and <tag> all default to <message>. # <file>, <contents>, and <tag> all default to <message>.
test_commit () { test_commit () {
notick= && local notick= &&
echo=echo && local echo=echo &&
append= && local append= &&
author= && local author= &&
signoff= && local signoff= &&
indir= && local indir= &&
tag=light && local tag=light &&
while test $# != 0 while test $# != 0
do do
case "$1" in case "$1" in
@ -322,7 +322,7 @@ test_commit () {
shift shift
done && done &&
indir=${indir:+"$indir"/} && indir=${indir:+"$indir"/} &&
file=${2:-"$1.t"} && local file=${2:-"$1.t"} &&
if test -n "$append" if test -n "$append"
then then
$echo "${3-$1}" >>"$indir$file" $echo "${3-$1}" >>"$indir$file"