1#!/bin/sh
   2test_description='rev-list/rev-parse --glob'
   4. ./test-lib.sh
   6commit () {
   8        test_tick &&
   9        echo $1 > foo &&
  10        git add foo &&
  11        git commit -m "$1"
  12}
  13compare () {
  15        # Split arguments on whitespace.
  16        git $1 $2 >expected &&
  17        git $1 $3 >actual &&
  18        test_cmp expected actual
  19}
  20test_expect_success 'setup' '
  22        commit master &&
  24        git checkout -b subspace/one master &&
  25        commit one &&
  26        git checkout -b subspace/two master &&
  27        commit two &&
  28        git checkout -b subspace-x master &&
  29        commit subspace-x &&
  30        git checkout -b other/three master &&
  31        commit three &&
  32        git checkout -b someref master &&
  33        commit some &&
  34        git checkout master &&
  35        commit master2 &&
  36        git tag foo/bar master &&
  37        commit master3 &&
  38        git update-ref refs/remotes/foo/baz master &&
  39        commit master4 &&
  40        git update-ref refs/remotes/upstream/one subspace/one &&
  41        git update-ref refs/remotes/upstream/two subspace/two &&
  42        git update-ref refs/remotes/upstream/x subspace-x &&
  43        git tag qux/one subspace/one &&
  44        git tag qux/two subspace/two &&
  45        git tag qux/x subspace-x
  46'
  47test_expect_success 'rev-parse --glob=refs/heads/subspace/*' '
  49        compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
  51'
  53test_expect_success 'rev-parse --glob=heads/subspace/*' '
  55        compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/*"
  57'
  59test_expect_success 'rev-parse --glob=refs/heads/subspace/' '
  61        compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/"
  63'
  65test_expect_success 'rev-parse --glob=heads/subspace/' '
  67        compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/"
  69'
  71test_expect_success 'rev-parse --glob=heads/subspace' '
  73        compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace"
  75'
  77test_expect_failure 'rev-parse accepts --glob as detached option' '
  79        compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"
  81'
  83test_expect_failure 'rev-parse is not confused by option-like glob' '
  85        compare rev-parse "master" "--glob --symbolic master"
  87'
  89test_expect_success 'rev-parse --branches=subspace/*' '
  91        compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
  93'
  95test_expect_success 'rev-parse --branches=subspace/' '
  97        compare rev-parse "subspace/one subspace/two" "--branches=subspace/"
  99'
 101test_expect_success 'rev-parse --branches=subspace' '
 103        compare rev-parse "subspace/one subspace/two" "--branches=subspace"
 105'
 107test_expect_success 'rev-parse --glob=heads/subspace/* --glob=heads/other/*' '
 109        compare rev-parse "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
 111'
 113test_expect_success 'rev-parse --glob=heads/someref/* master' '
 115        compare rev-parse "master" "--glob=heads/someref/* master"
 117'
 119test_expect_success 'rev-parse --glob=heads/*' '
 121        compare rev-parse "master other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
 123'
 125test_expect_success 'rev-parse --tags=foo' '
 127        compare rev-parse "foo/bar" "--tags=foo"
 129'
 131test_expect_success 'rev-parse --remotes=foo' '
 133        compare rev-parse "foo/baz" "--remotes=foo"
 135'
 137test_expect_success 'rev-parse --exclude with --branches' '
 139        compare rev-parse "--exclude=*/* --branches" "master someref subspace-x"
 140'
 141test_expect_success 'rev-parse --exclude with --all' '
 143        compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags"
 144'
 145test_expect_success 'rev-parse accumulates multiple --exclude' '
 147        compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
 148'
 149test_expect_success 'rev-parse --branches clears --exclude' '
 151        compare rev-parse "--exclude=* --branches --branches" "--branches"
 152'
 153test_expect_success 'rev-parse --tags clears --exclude' '
 155        compare rev-parse "--exclude=* --tags --tags" "--tags"
 156'
 157test_expect_success 'rev-parse --all clears --exclude' '
 159        compare rev-parse "--exclude=* --all --all" "--all"
 160'
 161test_expect_success 'rev-parse --exclude=glob with --branches=glob' '
 163        compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
 164'
 165test_expect_success 'rev-parse --exclude=glob with --tags=glob' '
 167        compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
 168'
 169test_expect_success 'rev-parse --exclude=glob with --remotes=glob' '
 171        compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
 172'
 173test_expect_success 'rev-parse --exclude=ref with --branches=glob' '
 175        compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
 176'
 177test_expect_success 'rev-parse --exclude=ref with --tags=glob' '
 179        compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
 180'
 181test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
 183        compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
 184'
 185test_expect_success 'rev-list --exclude=glob with --branches=glob' '
 187        compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
 188'
 189test_expect_success 'rev-list --exclude=glob with --tags=glob' '
 191        compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
 192'
 193test_expect_success 'rev-list --exclude=glob with --remotes=glob' '
 195        compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
 196'
 197test_expect_success 'rev-list --exclude=ref with --branches=glob' '
 199        compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
 200'
 201test_expect_success 'rev-list --exclude=ref with --tags=glob' '
 203        compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
 204'
 205test_expect_success 'rev-list --exclude=ref with --remotes=glob' '
 207        compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
 208'
 209test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
 211        compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
 213'
 215test_expect_success 'rev-list --glob refs/heads/subspace/*' '
 217        compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*"
 219'
 221test_expect_success 'rev-list not confused by option-like --glob arg' '
 223        compare rev-list "master" "--glob -0 master"
 225'
 227test_expect_success 'rev-list --glob=heads/subspace/*' '
 229        compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
 231'
 233test_expect_success 'rev-list --glob=refs/heads/subspace/' '
 235        compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/"
 237'
 239test_expect_success 'rev-list --glob=heads/subspace/' '
 241        compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/"
 243'
 245test_expect_success 'rev-list --glob=heads/subspace' '
 247        compare rev-list "subspace/one subspace/two" "--glob=heads/subspace"
 249'
 251test_expect_success 'rev-list --branches=subspace/*' '
 253        compare rev-list "subspace/one subspace/two" "--branches=subspace/*"
 255'
 257test_expect_success 'rev-list --branches=subspace/' '
 259        compare rev-list "subspace/one subspace/two" "--branches=subspace/"
 261'
 263test_expect_success 'rev-list --branches=subspace' '
 265        compare rev-list "subspace/one subspace/two" "--branches=subspace"
 267'
 269test_expect_success 'rev-list --branches' '
 271        compare rev-list "master subspace-x someref other/three subspace/one subspace/two" "--branches"
 273'
 275test_expect_success 'rev-list --glob=heads/someref/* master' '
 277        compare rev-list "master" "--glob=heads/someref/* master"
 279'
 281test_expect_success 'rev-list --glob=heads/subspace/* --glob=heads/other/*' '
 283        compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
 285'
 287test_expect_success 'rev-list --glob=heads/*' '
 289        compare rev-list "master other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
 291'
 293test_expect_success 'rev-list --tags=foo' '
 295        compare rev-list "foo/bar" "--tags=foo"
 297'
 299test_expect_success 'rev-list --tags' '
 301        compare rev-list "foo/bar qux/x qux/two qux/one" "--tags"
 303'
 305test_expect_success 'rev-list --remotes=foo' '
 307        compare rev-list "foo/baz" "--remotes=foo"
 309'
 311test_expect_success 'rev-list --exclude with --branches' '
 313        compare rev-list "--exclude=*/* --branches" "master someref subspace-x"
 314'
 315test_expect_success 'rev-list --exclude with --all' '
 317        compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags"
 318'
 319test_expect_success 'rev-list accumulates multiple --exclude' '
 321        compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
 322'
 323test_expect_success 'rev-list should succeed with empty output on empty stdin' '
 325        git rev-list --stdin </dev/null >actual &&
 326        test_must_be_empty actual
 327'
 328test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
 330        git rev-list --exclude=* --all >actual &&
 331        test_must_be_empty actual
 332'
 333test_expect_success 'rev-list should succeed with empty output with empty --all' '
 335        (
 336                test_create_repo empty &&
 337                cd empty &&
 338                git rev-list --all >actual &&
 339                test_must_be_empty actual
 340        )
 341'
 342test_expect_success 'rev-list should succeed with empty output with empty glob' '
 344        git rev-list --glob=does-not-match-anything >actual &&
 345        test_must_be_empty actual
 346'
 347test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
 349        compare shortlog "subspace/one subspace/two" --branches=subspace &&
 351        compare shortlog \
 352          "master subspace-x someref other/three subspace/one subspace/two" \
 353          --branches &&
 354        compare shortlog master "--glob=heads/someref/* master" &&
 355        compare shortlog "subspace/one subspace/two other/three" \
 356          "--glob=heads/subspace/* --glob=heads/other/*" &&
 357        compare shortlog \
 358          "master other/three someref subspace-x subspace/one subspace/two" \
 359          "--glob=heads/*" &&
 360        compare shortlog foo/bar --tags=foo &&
 361        compare shortlog "foo/bar qux/one qux/two qux/x" --tags &&
 362        compare shortlog foo/baz --remotes=foo
 363'
 365test_expect_failure 'shortlog accepts --glob as detached option' '
 367        compare shortlog \
 369          "master other/three someref subspace-x subspace/one subspace/two" \
 370          "--glob heads/*"
 371'
 373test_expect_failure 'shortlog --glob is not confused by option-like argument' '
 375        compare shortlog master "--glob -e master"
 377'
 379test_done