3 test_description
='show-ref'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 test_expect_success setup
'
11 git tag -f -a -m "annotated A" A &&
12 git checkout -b side &&
14 git tag -f -a -m "annotated B" B &&
20 test_expect_success
'show-ref' '
21 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
23 git show-ref A >actual &&
24 test_cmp expect actual &&
26 git show-ref tags/A >actual &&
27 test_cmp expect actual &&
29 git show-ref refs/tags/A >actual &&
30 test_cmp expect actual &&
32 test_must_fail git show-ref D >actual &&
33 test_must_be_empty actual
36 test_expect_success
'show-ref -q' '
37 git show-ref -q A >actual &&
38 test_must_be_empty actual &&
40 git show-ref -q tags/A >actual &&
41 test_must_be_empty actual &&
43 git show-ref -q refs/tags/A >actual &&
44 test_must_be_empty actual &&
46 test_must_fail git show-ref -q D >actual &&
47 test_must_be_empty actual
50 test_expect_success
'show-ref --verify' '
51 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
53 git show-ref --verify refs/tags/A >actual &&
54 test_cmp expect actual &&
56 test_must_fail git show-ref --verify A >actual &&
57 test_must_be_empty actual &&
59 test_must_fail git show-ref --verify tags/A >actual &&
60 test_must_be_empty actual &&
62 test_must_fail git show-ref --verify D >actual &&
63 test_must_be_empty actual
66 test_expect_success
'show-ref --verify -q' '
67 git show-ref --verify -q refs/tags/A >actual &&
68 test_must_be_empty actual &&
70 test_must_fail git show-ref --verify -q A >actual &&
71 test_must_be_empty actual &&
73 test_must_fail git show-ref --verify -q tags/A >actual &&
74 test_must_be_empty actual &&
76 test_must_fail git show-ref --verify -q D >actual &&
77 test_must_be_empty actual
80 test_expect_success
'show-ref -d' '
82 echo $(git rev-parse refs/tags/A) refs/tags/A &&
83 echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}"
84 echo $(git rev-parse refs/tags/C) refs/tags/C
86 git show-ref -d A C >actual &&
87 test_cmp expect actual &&
89 git show-ref -d tags/A tags/C >actual &&
90 test_cmp expect actual &&
92 git show-ref -d refs/tags/A refs/tags/C >actual &&
93 test_cmp expect actual &&
95 git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
96 test_cmp expect actual &&
98 echo $(git rev-parse refs/heads/main) refs/heads/main >expect &&
99 git show-ref -d main >actual &&
100 test_cmp expect actual &&
102 git show-ref -d heads/main >actual &&
103 test_cmp expect actual &&
105 git show-ref -d refs/heads/main >actual &&
106 test_cmp expect actual &&
108 git show-ref -d --verify refs/heads/main >actual &&
109 test_cmp expect actual &&
111 test_must_fail git show-ref -d --verify main >actual &&
112 test_must_be_empty actual &&
114 test_must_fail git show-ref -d --verify heads/main >actual &&
115 test_must_be_empty actual &&
117 test_must_fail git show-ref --verify -d A C >actual &&
118 test_must_be_empty actual &&
120 test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
121 test_must_be_empty actual
125 test_expect_success
'show-ref --heads, --tags, --head, pattern' '
126 for branch in B main side
128 echo $(git rev-parse refs/heads/$branch) refs/heads/$branch
129 done >expect.heads &&
130 git show-ref --heads >actual &&
131 test_cmp expect.heads actual &&
135 echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
137 git show-ref --tags >actual &&
138 test_cmp expect.tags actual &&
140 cat expect.heads expect.tags >expect &&
141 git show-ref --heads --tags >actual &&
142 test_cmp expect actual &&
145 echo $(git rev-parse HEAD) HEAD &&
146 cat expect.heads expect.tags
148 git show-ref --heads --tags --head >actual &&
149 test_cmp expect actual &&
152 echo $(git rev-parse HEAD) HEAD &&
153 echo $(git rev-parse refs/heads/B) refs/heads/B
154 echo $(git rev-parse refs/tags/B) refs/tags/B
156 git show-ref --head B >actual &&
157 test_cmp expect actual &&
160 echo $(git rev-parse HEAD) HEAD &&
161 echo $(git rev-parse refs/heads/B) refs/heads/B
162 echo $(git rev-parse refs/tags/B) refs/tags/B
163 echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}"
165 git show-ref --head -d B >actual &&
166 test_cmp expect actual
169 test_expect_success
'show-ref --verify HEAD' '
170 echo $(git rev-parse HEAD) HEAD >expect &&
171 git show-ref --verify HEAD >actual &&
172 test_cmp expect actual &&
174 git show-ref --verify -q HEAD >actual &&
175 test_must_be_empty actual
178 test_expect_success
'show-ref --verify with dangling ref' '
180 echo "$*" | sed "s#..#.git/objects/&/#"
184 file=$(sha1_file "$*") &&
189 test_when_finished "rm -rf dangling" &&
193 test_commit dangling &&
194 sha=$(git rev-parse refs/tags/dangling) &&
195 remove_object $sha &&
196 test_must_fail git show-ref --verify refs/tags/dangling