Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t3800-mktag.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t3800-mktag.sh` 586 lines ยท 12982 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # 4 5 test_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 14 check_verify_failure () { 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 err && 37 if test -z "$no_strict" 38 then 39 test_must_fail git mktag err2 && 40 test_cmp err err2 41 else 42 git mktag --no-strict expected && 91 git -C bad-tag for-each-ref "$tag_ref" >actual && 92 test_cmp expected actual && 93 94 test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)" 95 ' 96 97 test_expect_success "fast-export & fast-import: $subject" ' 98 # Make sure the earlier test created it for us 99 git rev-parse "$bad_tag" && 100 101 test_must_fail git -C bad-tag fast-export --all && 102 test_must_fail git -C bad-tag fast-export "$bad_tag" 103 ' 104 } 105 106 test_expect_mktag_success() { 107 test_expect_success "$1" ' 108 git hash-object -t tag -w --stdin expected && 109 git fsck --strict && 110 111 git mktag hash && 112 test_cmp expected hash && 113 test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" && 114 git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) && 115 git fsck --strict 116 ' 117 } 118 119 ########################################################### 120 # first create a commit, so we have a valid object/type 121 # for the tag. 122 test_expect_success 'setup' ' 123 test_commit A && 124 test_commit B && 125 head=$(git rev-parse --verify HEAD) && 126 head_parent=$(git rev-parse --verify HEAD~) && 127 tree=$(git rev-parse HEAD^{tree}) && 128 blob=$(git rev-parse --verify HEAD:B.t) 129 ' 130 131 test_expect_success 'basic usage' ' 132 cat >tag.sig <<-EOF && 133 object $head 134 type commit 135 tag mytag 136 tagger T A Gger `1206478233` -0500 137 EOF 138 git mktag tag.sig <tag.sig < 0 +0000 161 162 EOF 163 164 check_verify_failure '"object" line label check' '^error:.* missingObject:' 165 166 ############################################################ 167 # 3. object line hash check 168 169 cat >tag.sig < 0 +0000 174 175 EOF 176 177 check_verify_failure '"object" line check' '^error:.* badObjectSha1:' 178 179 ############################################################ 180 # 4. type line label check 181 182 cat >tag.sig < 0 +0000 187 188 EOF 189 190 check_verify_failure '"type" line label check' '^error:.* missingTypeEntry:' 191 192 ############################################################ 193 # 5. type line eol check 194 195 echo "object $head" >tag.sig 196 printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig 197 198 check_verify_failure '"type" line eol check' '^error:.* unterminatedHeader:' 199 200 ############################################################ 201 # 6. tag line label check #1 202 203 cat >tag.sig < 0 +0000 208 209 EOF 210 211 check_verify_failure '"tag" line label check #1' \ 212 '^error:.* missingTagEntry:' 213 214 ############################################################ 215 # 7. tag line label check #2 216 217 cat >tag.sig <tag.sig <tag.sig < 0 +0000 246 247 EOF 248 249 check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \ 250 '^fatal: could not read tagged object' \ 251 --fsck-obj-ok 252 253 cat >tag.sig < 0 +0000 258 259 EOF 260 261 check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \ 262 '^error:.* badType:' 263 264 cat >tag.sig < 0 +0000 269 270 EOF 271 272 check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \ 273 '^error:.* badType:' 274 275 cat >tag.sig < 0 +0000 280 281 EOF 282 283 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \ 284 '^fatal: object.*tagged as.*tree.*but is.*commit' \ 285 --fsck-obj-ok 286 287 ############################################################ 288 # 9.5. verify object (hash/type) check -- replacement 289 290 test_expect_success 'setup replacement of commit -> commit and tree -> blob' ' 291 git replace $head_parent $head && 292 git replace -f $tree $blob 293 ' 294 295 cat >tag.sig < 0 +0000 300 301 EOF 302 303 test_expect_mktag_success 'tag to a commit replaced by another commit' 304 305 cat >tag.sig < 0 +0000 310 311 EOF 312 313 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \ 314 '^fatal: object.*tagged as.*tree.*but is.*blob' \ 315 --fsck-obj-ok 316 317 ############################################################ 318 # 10. verify tag-name check 319 320 cat >tag.sig < 0 +0000 325 326 EOF 327 328 check_verify_failure 'verify tag-name check' \ 329 '^error:.* badTagName:' \ 330 --no-strict \ 331 --fsck-obj-ok 332 333 ############################################################ 334 # 11. tagger line label check #1 335 336 cat >tag.sig <tag.sig <tag.sig < 0 +0000 374 375 This is filler 376 EOF 377 378 test_expect_mktag_success 'allow missing tag author name' 379 380 ############################################################ 381 # 14. disallow missing tag author name 382 383 cat >tag.sig < 0 +0000 389 390 EOF 391 392 check_verify_failure 'disallow malformed tagger' \ 393 '^error:.* badEmail:' \ 394 --no-strict \ 395 --fsck-obj-ok 396 397 ############################################################ 398 # 15. allow empty tag email 399 400 cat >tag.sig < 0 +0000 405 406 EOF 407 408 test_expect_mktag_success 'allow empty tag email' 409 410 ############################################################ 411 # 16. allow spaces in tag email like fsck 412 413 cat >tag.sig < 0 +0000 418 419 EOF 420 421 test_expect_mktag_success 'allow spaces in tag email like fsck' 422 423 ############################################################ 424 # 17. disallow missing tag timestamp 425 426 tr '_' ' ' >tag.sig <__ 431 432 EOF 433 434 check_verify_failure 'disallow missing tag timestamp' \ 435 '^error:.* badDate:' 436 437 ############################################################ 438 # 18. detect invalid tag timestamp1 439 440 cat >tag.sig < Tue Mar 25 15:47:44 2008 445 446 EOF 447 448 check_verify_failure 'detect invalid tag timestamp1' \ 449 '^error:.* badDate:' 450 451 ############################################################ 452 # 19. detect invalid tag timestamp2 453 454 cat >tag.sig < 2008-03-31T12:20:15-0500 459 460 EOF 461 462 check_verify_failure 'detect invalid tag timestamp2' \ 463 '^error:.* badDate:' 464 465 ############################################################ 466 # 20. detect invalid tag timezone1 467 468 cat >tag.sig < `1206478233` GMT 473 474 EOF 475 476 check_verify_failure 'detect invalid tag timezone1' \ 477 '^error:.* badTimezone:' 478 479 ############################################################ 480 # 21. detect invalid tag timezone2 481 482 cat >tag.sig < `1206478233` + 30 487 488 EOF 489 490 check_verify_failure 'detect invalid tag timezone2' \ 491 '^error:.* badTimezone:' 492 493 ############################################################ 494 # 22. allow invalid tag timezone3 (the maximum is -1200/+1400) 495 496 cat >tag.sig < `1206478233` -1430 501 502 EOF 503 504 test_expect_mktag_success 'allow invalid tag timezone' 505 506 ############################################################ 507 # 23. detect invalid header entry 508 509 cat >tag.sig < `1206478233` -0500 514 this line should not be here 515 516 EOF 517 518 check_verify_failure 'detect invalid header entry' \ 519 '^error:.* extraHeaderEntry:' \ 520 --no-strict \ 521 --fsck-obj-ok 522 523 test_expect_success 'invalid header entry config & fsck' ' 524 test_must_fail git mktag err && 538 test_grep "warning .*extraHeaderEntry:" err && 539 test_must_fail git -c fsck.extraHeaderEntry=error 2>err fsck && 540 test_grep "error .* extraHeaderEntry:" err 541 ' 542 543 cat >tag.sig < `1206478233` -0500 548 549 550 this line comes after an extra newline 551 EOF 552 553 test_expect_mktag_success 'allow extra newlines at start of body' 554 555 cat >tag.sig < `1206478233` -0500 560 561 EOF 562 563 test_expect_mktag_success 'allow a blank line before an empty body (1)' 564 565 cat >tag.sig < `1206478233` -0500 570 EOF 571 572 test_expect_mktag_success 'allow no blank line before an empty body (2)' 573 574 ############################################################ 575 # 24. create valid tag 576 577 cat >tag.sig < `1206478233` -0500 582 EOF 583 584 test_expect_mktag_success 'create valid tag object' 585 586 test_done