test-lib functions: add --author support to test_commit

Add support for --author to "test_commit". This will simplify some current and future tests, one of those is being changed here. Let's also line-wrap the "git commit" command invocation to make diffs that add subsequent options easier to add, as they'll only need to add a new option line. 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 999cfc4f45e90a2eafa9b170d0ab9f0f13cbddb8
2 files changed +12 -6
t/t7509-commit-authorship.sh
+2 -5
@@ -18,11 +18,8 @@ message_body () {
18 }
19
20 test_expect_success '-C option copies authorship and message' '
21 - echo "Initial" >foo &&
22 - git add foo &&
23 - test_tick &&
24 - git commit -m "Initial Commit" --author Frigate\ \<flying@over.world\> &&
25 - git tag Initial &&
21 + test_commit --author Frigate\ \<flying@over.world\> \
22 + "Initial Commit" foo Initial Initial &&
23 echo "Test 1" >>foo &&
24 test_tick &&
25 git commit -a -C Initial &&
t/test-lib-functions.sh
+10 -1
@@ -185,6 +185,8 @@ debug () {
185 # Do not call test_tick before making a commit
186 # --signoff
187 # Invoke "git commit" with --signoff
188 +# --author=<author>
189 +# Invoke "git commit" with --author=<author>
190 #
191 # This will commit a file with the given contents and the given commit
192 # message, and tag the resulting commit with the given tag name.
@@ -193,6 +195,7 @@ debug () {
195
196 test_commit () {
197 notick= &&
198 + author= &&
199 signoff= &&
200 indir= &&
201 while test $# != 0
@@ -201,6 +204,10 @@ test_commit () {
204 --notick)
205 notick=yes
206 ;;
207 + --author)
208 + author="$2"
209 + shift
210 + ;;
211 --signoff)
212 signoff="$1"
213 ;;
@@ -222,7 +229,9 @@ test_commit () {
229 then
230 test_tick
231 fi &&
225 - git ${indir:+ -C "$indir"} commit $signoff -m "$1" &&
232 + git ${indir:+ -C "$indir"} commit \
233 + ${author:+ --author "$author"} \
234 + $signoff -m "$1" &&
235 git ${indir:+ -C "$indir"} tag "${4:-$1}"
236 }
237