1#!/bin/sh
   2test_description='show-ref'
   4. ./test-lib.sh
   5test_expect_success setup '
   7        test_commit A &&
   8        git tag -f -a -m "annotated A" A &&
   9        git checkout -b side &&
  10        test_commit B &&
  11        git tag -f -a -m "annotated B" B &&
  12        git checkout master &&
  13        test_commit C &&
  14        git branch B A^0
  15'
  16test_expect_success 'show-ref' '
  18        echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
  19        git show-ref A >actual &&
  21        test_cmp expect actual &&
  22        git show-ref tags/A >actual &&
  24        test_cmp expect actual &&
  25        git show-ref refs/tags/A >actual &&
  27        test_cmp expect actual &&
  28        >expect &&
  30        test_must_fail git show-ref D >actual &&
  32        test_cmp expect actual
  33'
  34test_expect_success 'show-ref -q' '
  36        >expect &&
  37        git show-ref -q A >actual &&
  39        test_cmp expect actual &&
  40        git show-ref -q tags/A >actual &&
  42        test_cmp expect actual &&
  43        git show-ref -q refs/tags/A >actual &&
  45        test_cmp expect actual &&
  46        test_must_fail git show-ref -q D >actual &&
  48        test_cmp expect actual
  49'
  50test_expect_success 'show-ref --verify' '
  52        echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
  53        git show-ref --verify refs/tags/A >actual &&
  55        test_cmp expect actual &&
  56        >expect &&
  58        test_must_fail git show-ref --verify A >actual &&
  60        test_cmp expect actual &&
  61        test_must_fail git show-ref --verify tags/A >actual &&
  63        test_cmp expect actual &&
  64        test_must_fail git show-ref --verify D >actual &&
  66        test_cmp expect actual
  67'
  68test_expect_success 'show-ref --verify -q' '
  70        >expect &&
  71        git show-ref --verify -q refs/tags/A >actual &&
  73        test_cmp expect actual &&
  74        test_must_fail git show-ref --verify -q A >actual &&
  76        test_cmp expect actual &&
  77        test_must_fail git show-ref --verify -q tags/A >actual &&
  79        test_cmp expect actual &&
  80        test_must_fail git show-ref --verify -q D >actual &&
  82        test_cmp expect actual
  83'
  84test_expect_success 'show-ref -d' '
  86        {
  87                echo $(git rev-parse refs/tags/A) refs/tags/A &&
  88                echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}"
  89                echo $(git rev-parse refs/tags/C) refs/tags/C
  90        } >expect &&
  91        git show-ref -d A C >actual &&
  92        test_cmp expect actual &&
  93        git show-ref -d tags/A tags/C >actual &&
  95        test_cmp expect actual &&
  96        git show-ref -d refs/tags/A refs/tags/C >actual &&
  98        test_cmp expect actual &&
  99        echo $(git rev-parse refs/heads/master) refs/heads/master >expect &&
 101        git show-ref -d master >actual &&
 102        test_cmp expect actual &&
 103        git show-ref -d heads/master >actual &&
 105        test_cmp expect actual &&
 106        git show-ref -d refs/heads/master >actual &&
 108        test_cmp expect actual &&
 109        git show-ref -d --verify refs/heads/master >actual &&
 111        test_cmp expect actual &&
 112        >expect &&
 114        test_must_fail git show-ref -d --verify master >actual &&
 116        test_cmp expect actual &&
 117        test_must_fail git show-ref -d --verify heads/master >actual &&
 119        test_cmp expect actual
 120'
 122test_expect_success 'show-ref --heads, --tags, --head, pattern' '
 124        for branch in B master side
 125        do
 126                echo $(git rev-parse refs/heads/$branch) refs/heads/$branch
 127        done >expect.heads &&
 128        git show-ref --heads >actual &&
 129        test_cmp expect.heads actual &&
 130        for tag in A B C
 132        do
 133                echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
 134        done >expect.tags &&
 135        git show-ref --tags >actual &&
 136        test_cmp expect.tags actual &&
 137        cat expect.heads expect.tags >expect &&
 139        git show-ref --heads --tags >actual &&
 140        test_cmp expect actual &&
 141        {
 143                echo $(git rev-parse HEAD) HEAD &&
 144                cat expect.heads expect.tags
 145        } >expect &&
 146        git show-ref --heads --tags --head >actual &&
 147        test_cmp expect actual &&
 148        {
 150                echo $(git rev-parse HEAD) HEAD &&
 151                echo $(git rev-parse refs/heads/B) refs/heads/B
 152                echo $(git rev-parse refs/tags/B) refs/tags/B
 153        } >expect &&
 154        git show-ref --head B >actual &&
 155        test_cmp expect actual &&
 156        {
 158                echo $(git rev-parse HEAD) HEAD &&
 159                echo $(git rev-parse refs/heads/B) refs/heads/B
 160                echo $(git rev-parse refs/tags/B) refs/tags/B
 161                echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}"
 162        } >expect &&
 163        git show-ref --head -d B >actual &&
 164        test_cmp expect actual
 165'
 166test_done