]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1403-show-ref.sh
Merge branch 'gc/branch-recurse-submodules-fix'
[thirdparty/git.git] / t / t1403-show-ref.sh
1 #!/bin/sh
2
3 test_description='show-ref'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 test_expect_success setup '
11 test_commit --annotate A &&
12 git checkout -b side &&
13 test_commit --annotate B &&
14 git checkout main &&
15 test_commit C &&
16 git branch B A^0
17 '
18
19 test_expect_success 'show-ref' '
20 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
21
22 git show-ref A >actual &&
23 test_cmp expect actual &&
24
25 git show-ref tags/A >actual &&
26 test_cmp expect actual &&
27
28 git show-ref refs/tags/A >actual &&
29 test_cmp expect actual &&
30
31 test_must_fail git show-ref D >actual &&
32 test_must_be_empty actual
33 '
34
35 test_expect_success 'show-ref -q' '
36 git show-ref -q A >actual &&
37 test_must_be_empty actual &&
38
39 git show-ref -q tags/A >actual &&
40 test_must_be_empty actual &&
41
42 git show-ref -q refs/tags/A >actual &&
43 test_must_be_empty actual &&
44
45 test_must_fail git show-ref -q D >actual &&
46 test_must_be_empty actual
47 '
48
49 test_expect_success 'show-ref --verify' '
50 echo $(git rev-parse refs/tags/A) refs/tags/A >expect &&
51
52 git show-ref --verify refs/tags/A >actual &&
53 test_cmp expect actual &&
54
55 test_must_fail git show-ref --verify A >actual &&
56 test_must_be_empty actual &&
57
58 test_must_fail git show-ref --verify tags/A >actual &&
59 test_must_be_empty actual &&
60
61 test_must_fail git show-ref --verify D >actual &&
62 test_must_be_empty actual
63 '
64
65 test_expect_success 'show-ref --verify -q' '
66 git show-ref --verify -q refs/tags/A >actual &&
67 test_must_be_empty actual &&
68
69 test_must_fail git show-ref --verify -q A >actual &&
70 test_must_be_empty actual &&
71
72 test_must_fail git show-ref --verify -q tags/A >actual &&
73 test_must_be_empty actual &&
74
75 test_must_fail git show-ref --verify -q D >actual &&
76 test_must_be_empty actual
77 '
78
79 test_expect_success 'show-ref -d' '
80 {
81 echo $(git rev-parse refs/tags/A) refs/tags/A &&
82 echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}" &&
83 echo $(git rev-parse refs/tags/C) refs/tags/C
84 } >expect &&
85 git show-ref -d A C >actual &&
86 test_cmp expect actual &&
87
88 git show-ref -d tags/A tags/C >actual &&
89 test_cmp expect actual &&
90
91 git show-ref -d refs/tags/A refs/tags/C >actual &&
92 test_cmp expect actual &&
93
94 git show-ref --verify -d refs/tags/A refs/tags/C >actual &&
95 test_cmp expect actual &&
96
97 echo $(git rev-parse refs/heads/main) refs/heads/main >expect &&
98 git show-ref -d main >actual &&
99 test_cmp expect actual &&
100
101 git show-ref -d heads/main >actual &&
102 test_cmp expect actual &&
103
104 git show-ref -d refs/heads/main >actual &&
105 test_cmp expect actual &&
106
107 git show-ref -d --verify refs/heads/main >actual &&
108 test_cmp expect actual &&
109
110 test_must_fail git show-ref -d --verify main >actual &&
111 test_must_be_empty actual &&
112
113 test_must_fail git show-ref -d --verify heads/main >actual &&
114 test_must_be_empty actual &&
115
116 test_must_fail git show-ref --verify -d A C >actual &&
117 test_must_be_empty actual &&
118
119 test_must_fail git show-ref --verify -d tags/A tags/C >actual &&
120 test_must_be_empty actual
121
122 '
123
124 test_expect_success 'show-ref --heads, --tags, --head, pattern' '
125 for branch in B main side
126 do
127 echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1
128 done >expect.heads &&
129 git show-ref --heads >actual &&
130 test_cmp expect.heads actual &&
131
132 for tag in A B C
133 do
134 echo $(git rev-parse refs/tags/$tag) refs/tags/$tag || return 1
135 done >expect.tags &&
136 git show-ref --tags >actual &&
137 test_cmp expect.tags actual &&
138
139 cat expect.heads expect.tags >expect &&
140 git show-ref --heads --tags >actual &&
141 test_cmp expect actual &&
142
143 {
144 echo $(git rev-parse HEAD) HEAD &&
145 cat expect.heads expect.tags
146 } >expect &&
147 git show-ref --heads --tags --head >actual &&
148 test_cmp expect actual &&
149
150 {
151 echo $(git rev-parse HEAD) HEAD &&
152 echo $(git rev-parse refs/heads/B) refs/heads/B &&
153 echo $(git rev-parse refs/tags/B) refs/tags/B
154 } >expect &&
155 git show-ref --head B >actual &&
156 test_cmp expect actual &&
157
158 {
159 echo $(git rev-parse HEAD) HEAD &&
160 echo $(git rev-parse refs/heads/B) refs/heads/B &&
161 echo $(git rev-parse refs/tags/B) refs/tags/B &&
162 echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}"
163 } >expect &&
164 git show-ref --head -d B >actual &&
165 test_cmp expect actual
166 '
167
168 test_expect_success 'show-ref --verify HEAD' '
169 echo $(git rev-parse HEAD) HEAD >expect &&
170 git show-ref --verify HEAD >actual &&
171 test_cmp expect actual &&
172
173 git show-ref --verify -q HEAD >actual &&
174 test_must_be_empty actual
175 '
176
177 test_expect_success 'show-ref --verify with dangling ref' '
178 sha1_file() {
179 echo "$*" | sed "s#..#.git/objects/&/#"
180 } &&
181
182 remove_object() {
183 file=$(sha1_file "$*") &&
184 test -e "$file" &&
185 rm -f "$file"
186 } &&
187
188 test_when_finished "rm -rf dangling" &&
189 (
190 git init dangling &&
191 cd dangling &&
192 test_commit dangling &&
193 sha=$(git rev-parse refs/tags/dangling) &&
194 remove_object $sha &&
195 test_must_fail git show-ref --verify refs/tags/dangling
196 )
197 '
198
199 test_done