t / t6302-for-each-ref-filter.shon commit t6302: also test annotated in addition to signed tags (7bc734e)
   1#!/bin/sh
   2
   3test_description='test for-each-refs usage of ref-filter APIs'
   4
   5. ./test-lib.sh
   6. "$TEST_DIRECTORY"/lib-gpg.sh
   7
   8if ! test_have_prereq GPG
   9then
  10        skip_all="skipping for-each-ref tests, GPG not available"
  11        test_done
  12fi
  13
  14test_expect_success 'setup some history and refs' '
  15        test_commit one &&
  16        test_commit two &&
  17        test_commit three &&
  18        git checkout -b side &&
  19        test_commit four &&
  20        git tag -m "An annotated tag" annotated-tag &&
  21        git tag -m "Annonated doubly" doubly-annotated-tag annotated-tag &&
  22        git tag -s -m "A signed tag" signed-tag &&
  23        git tag -s -m "Signed doubly" doubly-signed-tag signed-tag &&
  24        git checkout master &&
  25        git update-ref refs/odd/spot master
  26'
  27
  28test_expect_success 'filtering with --points-at' '
  29        cat >expect <<-\EOF &&
  30        refs/heads/master
  31        refs/odd/spot
  32        refs/tags/three
  33        EOF
  34        git for-each-ref --format="%(refname)" --points-at=master >actual &&
  35        test_cmp expect actual
  36'
  37
  38test_expect_success 'check signed tags with --points-at' '
  39        sed -e "s/Z$//" >expect <<-\EOF &&
  40        refs/heads/side Z
  41        refs/tags/annotated-tag four
  42        refs/tags/four Z
  43        refs/tags/signed-tag four
  44        EOF
  45        git for-each-ref --format="%(refname) %(*subject)" --points-at=side >actual &&
  46        test_cmp expect actual
  47'
  48
  49test_expect_success 'filtering with --merged' '
  50        cat >expect <<-\EOF &&
  51        refs/heads/master
  52        refs/odd/spot
  53        refs/tags/one
  54        refs/tags/three
  55        refs/tags/two
  56        EOF
  57        git for-each-ref --format="%(refname)" --merged=master >actual &&
  58        test_cmp expect actual
  59'
  60
  61test_expect_success 'filtering with --no-merged' '
  62        cat >expect <<-\EOF &&
  63        refs/heads/side
  64        refs/tags/annotated-tag
  65        refs/tags/doubly-annotated-tag
  66        refs/tags/doubly-signed-tag
  67        refs/tags/four
  68        refs/tags/signed-tag
  69        EOF
  70        git for-each-ref --format="%(refname)" --no-merged=master >actual &&
  71        test_cmp expect actual
  72'
  73
  74test_expect_success 'filtering with --contains' '
  75        cat >expect <<-\EOF &&
  76        refs/heads/master
  77        refs/heads/side
  78        refs/odd/spot
  79        refs/tags/annotated-tag
  80        refs/tags/doubly-annotated-tag
  81        refs/tags/doubly-signed-tag
  82        refs/tags/four
  83        refs/tags/signed-tag
  84        refs/tags/three
  85        refs/tags/two
  86        EOF
  87        git for-each-ref --format="%(refname)" --contains=two >actual &&
  88        test_cmp expect actual
  89'
  90
  91test_expect_success '%(color) must fail' '
  92        test_must_fail git for-each-ref --format="%(color)%(refname)"
  93'
  94
  95test_expect_success 'left alignment is default' '
  96        cat >expect <<-\EOF &&
  97        refname is refs/heads/master  |refs/heads/master
  98        refname is refs/heads/side    |refs/heads/side
  99        refname is refs/odd/spot      |refs/odd/spot
 100        refname is refs/tags/annotated-tag|refs/tags/annotated-tag
 101        refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
 102        refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
 103        refname is refs/tags/four     |refs/tags/four
 104        refname is refs/tags/one      |refs/tags/one
 105        refname is refs/tags/signed-tag|refs/tags/signed-tag
 106        refname is refs/tags/three    |refs/tags/three
 107        refname is refs/tags/two      |refs/tags/two
 108        EOF
 109        git for-each-ref --format="%(align:30)refname is %(refname)%(end)|%(refname)" >actual &&
 110        test_cmp expect actual
 111'
 112
 113test_expect_success 'middle alignment' '
 114        cat >expect <<-\EOF &&
 115        | refname is refs/heads/master |refs/heads/master
 116        |  refname is refs/heads/side  |refs/heads/side
 117        |   refname is refs/odd/spot   |refs/odd/spot
 118        |refname is refs/tags/annotated-tag|refs/tags/annotated-tag
 119        |refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
 120        |refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
 121        |  refname is refs/tags/four   |refs/tags/four
 122        |   refname is refs/tags/one   |refs/tags/one
 123        |refname is refs/tags/signed-tag|refs/tags/signed-tag
 124        |  refname is refs/tags/three  |refs/tags/three
 125        |   refname is refs/tags/two   |refs/tags/two
 126        EOF
 127        git for-each-ref --format="|%(align:middle,30)refname is %(refname)%(end)|%(refname)" >actual &&
 128        test_cmp expect actual
 129'
 130
 131test_expect_success 'right alignment' '
 132        cat >expect <<-\EOF &&
 133        |  refname is refs/heads/master|refs/heads/master
 134        |    refname is refs/heads/side|refs/heads/side
 135        |      refname is refs/odd/spot|refs/odd/spot
 136        |refname is refs/tags/annotated-tag|refs/tags/annotated-tag
 137        |refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
 138        |refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
 139        |     refname is refs/tags/four|refs/tags/four
 140        |      refname is refs/tags/one|refs/tags/one
 141        |refname is refs/tags/signed-tag|refs/tags/signed-tag
 142        |    refname is refs/tags/three|refs/tags/three
 143        |      refname is refs/tags/two|refs/tags/two
 144        EOF
 145        git for-each-ref --format="|%(align:30,right)refname is %(refname)%(end)|%(refname)" >actual &&
 146        test_cmp expect actual
 147'
 148
 149cat >expect <<-\EOF
 150|       refname is refs/heads/master       |refs/heads/master
 151|        refname is refs/heads/side        |refs/heads/side
 152|         refname is refs/odd/spot         |refs/odd/spot
 153|    refname is refs/tags/annotated-tag    |refs/tags/annotated-tag
 154|refname is refs/tags/doubly-annotated-tag |refs/tags/doubly-annotated-tag
 155|  refname is refs/tags/doubly-signed-tag  |refs/tags/doubly-signed-tag
 156|        refname is refs/tags/four         |refs/tags/four
 157|         refname is refs/tags/one         |refs/tags/one
 158|     refname is refs/tags/signed-tag      |refs/tags/signed-tag
 159|        refname is refs/tags/three        |refs/tags/three
 160|         refname is refs/tags/two         |refs/tags/two
 161EOF
 162
 163test_align_permutations() {
 164        while read -r option
 165        do
 166                test_expect_success "align:$option" '
 167                        git for-each-ref --format="|%(align:$option)refname is %(refname)%(end)|%(refname)" >actual &&
 168                        test_cmp expect actual
 169                '
 170        done
 171}
 172
 173test_align_permutations <<-\EOF
 174        middle,42
 175        42,middle
 176        position=middle,42
 177        42,position=middle
 178        middle,width=42
 179        width=42,middle
 180        position=middle,width=42
 181        width=42,position=middle
 182EOF
 183
 184# Last one wins (silently) when multiple arguments of the same type are given
 185
 186test_align_permutations <<-\EOF
 187        32,width=42,middle
 188        width=30,42,middle
 189        width=42,position=right,middle
 190        42,right,position=middle
 191EOF
 192
 193# Individual atoms inside %(align:...) and %(end) must not be quoted.
 194
 195test_expect_success 'alignment with format quote' "
 196        cat >expect <<-\EOF &&
 197        |'      '\''master| A U Thor'\''      '|
 198        |'       '\''side| A U Thor'\''       '|
 199        |'     '\''odd/spot| A U Thor'\''     '|
 200        |'      '\''annotated-tag| '\''       '|
 201        |'   '\''doubly-annotated-tag| '\''   '|
 202        |'    '\''doubly-signed-tag| '\''     '|
 203        |'       '\''four| A U Thor'\''       '|
 204        |'       '\''one| A U Thor'\''        '|
 205        |'        '\''signed-tag| '\''        '|
 206        |'      '\''three| A U Thor'\''       '|
 207        |'       '\''two| A U Thor'\''        '|
 208        EOF
 209        git for-each-ref --shell --format=\"|%(align:30,middle)'%(refname:short)| %(authorname)'%(end)|\" >actual &&
 210        test_cmp expect actual
 211"
 212
 213test_expect_success 'nested alignment with quote formatting' "
 214        cat >expect <<-\EOF &&
 215        |'         master               '|
 216        |'           side               '|
 217        |'       odd/spot               '|
 218        |'  annotated-tag               '|
 219        |'doubly-annotated-tag          '|
 220        |'doubly-signed-tag             '|
 221        |'           four               '|
 222        |'            one               '|
 223        |'     signed-tag               '|
 224        |'          three               '|
 225        |'            two               '|
 226        EOF
 227        git for-each-ref --shell --format='|%(align:30,left)%(align:15,right)%(refname:short)%(end)%(end)|' >actual &&
 228        test_cmp expect actual
 229"
 230
 231test_expect_success 'check `%(contents:lines=1)`' '
 232        cat >expect <<-\EOF &&
 233        master |three
 234        side |four
 235        odd/spot |three
 236        annotated-tag |An annotated tag
 237        doubly-annotated-tag |Annonated doubly
 238        doubly-signed-tag |Signed doubly
 239        four |four
 240        one |one
 241        signed-tag |A signed tag
 242        three |three
 243        two |two
 244        EOF
 245        git for-each-ref --format="%(refname:short) |%(contents:lines=1)" >actual &&
 246        test_cmp expect actual
 247'
 248
 249test_expect_success 'check `%(contents:lines=0)`' '
 250        cat >expect <<-\EOF &&
 251        master |
 252        side |
 253        odd/spot |
 254        annotated-tag |
 255        doubly-annotated-tag |
 256        doubly-signed-tag |
 257        four |
 258        one |
 259        signed-tag |
 260        three |
 261        two |
 262        EOF
 263        git for-each-ref --format="%(refname:short) |%(contents:lines=0)" >actual &&
 264        test_cmp expect actual
 265'
 266
 267test_expect_success 'check `%(contents:lines=99999)`' '
 268        cat >expect <<-\EOF &&
 269        master |three
 270        side |four
 271        odd/spot |three
 272        annotated-tag |An annotated tag
 273        doubly-annotated-tag |Annonated doubly
 274        doubly-signed-tag |Signed doubly
 275        four |four
 276        one |one
 277        signed-tag |A signed tag
 278        three |three
 279        two |two
 280        EOF
 281        git for-each-ref --format="%(refname:short) |%(contents:lines=99999)" >actual &&
 282        test_cmp expect actual
 283'
 284
 285test_expect_success '`%(contents:lines=-1)` should fail' '
 286        test_must_fail git for-each-ref --format="%(refname:short) |%(contents:lines=-1)"
 287'
 288
 289test_expect_success 'setup for version sort' '
 290        test_commit foo1.3 &&
 291        test_commit foo1.6 &&
 292        test_commit foo1.10
 293'
 294
 295test_expect_success 'version sort' '
 296        git for-each-ref --sort=version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
 297        cat >expect <<-\EOF &&
 298        foo1.3
 299        foo1.6
 300        foo1.10
 301        EOF
 302        test_cmp expect actual
 303'
 304
 305test_expect_success 'version sort (shortened)' '
 306        git for-each-ref --sort=v:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
 307        cat >expect <<-\EOF &&
 308        foo1.3
 309        foo1.6
 310        foo1.10
 311        EOF
 312        test_cmp expect actual
 313'
 314
 315test_expect_success 'reverse version sort' '
 316        git for-each-ref --sort=-version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
 317        cat >expect <<-\EOF &&
 318        foo1.10
 319        foo1.6
 320        foo1.3
 321        EOF
 322        test_cmp expect actual
 323'
 324
 325test_done