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