test-lib functions: add an --annotated option to "test_commit"
Add an --annotated option to test_commit to create annotated tags. The tag will share the same message as the commit, and we'll call test_tick before creating it (unless --notick) is provided. There's quite a few tests that could be simplified with this construct. I've picked one to convert in this change as a demonstration. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
May 10, 2021 at 16:19 UTC
6cf8d96fa28668a62f05be5b276739c03c514581
2 files changed
+24
-9
t/t1403-show-ref.sh
+2
-4
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
. ./test-lib.sh
8
9
test_expect_success setup '
10
- test_commit A &&
11
- git tag -f -a -m "annotated A" A &&
10
+ test_commit --annotate A &&
11
git checkout -b side &&
13
- test_commit B &&
14
- git tag -f -a -m "annotated B" B &&
12
+ test_commit --annotate B &&
13
git checkout main &&
14
test_commit C &&
15
git branch B A^0
t/test-lib-functions.sh
+22
-5
@@ -179,6 +179,10 @@ debug () {
179
# Invoke "git commit" with --author <author>
180
# --no-tag
181
# Do not tag the resulting commit
182
+# --annotate
183
+# Create an annotated tag with "--annotate -m <message>". Calls
184
+# test_tick between making the commit and tag, unless --notick
185
+# is given.
186
#
187
# This will commit a file with the given contents and the given commit
188
# message, and tag the resulting commit with the given tag name.
@@ -191,7 +195,7 @@ test_commit () {
195
author= &&
196
signoff= &&
197
indir= &&
194
- no_tag= &&
198
+ tag=light &&
199
while test $# != 0
200
do
201
case "$1" in
@@ -219,7 +223,10 @@ test_commit () {
223
shift
224
;;
225
--no-tag)
222
- no_tag=yes
226
+ tag=none
227
+ ;;
228
+ --annotate)
229
+ tag=annotate
230
;;
231
*)
232
break
@@ -243,10 +250,20 @@ test_commit () {
250
git ${indir:+ -C "$indir"} commit \
251
${author:+ --author "$author"} \
252
$signoff -m "$1" &&
246
- if test -z "$no_tag"
247
- then
253
+ case "$tag" in
254
+ none)
255
+ ;;
256
+ light)
257
git ${indir:+ -C "$indir"} tag "${4:-$1}"
249
- fi
258
+ ;;
259
+ annotate)
260
+ if test -z "$notick"
261
+ then
262
+ test_tick
263
+ fi &&
264
+ git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
265
+ ;;
266
+ esac
267
}
268
269
# Call test_merge with the arguments "<message> <commit>", where <commit>