t / t1403-show-ref.shon commit trace2: use system/global config for default trace2 settings (bce9db6)
   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        test_must_fail git show-ref D >actual &&
  30        test_must_be_empty actual
  31'
  32
  33test_expect_success 'show-ref -q' '
  34        git show-ref -q A >actual &&
  35        test_must_be_empty actual &&
  36
  37        git show-ref -q tags/A >actual &&
  38        test_must_be_empty actual &&
  39
  40        git show-ref -q refs/tags/A >actual &&
  41        test_must_be_empty actual &&
  42
  43        test_must_fail git show-ref -q D >actual &&
  44        test_must_be_empty actual
  45'
  46
  47test_expect_success 'show-ref --verify' '
  48        echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
  49
  50        git show-ref --verify refs/tags/A >actual &&
  51        test_cmp expect actual &&
  52
  53        test_must_fail git show-ref --verify A >actual &&
  54        test_must_be_empty actual &&
  55
  56        test_must_fail git show-ref --verify tags/A >actual &&
  57        test_must_be_empty actual &&
  58
  59        test_must_fail git show-ref --verify D >actual &&
  60        test_must_be_empty actual
  61'
  62
  63test_expect_success 'show-ref --verify -q' '
  64        git show-ref --verify -q refs/tags/A >actual &&
  65        test_must_be_empty actual &&
  66
  67        test_must_fail git show-ref --verify -q A >actual &&
  68        test_must_be_empty actual &&
  69
  70        test_must_fail git show-ref --verify -q tags/A >actual &&
  71        test_must_be_empty actual &&
  72
  73        test_must_fail git show-ref --verify -q D >actual &&
  74        test_must_be_empty actual
  75'
  76
  77test_expect_success 'show-ref -d' '
  78        {
  79                echo $(git rev-parse refs/tags/A) refs/tags/A &&
  80                echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}"
  81                echo $(git rev-parse refs/tags/C) refs/tags/C
  82        } >expect &&
  83        git show-ref -d A C >actual &&
  84        test_cmp expect actual &&
  85
  86        git show-ref -d tags/A tags/C >actual &&
  87        test_cmp expect actual &&
  88
  89        git show-ref -d refs/tags/A refs/tags/C >actual &&
  90        test_cmp expect actual &&
  91
  92        git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
  93        test_cmp expect actual &&
  94
  95        echo $(git rev-parse refs/heads/master) refs/heads/master >expect &&
  96        git show-ref -d master >actual &&
  97        test_cmp expect actual &&
  98
  99        git show-ref -d heads/master >actual &&
 100        test_cmp expect actual &&
 101
 102        git show-ref -d refs/heads/master >actual &&
 103        test_cmp expect actual &&
 104
 105        git show-ref -d --verify refs/heads/master >actual &&
 106        test_cmp expect actual &&
 107
 108        test_must_fail git show-ref -d --verify master >actual &&
 109        test_must_be_empty actual &&
 110
 111        test_must_fail git show-ref -d --verify heads/master >actual &&
 112        test_must_be_empty actual &&
 113
 114        test_must_fail git show-ref --verify -d A C >actual &&
 115        test_must_be_empty actual &&
 116
 117        test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
 118        test_must_be_empty actual
 119
 120'
 121
 122test_expect_success 'show-ref --heads, --tags, --head, pattern' '
 123        for branch in B master side
 124        do
 125                echo $(git rev-parse refs/heads/$branch) refs/heads/$branch
 126        done >expect.heads &&
 127        git show-ref --heads >actual &&
 128        test_cmp expect.heads actual &&
 129
 130        for tag in A B C
 131        do
 132                echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
 133        done >expect.tags &&
 134        git show-ref --tags >actual &&
 135        test_cmp expect.tags actual &&
 136
 137        cat expect.heads expect.tags >expect &&
 138        git show-ref --heads --tags >actual &&
 139        test_cmp expect actual &&
 140
 141        {
 142                echo $(git rev-parse HEAD) HEAD &&
 143                cat expect.heads expect.tags
 144        } >expect &&
 145        git show-ref --heads --tags --head >actual &&
 146        test_cmp expect actual &&
 147
 148        {
 149                echo $(git rev-parse HEAD) HEAD &&
 150                echo $(git rev-parse refs/heads/B) refs/heads/B
 151                echo $(git rev-parse refs/tags/B) refs/tags/B
 152        } >expect &&
 153        git show-ref --head B >actual &&
 154        test_cmp expect actual &&
 155
 156        {
 157                echo $(git rev-parse HEAD) HEAD &&
 158                echo $(git rev-parse refs/heads/B) refs/heads/B
 159                echo $(git rev-parse refs/tags/B) refs/tags/B
 160                echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}"
 161        } >expect &&
 162        git show-ref --head -d B >actual &&
 163        test_cmp expect actual
 164'
 165
 166test_expect_success 'show-ref --verify HEAD' '
 167        echo $(git rev-parse HEAD) HEAD >expect &&
 168        git show-ref --verify HEAD >actual &&
 169        test_cmp expect actual &&
 170
 171        git show-ref --verify -q HEAD >actual &&
 172        test_must_be_empty actual
 173'
 174
 175test_expect_success 'show-ref --verify with dangling ref' '
 176        sha1_file() {
 177                echo "$*" | sed "s#..#.git/objects/&/#"
 178        } &&
 179
 180        remove_object() {
 181                file=$(sha1_file "$*") &&
 182                test -e "$file" &&
 183                rm -f "$file"
 184        } &&
 185
 186        test_when_finished "rm -rf dangling" &&
 187        (
 188                git init dangling &&
 189                cd dangling &&
 190                test_commit dangling &&
 191                sha=$(git rev-parse refs/tags/dangling) &&
 192                remove_object $sha &&
 193                test_must_fail git show-ref --verify refs/tags/dangling
 194        )
 195'
 196
 197test_done