test-lib functions: add an --append option to test_commit

Add an --append option to test_commit to append <contents> to the <file> we're writing to. This simplifies a lot of test setup, as shown in some of the tests being changed here. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jan 12, 2021 at 21:17 UTC 3373518cc8bd0916581ccfd4a2ee9682d61a8874
2 files changed +20 -33
t/t4203-mailmap.sh
+7 -32
@@ -5,14 +5,8 @@ test_description='.mailmap configurations'
5 . ./test-lib.sh
6
7 test_expect_success 'setup commits and contacts file' '
8 - echo one >one &&
9 - git add one &&
10 - test_tick &&
11 - git commit -m initial &&
12 - echo two >>one &&
13 - git add one &&
14 - test_tick &&
15 - git commit --author "nick1 <bugs@company.xx>" -m second
8 + test_commit initial one one &&
9 + test_commit --author "nick1 <bugs@company.xx>" --append second one two
10 '
11
12 test_expect_success 'check-mailmap no arguments' '
@@ -436,30 +430,11 @@ test_expect_success 'Shortlog output (complex mapping)' '
430 Santa Claus <santa.claus@northpole.xx> <me@company.xx>
431 EOF
432
439 - echo three >>one &&
440 - git add one &&
441 - test_tick &&
442 - git commit --author "nick2 <bugs@company.xx>" -m third &&
443 -
444 - echo four >>one &&
445 - git add one &&
446 - test_tick &&
447 - git commit --author "nick2 <nick2@company.xx>" -m fourth &&
448 -
449 - echo five >>one &&
450 - git add one &&
451 - test_tick &&
452 - git commit --author "santa <me@company.xx>" -m fifth &&
453 -
454 - echo six >>one &&
455 - git add one &&
456 - test_tick &&
457 - git commit --author "claus <me@company.xx>" -m sixth &&
458 -
459 - echo seven >>one &&
460 - git add one &&
461 - test_tick &&
462 - git commit --author "CTO <cto@coompany.xx>" -m seventh &&
433 + test_commit --author "nick2 <bugs@company.xx>" --append third one three &&
434 + test_commit --author "nick2 <nick2@company.xx>" --append fourth one four &&
435 + test_commit --author "santa <me@company.xx>" --append fifth one five &&
436 + test_commit --author "claus <me@company.xx>" --append sixth one six &&
437 + test_commit --author "CTO <cto@coompany.xx>" --append seventh one seven &&
438
439 cat >expect <<-EOF &&
440 $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> (1):
t/test-lib-functions.sh
+13 -1
@@ -183,6 +183,9 @@ debug () {
183 # Run all git commands in directory <dir>
184 # --notick
185 # Do not call test_tick before making a commit
186 +# --append
187 +# Use "echo >>" instead of "echo >" when writing "<contents>" to
188 +# "<file>"
189 # --signoff
190 # Invoke "git commit" with --signoff
191 # --author=<author>
@@ -195,6 +198,7 @@ debug () {
198
199 test_commit () {
200 notick= &&
201 + append= &&
202 author= &&
203 signoff= &&
204 indir= &&
@@ -204,6 +208,9 @@ test_commit () {
208 --notick)
209 notick=yes
210 ;;
211 + --append)
212 + append=yes
213 + ;;
214 --author)
215 author="$2"
216 shift
@@ -223,7 +230,12 @@ test_commit () {
230 done &&
231 indir=${indir:+"$indir"/} &&
232 file=${2:-"$1.t"} &&
226 - echo "${3-$1}" > "$indir$file" &&
233 + if test -n "$append"
234 + then
235 + echo "${3-$1}" >>"$indir$file"
236 + else
237 + echo "${3-$1}" >"$indir$file"
238 + fi &&
239 git ${indir:+ -C "$indir"} add "$file" &&
240 if test -z "$notick"
241 then