Fourth batch
[git/raj.git] / t / t1403-show-ref.sh
blob5d955c3bff2ce9c276acd363f7c906565333da79
1 #!/bin/sh
3 test_description='show-ref'
4 . ./test-lib.sh
6 test_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
17 test_expect_success 'show-ref' '
18 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
20 git show-ref A >actual &&
21 test_cmp expect actual &&
23 git show-ref tags/A >actual &&
24 test_cmp expect actual &&
26 git show-ref refs/tags/A >actual &&
27 test_cmp expect actual &&
29 test_must_fail git show-ref D >actual &&
30 test_must_be_empty actual
33 test_expect_success 'show-ref -q' '
34 git show-ref -q A >actual &&
35 test_must_be_empty actual &&
37 git show-ref -q tags/A >actual &&
38 test_must_be_empty actual &&
40 git show-ref -q refs/tags/A >actual &&
41 test_must_be_empty actual &&
43 test_must_fail git show-ref -q D >actual &&
44 test_must_be_empty actual
47 test_expect_success 'show-ref --verify' '
48 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
50 git show-ref --verify refs/tags/A >actual &&
51 test_cmp expect actual &&
53 test_must_fail git show-ref --verify A >actual &&
54 test_must_be_empty actual &&
56 test_must_fail git show-ref --verify tags/A >actual &&
57 test_must_be_empty actual &&
59 test_must_fail git show-ref --verify D >actual &&
60 test_must_be_empty actual
63 test_expect_success 'show-ref --verify -q' '
64 git show-ref --verify -q refs/tags/A >actual &&
65 test_must_be_empty actual &&
67 test_must_fail git show-ref --verify -q A >actual &&
68 test_must_be_empty actual &&
70 test_must_fail git show-ref --verify -q tags/A >actual &&
71 test_must_be_empty actual &&
73 test_must_fail git show-ref --verify -q D >actual &&
74 test_must_be_empty actual
77 test_expect_success 'show-ref -d' '
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 &&
86 git show-ref -d tags/A tags/C >actual &&
87 test_cmp expect actual &&
89 git show-ref -d refs/tags/A refs/tags/C >actual &&
90 test_cmp expect actual &&
92 git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
93 test_cmp expect actual &&
95 echo $(git rev-parse refs/heads/master) refs/heads/master >expect &&
96 git show-ref -d master >actual &&
97 test_cmp expect actual &&
99 git show-ref -d heads/master >actual &&
100 test_cmp expect actual &&
102 git show-ref -d refs/heads/master >actual &&
103 test_cmp expect actual &&
105 git show-ref -d --verify refs/heads/master >actual &&
106 test_cmp expect actual &&
108 test_must_fail git show-ref -d --verify master >actual &&
109 test_must_be_empty actual &&
111 test_must_fail git show-ref -d --verify heads/master >actual &&
112 test_must_be_empty actual &&
114 test_must_fail git show-ref --verify -d A C >actual &&
115 test_must_be_empty actual &&
117 test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
118 test_must_be_empty actual
122 test_expect_success 'show-ref --heads, --tags, --head, pattern' '
123 for branch in B master side
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 &&
130 for tag in A B C
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 &&
137 cat expect.heads expect.tags >expect &&
138 git show-ref --heads --tags >actual &&
139 test_cmp expect actual &&
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 &&
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 &&
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
166 test_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 &&
171 git show-ref --verify -q HEAD >actual &&
172 test_must_be_empty actual
175 test_expect_success 'show-ref --verify with dangling ref' '
176 sha1_file() {
177 echo "$*" | sed "s#..#.git/objects/&/#"
178 } &&
180 remove_object() {
181 file=$(sha1_file "$*") &&
182 test -e "$file" &&
183 rm -f "$file"
184 } &&
186 test_when_finished "rm -rf dangling" &&
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
197 test_done