t / t1403-show-ref.shon commit Merge branch 'ew/fd-cloexec-fix' (2842e06)
   1#!/bin/sh
   2
   3test_description='show-ref'
   4. ./test-lib.sh
   5
   6test_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'
  16
  17test_expect_success 'show-ref' '
  18        echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
  19
  20        git show-ref A >actual &&
  21        test_cmp expect actual &&
  22
  23        git show-ref tags/A >actual &&
  24        test_cmp expect actual &&
  25
  26        git show-ref refs/tags/A >actual &&
  27        test_cmp expect actual &&
  28
  29        >expect &&
  30
  31        test_must_fail git show-ref D >actual &&
  32        test_cmp expect actual
  33'
  34
  35test_expect_success 'show-ref -q' '
  36        >expect &&
  37
  38        git show-ref -q A >actual &&
  39        test_cmp expect actual &&
  40
  41        git show-ref -q tags/A >actual &&
  42        test_cmp expect actual &&
  43
  44        git show-ref -q refs/tags/A >actual &&
  45        test_cmp expect actual &&
  46
  47        test_must_fail git show-ref -q D >actual &&
  48        test_cmp expect actual
  49'
  50
  51test_expect_success 'show-ref --verify' '
  52        echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
  53
  54        git show-ref --verify refs/tags/A >actual &&
  55        test_cmp expect actual &&
  56
  57        >expect &&
  58
  59        test_must_fail git show-ref --verify A >actual &&
  60        test_cmp expect actual &&
  61
  62        test_must_fail git show-ref --verify tags/A >actual &&
  63        test_cmp expect actual &&
  64
  65        test_must_fail git show-ref --verify D >actual &&
  66        test_cmp expect actual
  67'
  68
  69test_expect_success 'show-ref --verify -q' '
  70        >expect &&
  71
  72        git show-ref --verify -q refs/tags/A >actual &&
  73        test_cmp expect actual &&
  74
  75        test_must_fail git show-ref --verify -q A >actual &&
  76        test_cmp expect actual &&
  77
  78        test_must_fail git show-ref --verify -q tags/A >actual &&
  79        test_cmp expect actual &&
  80
  81        test_must_fail git show-ref --verify -q D >actual &&
  82        test_cmp expect actual
  83'
  84
  85test_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
  94        git show-ref -d tags/A tags/C >actual &&
  95        test_cmp expect actual &&
  96
  97        git show-ref -d refs/tags/A refs/tags/C >actual &&
  98        test_cmp expect actual &&
  99
 100        git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
 101        test_cmp expect actual &&
 102
 103        echo $(git rev-parse refs/heads/master) refs/heads/master >expect &&
 104        git show-ref -d master >actual &&
 105        test_cmp expect actual &&
 106
 107        git show-ref -d heads/master >actual &&
 108        test_cmp expect actual &&
 109
 110        git show-ref -d refs/heads/master >actual &&
 111        test_cmp expect actual &&
 112
 113        git show-ref -d --verify refs/heads/master >actual &&
 114        test_cmp expect actual &&
 115
 116        >expect &&
 117
 118        test_must_fail git show-ref -d --verify master >actual &&
 119        test_cmp expect actual &&
 120
 121        test_must_fail git show-ref -d --verify heads/master >actual &&
 122        test_cmp expect actual &&
 123
 124        test_must_fail git show-ref --verify -d A C >actual &&
 125        test_cmp expect actual &&
 126
 127        test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
 128        test_cmp expect actual
 129
 130'
 131
 132test_expect_success 'show-ref --heads, --tags, --head, pattern' '
 133        for branch in B master side
 134        do
 135                echo $(git rev-parse refs/heads/$branch) refs/heads/$branch
 136        done >expect.heads &&
 137        git show-ref --heads >actual &&
 138        test_cmp expect.heads actual &&
 139
 140        for tag in A B C
 141        do
 142                echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
 143        done >expect.tags &&
 144        git show-ref --tags >actual &&
 145        test_cmp expect.tags actual &&
 146
 147        cat expect.heads expect.tags >expect &&
 148        git show-ref --heads --tags >actual &&
 149        test_cmp expect actual &&
 150
 151        {
 152                echo $(git rev-parse HEAD) HEAD &&
 153                cat expect.heads expect.tags
 154        } >expect &&
 155        git show-ref --heads --tags --head >actual &&
 156        test_cmp expect actual &&
 157
 158        {
 159                echo $(git rev-parse HEAD) HEAD &&
 160                echo $(git rev-parse refs/heads/B) refs/heads/B
 161                echo $(git rev-parse refs/tags/B) refs/tags/B
 162        } >expect &&
 163        git show-ref --head B >actual &&
 164        test_cmp expect actual &&
 165
 166        {
 167                echo $(git rev-parse HEAD) HEAD &&
 168                echo $(git rev-parse refs/heads/B) refs/heads/B
 169                echo $(git rev-parse refs/tags/B) refs/tags/B
 170                echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}"
 171        } >expect &&
 172        git show-ref --head -d B >actual &&
 173        test_cmp expect actual
 174'
 175
 176test_expect_success 'show-ref --verify HEAD' '
 177        echo $(git rev-parse HEAD) HEAD >expect &&
 178        git show-ref --verify HEAD >actual &&
 179        test_cmp expect actual &&
 180
 181        >expect &&
 182
 183        git show-ref --verify -q HEAD >actual &&
 184        test_cmp expect actual
 185'
 186
 187test_expect_success 'show-ref --verify with dangling ref' '
 188        sha1_file() {
 189                echo "$*" | sed "s#..#.git/objects/&/#"
 190        } &&
 191
 192        remove_object() {
 193                file=$(sha1_file "$*") &&
 194                test -e "$file" &&
 195                rm -f "$file"
 196        } &&
 197
 198        test_when_finished "rm -rf dangling" &&
 199        (
 200                git init dangling &&
 201                cd dangling &&
 202                test_commit dangling &&
 203                sha=$(git rev-parse refs/tags/dangling) &&
 204                remove_object $sha &&
 205                test_must_fail git show-ref --verify refs/tags/dangling
 206        )
 207'
 208
 209test_done