@@ -12,15 +12,93 @@ test_description='git mktag: tag object verify test'
12
12
# given in the expect.pat file.
13
13
14
14
check_verify_failure () {
15
- test_expect_success " $1 " "
16
- test_must_fail git mktag <tag.sig 2>message &&
17
- grep '$2 ' message &&
18
- if test '$3 ' != '--no-strict'
15
+ subject=$1 &&
16
+ message=$2 &&
17
+ shift 2 &&
18
+
19
+ no_strict= &&
20
+ fsck_obj_ok= &&
21
+ no_strict= &&
22
+ while test $# ! = 0
23
+ do
24
+ case " $1 " in
25
+ --no-strict)
26
+ no_strict=yes
27
+ ;;
28
+ --fsck-obj-ok)
29
+ fsck_obj_ok=yes
30
+ ;;
31
+ esac &&
32
+ shift
33
+ done &&
34
+
35
+ test_expect_success " fail with [--[no-]strict]: $subject " '
36
+ test_must_fail git mktag <tag.sig 2>err &&
37
+ if test -z "$no_strict"
19
38
then
20
- test_must_fail git mktag --no-strict <tag.sig 2>message.no-strict &&
21
- grep '$2 ' message.no-strict
39
+ test_must_fail git mktag <tag.sig 2>err2 &&
40
+ test_cmp err err2
41
+ else
42
+ git mktag --no-strict <tag.sig
22
43
fi
23
- "
44
+ '
45
+
46
+ test_expect_success " setup: $subject " '
47
+ tag_ref=refs/tags/bad_tag &&
48
+
49
+ # Reset any leftover state from the last $subject
50
+ rm -rf bad-tag &&
51
+
52
+ git init --bare bad-tag &&
53
+ bad_tag=$(git -C bad-tag hash-object -t tag -w --stdin --literally <tag.sig)
54
+ '
55
+
56
+ test_expect_success " hash-object & fsck unreachable: $subject " '
57
+ if test -n "$fsck_obj_ok"
58
+ then
59
+ git -C bad-tag fsck
60
+ else
61
+ test_must_fail git -C bad-tag fsck
62
+ fi
63
+ '
64
+
65
+ test_expect_success " update-ref & fsck reachable: $subject " '
66
+ # Make sure the earlier test created it for us
67
+ git rev-parse "$bad_tag" &&
68
+
69
+ # The update-ref of the bad content will fail, do it
70
+ # anyway to see if it segfaults
71
+ test_might_fail git -C bad-tag update-ref "$tag_ref" "$bad_tag" &&
72
+
73
+ # Manually create the broken, we cannot do it with
74
+ # update-ref
75
+ echo "$bad_tag" >"bad-tag/$tag_ref" &&
76
+
77
+ # Unlike fsck-ing unreachable content above, this
78
+ # will always fail.
79
+ test_must_fail git -C bad-tag fsck
80
+ '
81
+
82
+ test_expect_success " for-each-ref: $subject " '
83
+ # Make sure the earlier test created it for us
84
+ git rev-parse "$bad_tag" &&
85
+
86
+ echo "$bad_tag" >"bad-tag/$tag_ref" &&
87
+
88
+ printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected &&
89
+ git -C bad-tag for-each-ref "$tag_ref" >actual &&
90
+ test_cmp expected actual &&
91
+
92
+ test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)"
93
+ '
94
+
95
+ test_expect_success " fast-export & fast-import: $subject " '
96
+ # Make sure the earlier test created it for us
97
+ git rev-parse "$bad_tag" &&
98
+
99
+ test_must_fail git -C bad-tag fast-export --all &&
100
+ test_must_fail git -C bad-tag fast-export "$bad_tag"
101
+ '
24
102
}
25
103
26
104
test_expect_mktag_success () {
@@ -167,7 +245,8 @@ tagger . <> 0 +0000
167
245
EOF
168
246
169
247
check_verify_failure ' verify object (hash/type) check -- correct type, nonexisting object' \
170
- ' ^fatal: could not read tagged object'
248
+ ' ^fatal: could not read tagged object' \
249
+ --fsck-obj-ok
171
250
172
251
cat > tag.sig << EOF
173
252
object $head
@@ -200,7 +279,8 @@ tagger . <> 0 +0000
200
279
EOF
201
280
202
281
check_verify_failure ' verify object (hash/type) check -- mismatched type, valid object' \
203
- ' ^fatal: object.*tagged as.*tree.*but is.*commit'
282
+ ' ^fatal: object.*tagged as.*tree.*but is.*commit' \
283
+ --fsck-obj-ok
204
284
205
285
# ###########################################################
206
286
# 9.5. verify object (hash/type) check -- replacement
@@ -229,7 +309,8 @@ tagger . <> 0 +0000
229
309
EOF
230
310
231
311
check_verify_failure ' verify object (hash/type) check -- mismatched type, valid object' \
232
- ' ^fatal: object.*tagged as.*tree.*but is.*blob'
312
+ ' ^fatal: object.*tagged as.*tree.*but is.*blob' \
313
+ --fsck-obj-ok
233
314
234
315
# ###########################################################
235
316
# 10. verify tag-name check
@@ -243,7 +324,9 @@ tagger . <> 0 +0000
243
324
EOF
244
325
245
326
check_verify_failure ' verify tag-name check' \
246
- ' ^error:.* badTagName:' ' --no-strict'
327
+ ' ^error:.* badTagName:' \
328
+ --no-strict \
329
+ --fsck-obj-ok
247
330
248
331
# ###########################################################
249
332
# 11. tagger line label check #1
@@ -257,7 +340,9 @@ This is filler
257
340
EOF
258
341
259
342
check_verify_failure ' "tagger" line label check #1' \
260
- ' ^error:.* missingTaggerEntry:' ' --no-strict'
343
+ ' ^error:.* missingTaggerEntry:' \
344
+ --no-strict \
345
+ --fsck-obj-ok
261
346
262
347
# ###########################################################
263
348
# 12. tagger line label check #2
@@ -272,7 +357,9 @@ This is filler
272
357
EOF
273
358
274
359
check_verify_failure ' "tagger" line label check #2' \
275
- ' ^error:.* missingTaggerEntry:' ' --no-strict'
360
+ ' ^error:.* missingTaggerEntry:' \
361
+ --no-strict \
362
+ --fsck-obj-ok
276
363
277
364
# ###########################################################
278
365
# 13. allow missing tag author name like fsck
@@ -301,7 +388,9 @@ tagger T A Gger <
301
388
EOF
302
389
303
390
check_verify_failure ' disallow malformed tagger' \
304
- ' ^error:.* badEmail:' ' --no-strict'
391
+ ' ^error:.* badEmail:' \
392
+ --no-strict \
393
+ --fsck-obj-ok
305
394
306
395
# ###########################################################
307
396
# 15. allow empty tag email
@@ -425,7 +514,9 @@ this line should not be here
425
514
EOF
426
515
427
516
check_verify_failure ' detect invalid header entry' \
428
- ' ^error:.* extraHeaderEntry:' ' --no-strict'
517
+ ' ^error:.* extraHeaderEntry:' \
518
+ --no-strict \
519
+ --fsck-obj-ok
429
520
430
521
test_expect_success ' invalid header entry config & fsck' '
431
522
test_must_fail git mktag <tag.sig &&
0 commit comments