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>

Philippe Blain committed Oct 21, 2022 at 15:13 UTC 455f0adf5709e24712bff725005ff1a59508a054
1 file changed +8 -8
t/test-lib-functions.sh
+8 -8
@@ -273,13 +273,13 @@ debug () {
273 # <file>, <contents>, and <tag> all default to <message>.
274
275 test_commit () {
276 - notick= &&
277 - echo=echo &&
278 - append= &&
279 - author= &&
280 - signoff= &&
281 - indir= &&
282 - tag=light &&
276 + local notick= &&
277 + local echo=echo &&
278 + local append= &&
279 + local author= &&
280 + local signoff= &&
281 + local indir= &&
282 + local tag=light &&
283 while test $# != 0
284 do
285 case "$1" in
@@ -322,7 +322,7 @@ test_commit () {
322 shift
323 done &&
324 indir=${indir:+"$indir"/} &&
325 - file=${2:-"$1.t"} &&
325 + local file=${2:-"$1.t"} &&
326 if test -n "$append"
327 then
328 $echo "${3-$1}" >>"$indir$file"