test-lib functions: add an --annotated option to "test_commit"
[alt-git.git] / t / t1403-show-ref.sh
blob17d3cc14050695d42bc19d043e9c3c5f4ab000e4
1 #!/bin/sh
3 test_description='show-ref'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 . ./test-lib.sh
9 test_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
18 test_expect_success 'show-ref' '
19 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
21 git show-ref A >actual &&
22 test_cmp expect actual &&
24 git show-ref tags/A >actual &&
25 test_cmp expect actual &&
27 git show-ref refs/tags/A >actual &&
28 test_cmp expect actual &&
30 test_must_fail git show-ref D >actual &&
31 test_must_be_empty actual
34 test_expect_success 'show-ref -q' '
35 git show-ref -q A >actual &&
36 test_must_be_empty actual &&
38 git show-ref -q tags/A >actual &&
39 test_must_be_empty actual &&
41 git show-ref -q refs/tags/A >actual &&
42 test_must_be_empty actual &&
44 test_must_fail git show-ref -q D >actual &&
45 test_must_be_empty actual
48 test_expect_success 'show-ref --verify' '
49 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
51 git show-ref --verify refs/tags/A >actual &&
52 test_cmp expect actual &&
54 test_must_fail git show-ref --verify A >actual &&
55 test_must_be_empty actual &&
57 test_must_fail git show-ref --verify tags/A >actual &&
58 test_must_be_empty actual &&
60 test_must_fail git show-ref --verify D >actual &&
61 test_must_be_empty actual
64 test_expect_success 'show-ref --verify -q' '
65 git show-ref --verify -q refs/tags/A >actual &&
66 test_must_be_empty actual &&
68 test_must_fail git show-ref --verify -q A >actual &&
69 test_must_be_empty actual &&
71 test_must_fail git show-ref --verify -q tags/A >actual &&
72 test_must_be_empty actual &&
74 test_must_fail git show-ref --verify -q D >actual &&
75 test_must_be_empty actual
78 test_expect_success 'show-ref -d' '
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 &&
87 git show-ref -d tags/A tags/C >actual &&
88 test_cmp expect actual &&
90 git show-ref -d refs/tags/A refs/tags/C >actual &&
91 test_cmp expect actual &&
93 git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
94 test_cmp expect actual &&
96 echo $(git rev-parse refs/heads/main) refs/heads/main >expect &&
97 git show-ref -d main >actual &&
98 test_cmp expect actual &&
100 git show-ref -d heads/main >actual &&
101 test_cmp expect actual &&
103 git show-ref -d refs/heads/main >actual &&
104 test_cmp expect actual &&
106 git show-ref -d --verify refs/heads/main >actual &&
107 test_cmp expect actual &&
109 test_must_fail git show-ref -d --verify main >actual &&
110 test_must_be_empty actual &&
112 test_must_fail git show-ref -d --verify heads/main >actual &&
113 test_must_be_empty actual &&
115 test_must_fail git show-ref --verify -d A C >actual &&
116 test_must_be_empty actual &&
118 test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
119 test_must_be_empty actual
123 test_expect_success 'show-ref --heads, --tags, --head, pattern' '
124 for branch in B main side
126 echo $(git rev-parse refs/heads/$branch) refs/heads/$branch
127 done >expect.heads &&
128 git show-ref --heads >actual &&
129 test_cmp expect.heads actual &&
131 for tag in A B C
133 echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
134 done >expect.tags &&
135 git show-ref --tags >actual &&
136 test_cmp expect.tags actual &&
138 cat expect.heads expect.tags >expect &&
139 git show-ref --heads --tags >actual &&
140 test_cmp expect actual &&
143 echo $(git rev-parse HEAD) HEAD &&
144 cat expect.heads expect.tags
145 } >expect &&
146 git show-ref --heads --tags --head >actual &&
147 test_cmp expect actual &&
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 &&
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
167 test_expect_success 'show-ref --verify HEAD' '
168 echo $(git rev-parse HEAD) HEAD >expect &&
169 git show-ref --verify HEAD >actual &&
170 test_cmp expect actual &&
172 git show-ref --verify -q HEAD >actual &&
173 test_must_be_empty actual
176 test_expect_success 'show-ref --verify with dangling ref' '
177 sha1_file() {
178 echo "$*" | sed "s#..#.git/objects/&/#"
179 } &&
181 remove_object() {
182 file=$(sha1_file "$*") &&
183 test -e "$file" &&
184 rm -f "$file"
185 } &&
187 test_when_finished "rm -rf dangling" &&
189 git init dangling &&
190 cd dangling &&
191 test_commit dangling &&
192 sha=$(git rev-parse refs/tags/dangling) &&
193 remove_object $sha &&
194 test_must_fail git show-ref --verify refs/tags/dangling
198 test_done