Skip to content

Commit 6cf8d96

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5144219 commit 6cf8d96

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

t/t1403-show-ref.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77
. ./test-lib.sh
88

99
test_expect_success setup '
10-
test_commit A &&
11-
git tag -f -a -m "annotated A" A &&
10+
test_commit --annotate A &&
1211
git checkout -b side &&
13-
test_commit B &&
14-
git tag -f -a -m "annotated B" B &&
12+
test_commit --annotate B &&
1513
git checkout main &&
1614
test_commit C &&
1715
git branch B A^0

t/test-lib-functions.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ debug () {
179179
# Invoke "git commit" with --author <author>
180180
# --no-tag
181181
# 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.
182186
#
183187
# This will commit a file with the given contents and the given commit
184188
# message, and tag the resulting commit with the given tag name.
@@ -191,7 +195,7 @@ test_commit () {
191195
author= &&
192196
signoff= &&
193197
indir= &&
194-
no_tag= &&
198+
tag=light &&
195199
while test $# != 0
196200
do
197201
case "$1" in
@@ -219,7 +223,10 @@ test_commit () {
219223
shift
220224
;;
221225
--no-tag)
222-
no_tag=yes
226+
tag=none
227+
;;
228+
--annotate)
229+
tag=annotate
223230
;;
224231
*)
225232
break
@@ -243,10 +250,20 @@ test_commit () {
243250
git ${indir:+ -C "$indir"} commit \
244251
${author:+ --author "$author"} \
245252
$signoff -m "$1" &&
246-
if test -z "$no_tag"
247-
then
253+
case "$tag" in
254+
none)
255+
;;
256+
light)
248257
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
250267
}
251268

252269
# Call test_merge with the arguments "<message> <commit>", where <commit>

0 commit comments

Comments
 (0)