Merge branch 'ab/test-lib'
[git/debian.git] / t / t1403-show-ref.sh
blob6ce62f878c358dbfec9223c1857a0168e2806e96
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 A &&
11 git tag -f -a -m "annotated A" A &&
12 git checkout -b side &&
13 test_commit B &&
14 git tag -f -a -m "annotated B" B &&
15 git checkout main &&
16 test_commit C &&
17 git branch B A^0
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
85 } >expect &&
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 &&
133 for tag in A B C
135 echo $(git rev-parse refs/tags/$tag) refs/tags/$tag
136 done >expect.tags &&
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
147 } >expect &&
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
155 } >expect &&
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^{}"
164 } >expect &&
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' '
179 sha1_file() {
180 echo "$*" | sed "s#..#.git/objects/&/#"
181 } &&
183 remove_object() {
184 file=$(sha1_file "$*") &&
185 test -e "$file" &&
186 rm -f "$file"
187 } &&
189 test_when_finished "rm -rf dangling" &&
191 git init dangling &&
192 cd 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
200 test_done