t / t3800-mktag.shon commit Merge branch 'jc/maint-checkout-fix' (11bd3dd)
   1#!/bin/sh
   2#
   3#
   4
   5test_description='git mktag: tag object verify test'
   6
   7. ./test-lib.sh
   8
   9###########################################################
  10# check the tag.sig file, expecting verify_tag() to fail,
  11# and checking that the error message matches the pattern
  12# given in the expect.pat file.
  13
  14check_verify_failure () {
  15        expect="$2"
  16        test_expect_success "$1" '
  17                ( test_must_fail git mktag <tag.sig 2>message ) &&
  18                grep "$expect" message
  19        '
  20}
  21
  22###########################################################
  23# first create a commit, so we have a valid object/type
  24# for the tag.
  25echo Hello >A
  26git update-index --add A
  27git commit -m "Initial commit"
  28head=$(git rev-parse --verify HEAD)
  29
  30############################################################
  31#  1. length check
  32
  33cat >tag.sig <<EOF
  34too short for a tag
  35EOF
  36
  37check_verify_failure 'Tag object length check' \
  38        '^error: .*size wrong.*$'
  39
  40############################################################
  41#  2. object line label check
  42
  43cat >tag.sig <<EOF
  44xxxxxx 139e9b33986b1c2670fff52c5067603117b3e895
  45type tag
  46tag mytag
  47tagger . <> 0 +0000
  48
  49EOF
  50
  51check_verify_failure '"object" line label check' '^error: char0: .*"object "$'
  52
  53############################################################
  54#  3. object line SHA1 check
  55
  56cat >tag.sig <<EOF
  57object zz9e9b33986b1c2670fff52c5067603117b3e895
  58type tag
  59tag mytag
  60tagger . <> 0 +0000
  61
  62EOF
  63
  64check_verify_failure '"object" line SHA1 check' '^error: char7: .*SHA1 hash$'
  65
  66############################################################
  67#  4. type line label check
  68
  69cat >tag.sig <<EOF
  70object 779e9b33986b1c2670fff52c5067603117b3e895
  71xxxx tag
  72tag mytag
  73tagger . <> 0 +0000
  74
  75EOF
  76
  77check_verify_failure '"type" line label check' '^error: char47: .*"\\ntype "$'
  78
  79############################################################
  80#  5. type line eol check
  81
  82echo "object 779e9b33986b1c2670fff52c5067603117b3e895" >tag.sig
  83printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
  84
  85check_verify_failure '"type" line eol check' '^error: char48: .*"\\n"$'
  86
  87############################################################
  88#  6. tag line label check #1
  89
  90cat >tag.sig <<EOF
  91object 779e9b33986b1c2670fff52c5067603117b3e895
  92type tag
  93xxx mytag
  94tagger . <> 0 +0000
  95
  96EOF
  97
  98check_verify_failure '"tag" line label check #1' \
  99        '^error: char57: no "tag " found$'
 100
 101############################################################
 102#  7. tag line label check #2
 103
 104cat >tag.sig <<EOF
 105object 779e9b33986b1c2670fff52c5067603117b3e895
 106type taggggggggggggggggggggggggggggggg
 107tag
 108EOF
 109
 110check_verify_failure '"tag" line label check #2' \
 111        '^error: char87: no "tag " found$'
 112
 113############################################################
 114#  8. type line type-name length check
 115
 116cat >tag.sig <<EOF
 117object 779e9b33986b1c2670fff52c5067603117b3e895
 118type taggggggggggggggggggggggggggggggg
 119tag mytag
 120EOF
 121
 122check_verify_failure '"type" line type-name length check' \
 123        '^error: char53: type too long$'
 124
 125############################################################
 126#  9. verify object (SHA1/type) check
 127
 128cat >tag.sig <<EOF
 129object 779e9b33986b1c2670fff52c5067603117b3e895
 130type tagggg
 131tag mytag
 132tagger . <> 0 +0000
 133
 134EOF
 135
 136check_verify_failure 'verify object (SHA1/type) check' \
 137        '^error: char7: could not verify object.*$'
 138
 139############################################################
 140# 10. verify tag-name check
 141
 142cat >tag.sig <<EOF
 143object $head
 144type commit
 145tag my  tag
 146tagger . <> 0 +0000
 147
 148EOF
 149
 150check_verify_failure 'verify tag-name check' \
 151        '^error: char67: could not verify tag name$'
 152
 153############################################################
 154# 11. tagger line label check #1
 155
 156cat >tag.sig <<EOF
 157object $head
 158type commit
 159tag mytag
 160
 161This is filler
 162EOF
 163
 164check_verify_failure '"tagger" line label check #1' \
 165        '^error: char70: could not find "tagger "$'
 166
 167############################################################
 168# 12. tagger line label check #2
 169
 170cat >tag.sig <<EOF
 171object $head
 172type commit
 173tag mytag
 174tagger
 175
 176This is filler
 177EOF
 178
 179check_verify_failure '"tagger" line label check #2' \
 180        '^error: char70: could not find "tagger "$'
 181
 182############################################################
 183# 13. disallow missing tag author name
 184
 185cat >tag.sig <<EOF
 186object $head
 187type commit
 188tag mytag
 189tagger  <> 0 +0000
 190
 191This is filler
 192EOF
 193
 194check_verify_failure 'disallow missing tag author name' \
 195        '^error: char77: missing tagger name$'
 196
 197############################################################
 198# 14. disallow missing tag author name
 199
 200cat >tag.sig <<EOF
 201object $head
 202type commit
 203tag mytag
 204tagger T A Gger <
 205 > 0 +0000
 206
 207EOF
 208
 209check_verify_failure 'disallow malformed tagger' \
 210        '^error: char77: malformed tagger field$'
 211
 212############################################################
 213# 15. allow empty tag email
 214
 215cat >tag.sig <<EOF
 216object $head
 217type commit
 218tag mytag
 219tagger T A Gger <> 0 +0000
 220
 221EOF
 222
 223test_expect_success \
 224    'allow empty tag email' \
 225    'git mktag <tag.sig >.git/refs/tags/mytag 2>message'
 226
 227############################################################
 228# 16. disallow spaces in tag email
 229
 230cat >tag.sig <<EOF
 231object $head
 232type commit
 233tag mytag
 234tagger T A Gger <tag ger@example.com> 0 +0000
 235
 236EOF
 237
 238check_verify_failure 'disallow spaces in tag email' \
 239        '^error: char77: malformed tagger field$'
 240
 241############################################################
 242# 17. disallow missing tag timestamp
 243
 244tr '_' ' ' >tag.sig <<EOF
 245object $head
 246type commit
 247tag mytag
 248tagger T A Gger <tagger@example.com>__
 249
 250EOF
 251
 252check_verify_failure 'disallow missing tag timestamp' \
 253        '^error: char107: missing tag timestamp$'
 254
 255############################################################
 256# 18. detect invalid tag timestamp1
 257
 258cat >tag.sig <<EOF
 259object $head
 260type commit
 261tag mytag
 262tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
 263
 264EOF
 265
 266check_verify_failure 'detect invalid tag timestamp1' \
 267        '^error: char107: missing tag timestamp$'
 268
 269############################################################
 270# 19. detect invalid tag timestamp2
 271
 272cat >tag.sig <<EOF
 273object $head
 274type commit
 275tag mytag
 276tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
 277
 278EOF
 279
 280check_verify_failure 'detect invalid tag timestamp2' \
 281        '^error: char111: malformed tag timestamp$'
 282
 283############################################################
 284# 20. detect invalid tag timezone1
 285
 286cat >tag.sig <<EOF
 287object $head
 288type commit
 289tag mytag
 290tagger T A Gger <tagger@example.com> 1206478233 GMT
 291
 292EOF
 293
 294check_verify_failure 'detect invalid tag timezone1' \
 295        '^error: char118: malformed tag timezone$'
 296
 297############################################################
 298# 21. detect invalid tag timezone2
 299
 300cat >tag.sig <<EOF
 301object $head
 302type commit
 303tag mytag
 304tagger T A Gger <tagger@example.com> 1206478233 +  30
 305
 306EOF
 307
 308check_verify_failure 'detect invalid tag timezone2' \
 309        '^error: char118: malformed tag timezone$'
 310
 311############################################################
 312# 22. detect invalid tag timezone3
 313
 314cat >tag.sig <<EOF
 315object $head
 316type commit
 317tag mytag
 318tagger T A Gger <tagger@example.com> 1206478233 -1430
 319
 320EOF
 321
 322check_verify_failure 'detect invalid tag timezone3' \
 323        '^error: char118: malformed tag timezone$'
 324
 325############################################################
 326# 23. detect invalid header entry
 327
 328cat >tag.sig <<EOF
 329object $head
 330type commit
 331tag mytag
 332tagger T A Gger <tagger@example.com> 1206478233 -0500
 333this line should not be here
 334
 335EOF
 336
 337check_verify_failure 'detect invalid header entry' \
 338        '^error: char124: trailing garbage in tag header$'
 339
 340############################################################
 341# 24. create valid tag
 342
 343cat >tag.sig <<EOF
 344object $head
 345type commit
 346tag mytag
 347tagger T A Gger <tagger@example.com> 1206478233 -0500
 348
 349EOF
 350
 351test_expect_success \
 352    'create valid tag' \
 353    'git mktag <tag.sig >.git/refs/tags/mytag 2>message'
 354
 355############################################################
 356# 25. check mytag
 357
 358test_expect_success \
 359    'check mytag' \
 360    'git tag -l | grep mytag'
 361
 362
 363test_done