Git fork
1#!/bin/sh
2
3test_description='show-ref'
4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7. ./test-lib.sh
8
9test_expect_success setup '
10 test_commit --annotate A &&
11 git checkout -b side &&
12 test_commit --annotate B &&
13 git checkout main &&
14 test_commit C &&
15 git branch B A^0
16'
17
18test_expect_success 'show-ref' '
19 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
20
21 git show-ref A >actual &&
22 test_cmp expect actual &&
23
24 git show-ref tags/A >actual &&
25 test_cmp expect actual &&
26
27 git show-ref refs/tags/A >actual &&
28 test_cmp expect actual &&
29
30 test_must_fail git show-ref D >actual &&
31 test_must_be_empty actual
32'
33
34test_expect_success 'show-ref -q' '
35 git show-ref -q A >actual &&
36 test_must_be_empty actual &&
37
38 git show-ref -q tags/A >actual &&
39 test_must_be_empty actual &&
40
41 git show-ref -q refs/tags/A >actual &&
42 test_must_be_empty actual &&
43
44 test_must_fail git show-ref -q D >actual &&
45 test_must_be_empty actual
46'
47
48test_expect_success 'show-ref --verify' '
49 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
50
51 git show-ref --verify refs/tags/A >actual &&
52 test_cmp expect actual &&
53
54 test_must_fail git show-ref --verify A >actual &&
55 test_must_be_empty actual &&
56
57 test_must_fail git show-ref --verify tags/A >actual &&
58 test_must_be_empty actual &&
59
60 test_must_fail git show-ref --verify D >actual &&
61 test_must_be_empty actual
62'
63
64test_expect_success 'show-ref --verify -q' '
65 git show-ref --verify -q refs/tags/A >actual &&
66 test_must_be_empty actual &&
67
68 test_must_fail git show-ref --verify -q A >actual &&
69 test_must_be_empty actual &&
70
71 test_must_fail git show-ref --verify -q tags/A >actual &&
72 test_must_be_empty actual &&
73
74 test_must_fail git show-ref --verify -q D >actual &&
75 test_must_be_empty actual
76'
77
78test_expect_success 'show-ref -d' '
79 {
80 echo $(git rev-parse refs/tags/A) refs/tags/A &&
81 echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}" &&
82 echo $(git rev-parse refs/tags/C) refs/tags/C
83 } >expect &&
84 git show-ref -d A C >actual &&
85 test_cmp expect actual &&
86
87 git show-ref -d tags/A tags/C >actual &&
88 test_cmp expect actual &&
89
90 git show-ref -d refs/tags/A refs/tags/C >actual &&
91 test_cmp expect actual &&
92
93 git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
94 test_cmp expect actual &&
95
96 echo $(git rev-parse refs/heads/main) refs/heads/main >expect &&
97 git show-ref -d main >actual &&
98 test_cmp expect actual &&
99
100 git show-ref -d heads/main >actual &&
101 test_cmp expect actual &&
102
103 git show-ref -d refs/heads/main >actual &&
104 test_cmp expect actual &&
105
106 git show-ref -d --verify refs/heads/main >actual &&
107 test_cmp expect actual &&
108
109 test_must_fail git show-ref -d --verify main >actual &&
110 test_must_be_empty actual &&
111
112 test_must_fail git show-ref -d --verify heads/main >actual &&
113 test_must_be_empty actual &&
114
115 test_must_fail git show-ref --verify -d A C >actual &&
116 test_must_be_empty actual &&
117
118 test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
119 test_must_be_empty actual
120
121'
122
123test_expect_success 'show-ref --branches, --tags, --head, pattern' '
124 for branch in B main side
125 do
126 echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1
127 done >expect.branches &&
128 git show-ref --branches >actual &&
129 test_cmp expect.branches actual &&
130
131 for tag in A B C
132 do
133 echo $(git rev-parse refs/tags/$tag) refs/tags/$tag || return 1
134 done >expect.tags &&
135 git show-ref --tags >actual &&
136 test_cmp expect.tags actual &&
137
138 cat expect.branches expect.tags >expect &&
139 git show-ref --branches --tags >actual &&
140 test_cmp expect actual &&
141
142 {
143 echo $(git rev-parse HEAD) HEAD &&
144 cat expect.branches expect.tags
145 } >expect &&
146 git show-ref --branches --tags --head >actual &&
147 test_cmp expect actual &&
148
149 {
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
157 {
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'
166
167test_expect_success 'show-ref --heads is deprecated and hidden' '
168 test_expect_code 129 git show-ref -h >short-help &&
169 test_grep ! -e --heads short-help &&
170 git show-ref --heads >actual 2>warning &&
171 test_grep ! deprecated warning &&
172 test_cmp expect.branches actual
173'
174
175test_expect_success 'show-ref --verify HEAD' '
176 echo $(git rev-parse HEAD) HEAD >expect &&
177 git show-ref --verify HEAD >actual &&
178 test_cmp expect actual &&
179
180 git show-ref --verify -q HEAD >actual &&
181 test_must_be_empty actual
182'
183
184test_expect_success 'show-ref --verify pseudorefs' '
185 git update-ref CHERRY_PICK_HEAD HEAD $ZERO_OID &&
186 test_when_finished "git update-ref -d CHERRY_PICK_HEAD" &&
187 git show-ref -s --verify HEAD >actual &&
188 git show-ref -s --verify CHERRY_PICK_HEAD >expect &&
189 test_cmp actual expect
190'
191
192test_expect_success 'show-ref --verify with dangling ref' '
193 sha1_file() {
194 echo "$*" | sed "s#..#.git/objects/&/#"
195 } &&
196
197 remove_object() {
198 file=$(sha1_file "$*") &&
199 test_path_is_file "$file" &&
200 rm -f "$file"
201 } &&
202
203 test_when_finished "rm -rf dangling" &&
204 (
205 git init dangling &&
206 cd dangling &&
207 test_commit dangling &&
208 sha=$(git rev-parse refs/tags/dangling) &&
209 remove_object $sha &&
210 test_must_fail git show-ref --verify refs/tags/dangling
211 )
212'
213
214test_expect_success 'show-ref sub-modes are mutually exclusive' '
215 test_must_fail git show-ref --verify --exclude-existing 2>err &&
216 grep "verify" err &&
217 grep "exclude-existing" err &&
218 grep "cannot be used together" err &&
219
220 test_must_fail git show-ref --verify --exists 2>err &&
221 grep "verify" err &&
222 grep "exists" err &&
223 grep "cannot be used together" err &&
224
225 test_must_fail git show-ref --exclude-existing --exists 2>err &&
226 grep "exclude-existing" err &&
227 grep "exists" err &&
228 grep "cannot be used together" err
229'
230
231test_done