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