t / t6300-for-each-ref.shon commit fetch and pull: learn --progress (9839018)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Andy Parkins
   4#
   5
   6test_description='for-each-ref test'
   7
   8. ./test-lib.sh
   9
  10# Mon Jul 3 15:18:43 2006 +0000
  11datestamp=1151939923
  12setdate_and_increment () {
  13    GIT_COMMITTER_DATE="$datestamp +0200"
  14    datestamp=$(expr "$datestamp" + 1)
  15    GIT_AUTHOR_DATE="$datestamp +0200"
  16    datestamp=$(expr "$datestamp" + 1)
  17    export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
  18}
  19
  20test_expect_success 'Create sample commit with known timestamp' '
  21        setdate_and_increment &&
  22        echo "Using $datestamp" > one &&
  23        git add one &&
  24        git commit -m "Initial" &&
  25        setdate_and_increment &&
  26        git tag -a -m "Tagging at $datestamp" testtag
  27'
  28
  29test_expect_success 'Create upstream config' '
  30        git update-ref refs/remotes/origin/master master &&
  31        git remote add origin nowhere &&
  32        git config branch.master.remote origin &&
  33        git config branch.master.merge refs/heads/master
  34'
  35
  36test_atom() {
  37        case "$1" in
  38                head) ref=refs/heads/master ;;
  39                 tag) ref=refs/tags/testtag ;;
  40        esac
  41        printf '%s\n' "$3" >expected
  42        test_expect_${4:-success} "basic atom: $1 $2" "
  43                git for-each-ref --format='%($2)' $ref >actual &&
  44                test_cmp expected actual
  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 67a36f10722846e891fbada1ba48ed035de75581
  53test_atom head tree 0e51c00fcb93dffc755546f27593d511e1bdb46f
  54test_atom head parent ''
  55test_atom head numparent 0
  56test_atom head object ''
  57test_atom head type ''
  58test_atom head author 'A U Thor <author@example.com> 1151939924 +0200'
  59test_atom head authorname 'A U Thor'
  60test_atom head authoremail '<author@example.com>'
  61test_atom head authordate 'Mon Jul 3 17:18:44 2006 +0200'
  62test_atom head committer 'C O Mitter <committer@example.com> 1151939923 +0200'
  63test_atom head committername 'C O Mitter'
  64test_atom head committeremail '<committer@example.com>'
  65test_atom head committerdate 'Mon Jul 3 17:18:43 2006 +0200'
  66test_atom head tag ''
  67test_atom head tagger ''
  68test_atom head taggername ''
  69test_atom head taggeremail ''
  70test_atom head taggerdate ''
  71test_atom head creator 'C O Mitter <committer@example.com> 1151939923 +0200'
  72test_atom head creatordate 'Mon Jul 3 17:18:43 2006 +0200'
  73test_atom head subject 'Initial'
  74test_atom head body ''
  75test_atom head contents 'Initial
  76'
  77
  78test_atom tag refname refs/tags/testtag
  79test_atom tag upstream ''
  80test_atom tag objecttype tag
  81test_atom tag objectsize 154
  82test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322
  83test_atom tag tree ''
  84test_atom tag parent ''
  85test_atom tag numparent ''
  86test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581'
  87test_atom tag type 'commit'
  88test_atom tag author ''
  89test_atom tag authorname ''
  90test_atom tag authoremail ''
  91test_atom tag authordate ''
  92test_atom tag committer ''
  93test_atom tag committername ''
  94test_atom tag committeremail ''
  95test_atom tag committerdate ''
  96test_atom tag tag 'testtag'
  97test_atom tag tagger 'C O Mitter <committer@example.com> 1151939925 +0200'
  98test_atom tag taggername 'C O Mitter'
  99test_atom tag taggeremail '<committer@example.com>'
 100test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200'
 101test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200'
 102test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200'
 103test_atom tag subject 'Tagging at 1151939927'
 104test_atom tag body ''
 105test_atom tag contents 'Tagging at 1151939927
 106'
 107
 108test_expect_success 'Check invalid atoms names are errors' '
 109        test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
 110'
 111
 112test_expect_success 'Check format specifiers are ignored in naming date atoms' '
 113        git for-each-ref --format="%(authordate)" refs/heads &&
 114        git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
 115        git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
 116        git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
 117'
 118
 119test_expect_success 'Check valid format specifiers for date fields' '
 120        git for-each-ref --format="%(authordate:default)" refs/heads &&
 121        git for-each-ref --format="%(authordate:relative)" refs/heads &&
 122        git for-each-ref --format="%(authordate:short)" refs/heads &&
 123        git for-each-ref --format="%(authordate:local)" refs/heads &&
 124        git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
 125        git for-each-ref --format="%(authordate:rfc2822)" refs/heads
 126'
 127
 128test_expect_success 'Check invalid format specifiers are errors' '
 129        test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
 130'
 131
 132cat >expected <<\EOF
 133'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
 134'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
 135EOF
 136
 137test_expect_success 'Check unformatted date fields output' '
 138        (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
 139        git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
 140        test_cmp expected actual
 141'
 142
 143test_expect_success 'Check format "default" formatted date fields output' '
 144        f=default &&
 145        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 146        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
 147        test_cmp expected actual
 148'
 149
 150# Don't know how to do relative check because I can't know when this script
 151# is going to be run and can't fake the current time to git, and hence can't
 152# provide expected output.  Instead, I'll just make sure that "relative"
 153# doesn't exit in error
 154#
 155#cat >expected <<\EOF
 156#
 157#EOF
 158#
 159test_expect_success 'Check format "relative" date fields output' '
 160        f=relative &&
 161        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 162        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
 163'
 164
 165cat >expected <<\EOF
 166'refs/heads/master' '2006-07-03' '2006-07-03'
 167'refs/tags/testtag' '2006-07-03'
 168EOF
 169
 170test_expect_success 'Check format "short" date fields output' '
 171        f=short &&
 172        (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
 173        git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
 174        test_cmp expected actual
 175'
 176
 177cat >expected <<\EOF
 178'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
 179'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
 180EOF
 181
 182test_expect_success 'Check format "local" date fields output' '
 183        f=local &&
 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' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
 191'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
 192EOF
 193
 194test_expect_success 'Check format "iso8601" date fields output' '
 195        f=iso8601 &&
 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' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
 203'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
 204EOF
 205
 206test_expect_success 'Check format "rfc2822" date fields output' '
 207        f=rfc2822 &&
 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
 214refs/heads/master
 215refs/remotes/origin/master
 216refs/tags/testtag
 217EOF
 218
 219test_expect_success 'Verify ascending sort' '
 220        git for-each-ref --format="%(refname)" --sort=refname >actual &&
 221        test_cmp expected actual
 222'
 223
 224
 225cat >expected <<\EOF
 226refs/tags/testtag
 227refs/remotes/origin/master
 228refs/heads/master
 229EOF
 230
 231test_expect_success 'Verify descending sort' '
 232        git for-each-ref --format="%(refname)" --sort=-refname >actual &&
 233        test_cmp expected actual
 234'
 235
 236cat >expected <<\EOF
 237'refs/heads/master'
 238'refs/remotes/origin/master'
 239'refs/tags/testtag'
 240EOF
 241
 242test_expect_success 'Quoting style: shell' '
 243        git for-each-ref --shell --format="%(refname)" >actual &&
 244        test_cmp expected actual
 245'
 246
 247test_expect_success 'Quoting style: perl' '
 248        git for-each-ref --perl --format="%(refname)" >actual &&
 249        test_cmp expected actual
 250'
 251
 252test_expect_success 'Quoting style: python' '
 253        git for-each-ref --python --format="%(refname)" >actual &&
 254        test_cmp expected actual
 255'
 256
 257cat >expected <<\EOF
 258"refs/heads/master"
 259"refs/remotes/origin/master"
 260"refs/tags/testtag"
 261EOF
 262
 263test_expect_success 'Quoting style: tcl' '
 264        git for-each-ref --tcl --format="%(refname)" >actual &&
 265        test_cmp expected actual
 266'
 267
 268for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
 269        test_expect_success "more than one quoting style: $i" "
 270                git for-each-ref $i 2>&1 | (read line &&
 271                case \$line in
 272                \"error: more than one quoting style\"*) : happy;;
 273                *) false
 274                esac)
 275        "
 276done
 277
 278cat >expected <<\EOF
 279master
 280testtag
 281EOF
 282
 283test_expect_success 'Check short refname format' '
 284        (git for-each-ref --format="%(refname:short)" refs/heads &&
 285        git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
 286        test_cmp expected actual
 287'
 288
 289cat >expected <<EOF
 290origin/master
 291EOF
 292
 293test_expect_success 'Check short upstream format' '
 294        git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
 295        test_cmp expected actual
 296'
 297
 298test_expect_success 'Check for invalid refname format' '
 299        test_must_fail git for-each-ref --format="%(refname:INVALID)"
 300'
 301
 302cat >expected <<\EOF
 303heads/master
 304tags/master
 305EOF
 306
 307test_expect_success 'Check ambiguous head and tag refs (strict)' '
 308        git config --bool core.warnambiguousrefs true &&
 309        git checkout -b newtag &&
 310        echo "Using $datestamp" > one &&
 311        git add one &&
 312        git commit -m "Branch" &&
 313        setdate_and_increment &&
 314        git tag -m "Tagging at $datestamp" master &&
 315        git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
 316        test_cmp expected actual
 317'
 318
 319cat >expected <<\EOF
 320heads/master
 321master
 322EOF
 323
 324test_expect_success 'Check ambiguous head and tag refs (loose)' '
 325        git config --bool core.warnambiguousrefs false &&
 326        git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
 327        test_cmp expected actual
 328'
 329
 330cat >expected <<\EOF
 331heads/ambiguous
 332ambiguous
 333EOF
 334
 335test_expect_success 'Check ambiguous head and tag refs II (loose)' '
 336        git checkout master &&
 337        git tag ambiguous testtag^0 &&
 338        git branch ambiguous testtag^0 &&
 339        git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
 340        test_cmp expected actual
 341'
 342
 343test_expect_success 'an unusual tag with an incomplete line' '
 344
 345        git tag -m "bogo" bogo &&
 346        bogo=$(git cat-file tag bogo) &&
 347        bogo=$(printf "%s" "$bogo" | git mktag) &&
 348        git tag -f bogo "$bogo" &&
 349        git for-each-ref --format "%(body)" refs/tags/bogo
 350
 351'
 352
 353test_done