t / t6300-for-each-ref.shon commit fetch-pack: fix deepen shallow over smart http with no-done cap (ff62eca)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Andy Parkins
   4#
   5
   6test_description='for-each-ref test'
   7
   8. ./test-lib.sh
   9. "$TEST_DIRECTORY"/lib-gpg.sh
  10
  11# Mon Jul 3 15:18:43 2006 +0000
  12datestamp=1151939923
  13setdate_and_increment () {
  14    GIT_COMMITTER_DATE="$datestamp +0200"
  15    datestamp=$(expr "$datestamp" + 1)
  16    GIT_AUTHOR_DATE="$datestamp +0200"
  17    datestamp=$(expr "$datestamp" + 1)
  18    export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
  19}
  20
  21test_expect_success setup '
  22        setdate_and_increment &&
  23        echo "Using $datestamp" > one &&
  24        git add one &&
  25        git commit -m "Initial" &&
  26        setdate_and_increment &&
  27        git tag -a -m "Tagging at $datestamp" testtag &&
  28        git update-ref refs/remotes/origin/master master &&
  29        git remote add origin nowhere &&
  30        git config branch.master.remote origin &&
  31        git config branch.master.merge refs/heads/master
  32'
  33
  34test_atom() {
  35        case "$1" in
  36                head) ref=refs/heads/master ;;
  37                 tag) ref=refs/tags/testtag ;;
  38                   *) ref=$1 ;;
  39        esac
  40        printf '%s\n' "$3" >expected
  41        test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
  42                git for-each-ref --format='%($2)' $ref >actual &&
  43                sanitize_pgp <actual >actual.clean &&
  44                test_cmp expected actual.clean
  45        "
  46}
  47
  48test_atom head refname refs/heads/master
  49test_atom head upstream refs/remotes/origin/master
  50test_atom head objecttype commit
  51test_atom head objectsize 171
  52test_atom head objectname $(git rev-parse refs/heads/master)
  53test_atom head tree $(git rev-parse refs/heads/master^{tree})
  54test_atom head parent ''
  55test_atom head numparent 0
  56test_atom head object ''
  57test_atom head type ''
  58test_atom head '*objectname' ''
  59test_atom head '*objecttype' ''
  60test_atom head author 'A U Thor <author@example.com> 1151939924 +0200'
  61test_atom head authorname 'A U Thor'
  62test_atom head authoremail '<author@example.com>'
  63test_atom head authordate 'Mon Jul 3 17:18:44 2006 +0200'
  64test_atom head committer 'C O Mitter <committer@example.com> 1151939923 +0200'
  65test_atom head committername 'C O Mitter'
  66test_atom head committeremail '<committer@example.com>'
  67test_atom head committerdate 'Mon Jul 3 17:18:43 2006 +0200'
  68test_atom head tag ''
  69test_atom head tagger ''
  70test_atom head taggername ''
  71test_atom head taggeremail ''
  72test_atom head taggerdate ''
  73test_atom head creator 'C O Mitter <committer@example.com> 1151939923 +0200'
  74test_atom head creatordate 'Mon Jul 3 17:18:43 2006 +0200'
  75test_atom head subject 'Initial'
  76test_atom head contents:subject 'Initial'
  77test_atom head body ''
  78test_atom head contents:body ''
  79test_atom head contents:signature ''
  80test_atom head contents 'Initial
  81'
  82test_atom head HEAD '*'
  83
  84test_atom tag refname refs/tags/testtag
  85test_atom tag upstream ''
  86test_atom tag objecttype tag
  87test_atom tag objectsize 154
  88test_atom tag objectname $(git rev-parse refs/tags/testtag)
  89test_atom tag tree ''
  90test_atom tag parent ''
  91test_atom tag numparent ''
  92test_atom tag object $(git rev-parse refs/tags/testtag^0)
  93test_atom tag type 'commit'
  94test_atom tag '*objectname' '67a36f10722846e891fbada1ba48ed035de75581'
  95test_atom tag '*objecttype' 'commit'
  96test_atom tag author ''
  97test_atom tag authorname ''
  98test_atom tag authoremail ''
  99test_atom tag authordate ''
 100test_atom tag committer ''
 101test_atom tag committername ''
 102test_atom tag committeremail ''
 103test_atom tag committerdate ''
 104test_atom tag tag 'testtag'
 105test_atom tag tagger 'C O Mitter <committer@example.com> 1151939925 +0200'
 106test_atom tag taggername 'C O Mitter'
 107test_atom tag taggeremail '<committer@example.com>'
 108test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200'
 109test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200'
 110test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200'
 111test_atom tag subject 'Tagging at 1151939927'
 112test_atom tag contents:subject 'Tagging at 1151939927'
 113test_atom tag body ''
 114test_atom tag contents:body ''
 115test_atom tag contents:signature ''
 116test_atom tag contents 'Tagging at 1151939927
 117'
 118test_atom tag HEAD ' '
 119
 120test_expect_success 'Check invalid atoms names are errors' '
 121        test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
 122'
 123
 124test_expect_success 'Check format specifiers are ignored in naming date atoms' '
 125        git for-each-ref --format="%(authordate)" refs/heads &&
 126        git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
 127        git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
 128        git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
 129'
 130
 131test_expect_success 'Check valid format specifiers for date fields' '
 132        git for-each-ref --format="%(authordate:default)" refs/heads &&
 133        git for-each-ref --format="%(authordate:relative)" refs/heads &&
 134        git for-each-ref --format="%(authordate:short)" refs/heads &&
 135        git for-each-ref --format="%(authordate:local)" refs/heads &&
 136        git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
 137        git for-each-ref --format="%(authordate:rfc2822)" refs/heads
 138'
 139
 140test_expect_success 'Check invalid format specifiers are errors' '
 141        test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
 142'
 143
 144cat >expected <<\EOF
 145'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
 146'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
 147EOF
 148
 149test_expect_success 'Check unformatted date fields output' '
 150        (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
 151        git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
 152        test_cmp expected actual
 153'
 154
 155test_expect_success 'Check format "default" formatted date fields output' '
 156        f=default &&
 157        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 158        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
 159        test_cmp expected actual
 160'
 161
 162# Don't know how to do relative check because I can't know when this script
 163# is going to be run and can't fake the current time to git, and hence can't
 164# provide expected output.  Instead, I'll just make sure that "relative"
 165# doesn't exit in error
 166#
 167#cat >expected <<\EOF
 168#
 169#EOF
 170#
 171test_expect_success 'Check format "relative" date fields output' '
 172        f=relative &&
 173        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 174        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
 175'
 176
 177cat >expected <<\EOF
 178'refs/heads/master' '2006-07-03' '2006-07-03'
 179'refs/tags/testtag' '2006-07-03'
 180EOF
 181
 182test_expect_success 'Check format "short" date fields output' '
 183        f=short &&
 184        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 185        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
 186        test_cmp expected actual
 187'
 188
 189cat >expected <<\EOF
 190'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
 191'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
 192EOF
 193
 194test_expect_success 'Check format "local" date fields output' '
 195        f=local &&
 196        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 197        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
 198        test_cmp expected actual
 199'
 200
 201cat >expected <<\EOF
 202'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
 203'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
 204EOF
 205
 206test_expect_success 'Check format "iso8601" date fields output' '
 207        f=iso8601 &&
 208        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 209        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
 210        test_cmp expected actual
 211'
 212
 213cat >expected <<\EOF
 214'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
 215'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
 216EOF
 217
 218test_expect_success 'Check format "rfc2822" date fields output' '
 219        f=rfc2822 &&
 220        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 221        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
 222        test_cmp expected actual
 223'
 224
 225cat >expected <<\EOF
 226refs/heads/master
 227refs/remotes/origin/master
 228refs/tags/testtag
 229EOF
 230
 231test_expect_success 'Verify ascending sort' '
 232        git for-each-ref --format="%(refname)" --sort=refname >actual &&
 233        test_cmp expected actual
 234'
 235
 236
 237cat >expected <<\EOF
 238refs/tags/testtag
 239refs/remotes/origin/master
 240refs/heads/master
 241EOF
 242
 243test_expect_success 'Verify descending sort' '
 244        git for-each-ref --format="%(refname)" --sort=-refname >actual &&
 245        test_cmp expected actual
 246'
 247
 248cat >expected <<\EOF
 249'refs/heads/master'
 250'refs/remotes/origin/master'
 251'refs/tags/testtag'
 252EOF
 253
 254test_expect_success 'Quoting style: shell' '
 255        git for-each-ref --shell --format="%(refname)" >actual &&
 256        test_cmp expected actual
 257'
 258
 259test_expect_success 'Quoting style: perl' '
 260        git for-each-ref --perl --format="%(refname)" >actual &&
 261        test_cmp expected actual
 262'
 263
 264test_expect_success 'Quoting style: python' '
 265        git for-each-ref --python --format="%(refname)" >actual &&
 266        test_cmp expected actual
 267'
 268
 269cat >expected <<\EOF
 270"refs/heads/master"
 271"refs/remotes/origin/master"
 272"refs/tags/testtag"
 273EOF
 274
 275test_expect_success 'Quoting style: tcl' '
 276        git for-each-ref --tcl --format="%(refname)" >actual &&
 277        test_cmp expected actual
 278'
 279
 280for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
 281        test_expect_success "more than one quoting style: $i" "
 282                git for-each-ref $i 2>&1 | (read line &&
 283                case \$line in
 284                \"error: more than one quoting style\"*) : happy;;
 285                *) false
 286                esac)
 287        "
 288done
 289
 290cat >expected <<\EOF
 291master
 292testtag
 293EOF
 294
 295test_expect_success 'Check short refname format' '
 296        (git for-each-ref --format="%(refname:short)" refs/heads &&
 297        git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
 298        test_cmp expected actual
 299'
 300
 301cat >expected <<EOF
 302origin/master
 303EOF
 304
 305test_expect_success 'Check short upstream format' '
 306        git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
 307        test_cmp expected actual
 308'
 309
 310test_expect_success 'setup for upstream:track[short]' '
 311        test_commit two
 312'
 313
 314cat >expected <<EOF
 315[ahead 1]
 316EOF
 317
 318test_expect_success 'Check upstream:track format' '
 319        git for-each-ref --format="%(upstream:track)" refs/heads >actual &&
 320        test_cmp expected actual
 321'
 322
 323cat >expected <<EOF
 324>
 325EOF
 326
 327test_expect_success 'Check upstream:trackshort format' '
 328        git for-each-ref --format="%(upstream:trackshort)" refs/heads >actual &&
 329        test_cmp expected actual
 330'
 331
 332test_expect_success 'Check that :track[short] cannot be used with other atoms' '
 333        test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
 334        test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
 335'
 336
 337cat >expected <<EOF
 338$(git rev-parse --short HEAD)
 339EOF
 340
 341test_expect_success 'Check short objectname format' '
 342        git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
 343        test_cmp expected actual
 344'
 345
 346test_expect_success 'Check for invalid refname format' '
 347        test_must_fail git for-each-ref --format="%(refname:INVALID)"
 348'
 349
 350get_color ()
 351{
 352        git config --get-color no.such.slot "$1"
 353}
 354
 355cat >expected <<EOF
 356$(git rev-parse --short refs/heads/master) $(get_color green)master$(get_color reset)
 357$(git rev-parse --short refs/remotes/origin/master) $(get_color green)origin/master$(get_color reset)
 358$(git rev-parse --short refs/tags/testtag) $(get_color green)testtag$(get_color reset)
 359$(git rev-parse --short refs/tags/two) $(get_color green)two$(get_color reset)
 360EOF
 361
 362test_expect_success 'Check %(color:...) ' '
 363        git for-each-ref --format="%(objectname:short) %(color:green)%(refname:short)" >actual &&
 364        test_cmp expected actual
 365'
 366
 367cat >expected <<\EOF
 368heads/master
 369tags/master
 370EOF
 371
 372test_expect_success 'Check ambiguous head and tag refs (strict)' '
 373        git config --bool core.warnambiguousrefs true &&
 374        git checkout -b newtag &&
 375        echo "Using $datestamp" > one &&
 376        git add one &&
 377        git commit -m "Branch" &&
 378        setdate_and_increment &&
 379        git tag -m "Tagging at $datestamp" master &&
 380        git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
 381        test_cmp expected actual
 382'
 383
 384cat >expected <<\EOF
 385heads/master
 386master
 387EOF
 388
 389test_expect_success 'Check ambiguous head and tag refs (loose)' '
 390        git config --bool core.warnambiguousrefs false &&
 391        git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
 392        test_cmp expected actual
 393'
 394
 395cat >expected <<\EOF
 396heads/ambiguous
 397ambiguous
 398EOF
 399
 400test_expect_success 'Check ambiguous head and tag refs II (loose)' '
 401        git checkout master &&
 402        git tag ambiguous testtag^0 &&
 403        git branch ambiguous testtag^0 &&
 404        git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
 405        test_cmp expected actual
 406'
 407
 408test_expect_success 'an unusual tag with an incomplete line' '
 409
 410        git tag -m "bogo" bogo &&
 411        bogo=$(git cat-file tag bogo) &&
 412        bogo=$(printf "%s" "$bogo" | git mktag) &&
 413        git tag -f bogo "$bogo" &&
 414        git for-each-ref --format "%(body)" refs/tags/bogo
 415
 416'
 417
 418test_expect_success 'create tag with subject and body content' '
 419        cat >>msg <<-\EOF &&
 420                the subject line
 421
 422                first body line
 423                second body line
 424        EOF
 425        git tag -F msg subject-body
 426'
 427test_atom refs/tags/subject-body subject 'the subject line'
 428test_atom refs/tags/subject-body body 'first body line
 429second body line
 430'
 431test_atom refs/tags/subject-body contents 'the subject line
 432
 433first body line
 434second body line
 435'
 436
 437test_expect_success 'create tag with multiline subject' '
 438        cat >msg <<-\EOF &&
 439                first subject line
 440                second subject line
 441
 442                first body line
 443                second body line
 444        EOF
 445        git tag -F msg multiline
 446'
 447test_atom refs/tags/multiline subject 'first subject line second subject line'
 448test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
 449test_atom refs/tags/multiline body 'first body line
 450second body line
 451'
 452test_atom refs/tags/multiline contents:body 'first body line
 453second body line
 454'
 455test_atom refs/tags/multiline contents:signature ''
 456test_atom refs/tags/multiline contents 'first subject line
 457second subject line
 458
 459first body line
 460second body line
 461'
 462
 463test_expect_success GPG 'create signed tags' '
 464        git tag -s -m "" signed-empty &&
 465        git tag -s -m "subject line" signed-short &&
 466        cat >msg <<-\EOF &&
 467        subject line
 468
 469        body contents
 470        EOF
 471        git tag -s -F msg signed-long
 472'
 473
 474sig='-----BEGIN PGP SIGNATURE-----
 475-----END PGP SIGNATURE-----
 476'
 477
 478PREREQ=GPG
 479test_atom refs/tags/signed-empty subject ''
 480test_atom refs/tags/signed-empty contents:subject ''
 481test_atom refs/tags/signed-empty body "$sig"
 482test_atom refs/tags/signed-empty contents:body ''
 483test_atom refs/tags/signed-empty contents:signature "$sig"
 484test_atom refs/tags/signed-empty contents "$sig"
 485
 486test_atom refs/tags/signed-short subject 'subject line'
 487test_atom refs/tags/signed-short contents:subject 'subject line'
 488test_atom refs/tags/signed-short body "$sig"
 489test_atom refs/tags/signed-short contents:body ''
 490test_atom refs/tags/signed-short contents:signature "$sig"
 491test_atom refs/tags/signed-short contents "subject line
 492$sig"
 493
 494test_atom refs/tags/signed-long subject 'subject line'
 495test_atom refs/tags/signed-long contents:subject 'subject line'
 496test_atom refs/tags/signed-long body "body contents
 497$sig"
 498test_atom refs/tags/signed-long contents:body 'body contents
 499'
 500test_atom refs/tags/signed-long contents:signature "$sig"
 501test_atom refs/tags/signed-long contents "subject line
 502
 503body contents
 504$sig"
 505
 506cat >expected <<EOF
 507$(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
 508$(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
 509EOF
 510
 511test_expect_success 'Verify sort with multiple keys' '
 512        git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
 513                refs/tags/bogo refs/tags/master > actual &&
 514        test_cmp expected actual
 515'
 516test_done