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'
  41test_expect_success 'rev-parse --glob=refs/heads/subspace/*' '
  43        compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
  45'
  47test_expect_success 'rev-parse --glob=heads/subspace/*' '
  49        compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/*"
  51'
  53test_expect_success 'rev-parse --glob=refs/heads/subspace/' '
  55        compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/"
  57'
  59test_expect_success 'rev-parse --glob=heads/subspace/' '
  61        compare rev-parse "subspace/one subspace/two" "--glob=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_failure 'rev-parse accepts --glob as detached option' '
  73        compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"
  75'
  77test_expect_failure 'rev-parse is not confused by option-like glob' '
  79        compare rev-parse "master" "--glob --symbolic master"
  81'
  83test_expect_success 'rev-parse --branches=subspace/*' '
  85        compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
  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 --glob=heads/subspace/* --glob=heads/other/*' '
 103        compare rev-parse "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
 105'
 107test_expect_success 'rev-parse --glob=heads/someref/* master' '
 109        compare rev-parse "master" "--glob=heads/someref/* master"
 111'
 113test_expect_success 'rev-parse --glob=heads/*' '
 115        compare rev-parse "master other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
 117'
 119test_expect_success 'rev-parse --tags=foo' '
 121        compare rev-parse "foo/bar" "--tags=foo"
 123'
 125test_expect_success 'rev-parse --remotes=foo' '
 127        compare rev-parse "foo/baz" "--remotes=foo"
 129'
 131test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
 133        compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
 135'
 137test_expect_success 'rev-list --glob refs/heads/subspace/*' '
 139        compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*"
 141'
 143test_expect_success 'rev-list not confused by option-like --glob arg' '
 145        compare rev-list "master" "--glob -0 master"
 147'
 149test_expect_success 'rev-list --glob=heads/subspace/*' '
 151        compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
 153'
 155test_expect_success 'rev-list --glob=refs/heads/subspace/' '
 157        compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/"
 159'
 161test_expect_success 'rev-list --glob=heads/subspace/' '
 163        compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/"
 165'
 167test_expect_success 'rev-list --glob=heads/subspace' '
 169        compare rev-list "subspace/one subspace/two" "--glob=heads/subspace"
 171'
 173test_expect_success 'rev-list --branches=subspace/*' '
 175        compare rev-list "subspace/one subspace/two" "--branches=subspace/*"
 177'
 179test_expect_success 'rev-list --branches=subspace/' '
 181        compare rev-list "subspace/one subspace/two" "--branches=subspace/"
 183'
 185test_expect_success 'rev-list --branches=subspace' '
 187        compare rev-list "subspace/one subspace/two" "--branches=subspace"
 189'
 191test_expect_success 'rev-list --branches' '
 193        compare rev-list "master subspace-x someref other/three subspace/one subspace/two" "--branches"
 195'
 197test_expect_success 'rev-list --glob=heads/someref/* master' '
 199        compare rev-list "master" "--glob=heads/someref/* master"
 201'
 203test_expect_success 'rev-list --glob=heads/subspace/* --glob=heads/other/*' '
 205        compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
 207'
 209test_expect_success 'rev-list --glob=heads/*' '
 211        compare rev-list "master other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
 213'
 215test_expect_success 'rev-list --tags=foo' '
 217        compare rev-list "foo/bar" "--tags=foo"
 219'
 221test_expect_success 'rev-list --tags' '
 223        compare rev-list "foo/bar" "--tags"
 225'
 227test_expect_success 'rev-list --remotes=foo' '
 229        compare rev-list "foo/baz" "--remotes=foo"
 231'
 233test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
 235        compare shortlog "subspace/one subspace/two" --branches=subspace &&
 237        compare shortlog \
 238          "master subspace-x someref other/three subspace/one subspace/two" \
 239          --branches &&
 240        compare shortlog master "--glob=heads/someref/* master" &&
 241        compare shortlog "subspace/one subspace/two other/three" \
 242          "--glob=heads/subspace/* --glob=heads/other/*" &&
 243        compare shortlog \
 244          "master other/three someref subspace-x subspace/one subspace/two" \
 245          "--glob=heads/*" &&
 246        compare shortlog foo/bar --tags=foo &&
 247        compare shortlog foo/bar --tags &&
 248        compare shortlog foo/baz --remotes=foo
 249'
 251test_expect_failure 'shortlog accepts --glob as detached option' '
 253        compare shortlog \
 255          "master other/three someref subspace-x subspace/one subspace/two" \
 256          "--glob heads/*"
 257'
 259test_expect_failure 'shortlog --glob is not confused by option-like argument' '
 261        compare shortlog master "--glob -e master"
 263'
 265test_done