]>
Commit | Line | Data |
---|---|---|
d08bae7e IL |
1 | #!/bin/sh |
2 | ||
3 | test_description='rev-list/rev-parse --glob' | |
4 | ||
1550bb6e | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
7a98d9ab | 8 | TEST_PASSES_SANITIZE_LEAK=true |
d08bae7e IL |
9 | . ./test-lib.sh |
10 | ||
11 | commit () { | |
12 | test_tick && | |
13 | echo $1 > foo && | |
14 | git add foo && | |
15 | git commit -m "$1" | |
16 | } | |
17 | ||
18 | compare () { | |
19 | # Split arguments on whitespace. | |
20 | git $1 $2 >expected && | |
21 | git $1 $3 >actual && | |
22 | test_cmp expected actual | |
23 | } | |
24 | ||
25 | test_expect_success 'setup' ' | |
26 | ||
1550bb6e JS |
27 | commit main && |
28 | git checkout -b subspace/one main && | |
d08bae7e | 29 | commit one && |
1550bb6e | 30 | git checkout -b subspace/two main && |
d08bae7e | 31 | commit two && |
1550bb6e | 32 | git checkout -b subspace-x main && |
d08bae7e | 33 | commit subspace-x && |
1550bb6e | 34 | git checkout -b other/three main && |
d08bae7e | 35 | commit three && |
1550bb6e | 36 | git checkout -b someref main && |
d08bae7e | 37 | commit some && |
1550bb6e | 38 | git checkout main && |
b6211b89 | 39 | commit topic_2 && |
1550bb6e | 40 | git tag foo/bar main && |
b6211b89 | 41 | commit topic_3 && |
1550bb6e | 42 | git update-ref refs/remotes/foo/baz main && |
b6211b89 | 43 | commit topic_4 && |
9d55dca2 RA |
44 | git update-ref refs/remotes/upstream/one subspace/one && |
45 | git update-ref refs/remotes/upstream/two subspace/two && | |
46 | git update-ref refs/remotes/upstream/x subspace-x && | |
47 | git tag qux/one subspace/one && | |
48 | git tag qux/two subspace/two && | |
49 | git tag qux/x subspace-x | |
d08bae7e IL |
50 | ' |
51 | ||
52 | test_expect_success 'rev-parse --glob=refs/heads/subspace/*' ' | |
53 | ||
54 | compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/*" | |
55 | ||
56 | ' | |
57 | ||
58 | test_expect_success 'rev-parse --glob=heads/subspace/*' ' | |
59 | ||
60 | compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/*" | |
61 | ||
62 | ' | |
63 | ||
64 | test_expect_success 'rev-parse --glob=refs/heads/subspace/' ' | |
65 | ||
66 | compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/" | |
67 | ||
68 | ' | |
69 | ||
70 | test_expect_success 'rev-parse --glob=heads/subspace/' ' | |
71 | ||
72 | compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/" | |
73 | ||
74 | ' | |
75 | ||
76 | test_expect_success 'rev-parse --glob=heads/subspace' ' | |
77 | ||
78 | compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace" | |
79 | ||
80 | ' | |
81 | ||
0fc63ec4 JN |
82 | test_expect_failure 'rev-parse accepts --glob as detached option' ' |
83 | ||
84 | compare rev-parse "subspace/one subspace/two" "--glob heads/subspace" | |
85 | ||
86 | ' | |
87 | ||
88 | test_expect_failure 'rev-parse is not confused by option-like glob' ' | |
89 | ||
1550bb6e | 90 | compare rev-parse "main" "--glob --symbolic main" |
0fc63ec4 JN |
91 | |
92 | ' | |
93 | ||
b09fe971 IL |
94 | test_expect_success 'rev-parse --branches=subspace/*' ' |
95 | ||
96 | compare rev-parse "subspace/one subspace/two" "--branches=subspace/*" | |
97 | ||
98 | ' | |
99 | ||
100 | test_expect_success 'rev-parse --branches=subspace/' ' | |
101 | ||
102 | compare rev-parse "subspace/one subspace/two" "--branches=subspace/" | |
103 | ||
104 | ' | |
105 | ||
106 | test_expect_success 'rev-parse --branches=subspace' ' | |
107 | ||
108 | compare rev-parse "subspace/one subspace/two" "--branches=subspace" | |
109 | ||
110 | ' | |
111 | ||
d08bae7e IL |
112 | test_expect_success 'rev-parse --glob=heads/subspace/* --glob=heads/other/*' ' |
113 | ||
114 | compare rev-parse "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*" | |
115 | ||
116 | ' | |
117 | ||
1550bb6e | 118 | test_expect_success 'rev-parse --glob=heads/someref/* main' ' |
d08bae7e | 119 | |
1550bb6e | 120 | compare rev-parse "main" "--glob=heads/someref/* main" |
d08bae7e IL |
121 | |
122 | ' | |
123 | ||
124 | test_expect_success 'rev-parse --glob=heads/*' ' | |
125 | ||
1550bb6e | 126 | compare rev-parse "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*" |
d08bae7e IL |
127 | |
128 | ' | |
129 | ||
b09fe971 IL |
130 | test_expect_success 'rev-parse --tags=foo' ' |
131 | ||
132 | compare rev-parse "foo/bar" "--tags=foo" | |
133 | ||
134 | ' | |
135 | ||
136 | test_expect_success 'rev-parse --remotes=foo' ' | |
137 | ||
138 | compare rev-parse "foo/baz" "--remotes=foo" | |
139 | ||
140 | ' | |
141 | ||
9dc01bf0 | 142 | test_expect_success 'rev-parse --exclude with --branches' ' |
1550bb6e | 143 | compare rev-parse "--exclude=*/* --branches" "main someref subspace-x" |
9dc01bf0 JH |
144 | ' |
145 | ||
146 | test_expect_success 'rev-parse --exclude with --all' ' | |
147 | compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags" | |
148 | ' | |
149 | ||
150 | test_expect_success 'rev-parse accumulates multiple --exclude' ' | |
151 | compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches | |
152 | ' | |
153 | ||
52210480 AG |
154 | test_expect_success 'rev-parse --branches clears --exclude' ' |
155 | compare rev-parse "--exclude=* --branches --branches" "--branches" | |
156 | ' | |
157 | ||
158 | test_expect_success 'rev-parse --tags clears --exclude' ' | |
159 | compare rev-parse "--exclude=* --tags --tags" "--tags" | |
160 | ' | |
161 | ||
162 | test_expect_success 'rev-parse --all clears --exclude' ' | |
163 | compare rev-parse "--exclude=* --all --all" "--all" | |
164 | ' | |
165 | ||
9ab9b5df | 166 | test_expect_success 'rev-parse --exclude=glob with --branches=glob' ' |
9d55dca2 RA |
167 | compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" |
168 | ' | |
169 | ||
9ab9b5df | 170 | test_expect_success 'rev-parse --exclude=glob with --tags=glob' ' |
9d55dca2 RA |
171 | compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two" |
172 | ' | |
173 | ||
9ab9b5df | 174 | test_expect_success 'rev-parse --exclude=glob with --remotes=glob' ' |
9d55dca2 RA |
175 | compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" |
176 | ' | |
177 | ||
9ab9b5df | 178 | test_expect_success 'rev-parse --exclude=ref with --branches=glob' ' |
9d55dca2 RA |
179 | compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" |
180 | ' | |
181 | ||
9ab9b5df | 182 | test_expect_success 'rev-parse --exclude=ref with --tags=glob' ' |
9d55dca2 RA |
183 | compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two" |
184 | ' | |
185 | ||
9ab9b5df | 186 | test_expect_success 'rev-parse --exclude=ref with --remotes=glob' ' |
9d55dca2 RA |
187 | compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" |
188 | ' | |
189 | ||
c6ce27ab | 190 | for section in fetch receive uploadpack |
5ff36c9b PS |
191 | do |
192 | test_expect_success "rev-parse --exclude-hidden=$section with --all" ' | |
193 | compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags" "--exclude-hidden=$section --all" | |
194 | ' | |
195 | ||
196 | test_expect_success "rev-parse --exclude-hidden=$section with --all" ' | |
197 | compare "-c transfer.hideRefs=refs/heads/subspace/ rev-parse" "--exclude=refs/heads/subspace/* --all" "--exclude-hidden=$section --all" | |
198 | ' | |
199 | ||
200 | test_expect_success "rev-parse --exclude-hidden=$section with --glob" ' | |
201 | compare "-c transfer.hideRefs=refs/heads/subspace/ rev-parse" "--exclude=refs/heads/subspace/* --glob=refs/heads/*" "--exclude-hidden=$section --glob=refs/heads/*" | |
202 | ' | |
203 | ||
204 | test_expect_success "rev-parse --exclude-hidden=$section can be passed once per pseudo-ref" ' | |
205 | compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags --branches --tags" "--exclude-hidden=$section --all --exclude-hidden=$section --all" | |
206 | ' | |
207 | ||
208 | test_expect_success "rev-parse --exclude-hidden=$section can only be passed once per pseudo-ref" ' | |
209 | echo "fatal: --exclude-hidden= passed more than once" >expected && | |
210 | test_must_fail git rev-parse --exclude-hidden=$section --exclude-hidden=$section 2>err && | |
211 | test_cmp expected err | |
212 | ' | |
213 | ||
214 | for pseudoopt in branches tags remotes | |
215 | do | |
216 | test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt" ' | |
217 | echo "error: --exclude-hidden cannot be used together with --$pseudoopt" >expected && | |
218 | test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt 2>err && | |
219 | test_cmp expected err | |
220 | ' | |
221 | ||
222 | test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt=pattern" ' | |
223 | echo "error: --exclude-hidden cannot be used together with --$pseudoopt" >expected && | |
224 | test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt=pattern 2>err && | |
225 | test_cmp expected err | |
226 | ' | |
227 | done | |
228 | done | |
229 | ||
9ab9b5df | 230 | test_expect_success 'rev-list --exclude=glob with --branches=glob' ' |
9d55dca2 RA |
231 | compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" |
232 | ' | |
233 | ||
9ab9b5df | 234 | test_expect_success 'rev-list --exclude=glob with --tags=glob' ' |
9d55dca2 RA |
235 | compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two" |
236 | ' | |
237 | ||
9ab9b5df | 238 | test_expect_success 'rev-list --exclude=glob with --remotes=glob' ' |
9d55dca2 RA |
239 | compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" |
240 | ' | |
241 | ||
9ab9b5df | 242 | test_expect_success 'rev-list --exclude=ref with --branches=glob' ' |
9d55dca2 RA |
243 | compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" |
244 | ' | |
245 | ||
9ab9b5df | 246 | test_expect_success 'rev-list --exclude=ref with --tags=glob' ' |
9d55dca2 RA |
247 | compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two" |
248 | ' | |
249 | ||
9ab9b5df | 250 | test_expect_success 'rev-list --exclude=ref with --remotes=glob' ' |
9d55dca2 RA |
251 | compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" |
252 | ' | |
253 | ||
d08bae7e IL |
254 | test_expect_success 'rev-list --glob=refs/heads/subspace/*' ' |
255 | ||
256 | compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*" | |
257 | ||
258 | ' | |
259 | ||
5adba90d MM |
260 | test_expect_success 'rev-list --glob refs/heads/subspace/*' ' |
261 | ||
262 | compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*" | |
263 | ||
264 | ' | |
265 | ||
0fc63ec4 JN |
266 | test_expect_success 'rev-list not confused by option-like --glob arg' ' |
267 | ||
1550bb6e | 268 | compare rev-list "main" "--glob -0 main" |
0fc63ec4 JN |
269 | |
270 | ' | |
271 | ||
d08bae7e IL |
272 | test_expect_success 'rev-list --glob=heads/subspace/*' ' |
273 | ||
274 | compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*" | |
275 | ||
276 | ' | |
277 | ||
278 | test_expect_success 'rev-list --glob=refs/heads/subspace/' ' | |
279 | ||
280 | compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/" | |
281 | ||
282 | ' | |
283 | ||
284 | test_expect_success 'rev-list --glob=heads/subspace/' ' | |
285 | ||
286 | compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/" | |
287 | ||
288 | ' | |
289 | ||
290 | test_expect_success 'rev-list --glob=heads/subspace' ' | |
291 | ||
292 | compare rev-list "subspace/one subspace/two" "--glob=heads/subspace" | |
293 | ||
294 | ' | |
295 | ||
b09fe971 IL |
296 | test_expect_success 'rev-list --branches=subspace/*' ' |
297 | ||
298 | compare rev-list "subspace/one subspace/two" "--branches=subspace/*" | |
299 | ||
300 | ' | |
301 | ||
302 | test_expect_success 'rev-list --branches=subspace/' ' | |
303 | ||
304 | compare rev-list "subspace/one subspace/two" "--branches=subspace/" | |
305 | ||
306 | ' | |
307 | ||
308 | test_expect_success 'rev-list --branches=subspace' ' | |
309 | ||
310 | compare rev-list "subspace/one subspace/two" "--branches=subspace" | |
311 | ||
312 | ' | |
9332441d MG |
313 | |
314 | test_expect_success 'rev-list --branches' ' | |
315 | ||
1550bb6e | 316 | compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches" |
9332441d MG |
317 | |
318 | ' | |
319 | ||
1550bb6e | 320 | test_expect_success 'rev-list --glob=heads/someref/* main' ' |
d08bae7e | 321 | |
1550bb6e | 322 | compare rev-list "main" "--glob=heads/someref/* main" |
d08bae7e IL |
323 | |
324 | ' | |
325 | ||
326 | test_expect_success 'rev-list --glob=heads/subspace/* --glob=heads/other/*' ' | |
327 | ||
328 | compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*" | |
329 | ||
330 | ' | |
331 | ||
332 | test_expect_success 'rev-list --glob=heads/*' ' | |
333 | ||
1550bb6e | 334 | compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*" |
d08bae7e IL |
335 | |
336 | ' | |
337 | ||
b09fe971 IL |
338 | test_expect_success 'rev-list --tags=foo' ' |
339 | ||
340 | compare rev-list "foo/bar" "--tags=foo" | |
341 | ||
342 | ' | |
343 | ||
9332441d MG |
344 | test_expect_success 'rev-list --tags' ' |
345 | ||
9d55dca2 | 346 | compare rev-list "foo/bar qux/x qux/two qux/one" "--tags" |
9332441d MG |
347 | |
348 | ' | |
349 | ||
b09fe971 IL |
350 | test_expect_success 'rev-list --remotes=foo' ' |
351 | ||
352 | compare rev-list "foo/baz" "--remotes=foo" | |
353 | ||
354 | ' | |
355 | ||
751a2ac6 | 356 | test_expect_success 'rev-list --exclude with --branches' ' |
1550bb6e | 357 | compare rev-list "--exclude=*/* --branches" "main someref subspace-x" |
751a2ac6 JH |
358 | ' |
359 | ||
360 | test_expect_success 'rev-list --exclude with --all' ' | |
361 | compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags" | |
362 | ' | |
363 | ||
364 | test_expect_success 'rev-list accumulates multiple --exclude' ' | |
365 | compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches | |
366 | ' | |
367 | ||
a12cbe23 | 368 | test_expect_success 'rev-list should succeed with empty output on empty stdin' ' |
b89b4a66 | 369 | git rev-list --stdin </dev/null >actual && |
d3c6751b | 370 | test_must_be_empty actual |
751a2ac6 JH |
371 | ' |
372 | ||
0159ba32 | 373 | test_expect_success 'rev-list should succeed with empty output with all refs excluded' ' |
751a2ac6 | 374 | git rev-list --exclude=* --all >actual && |
d3c6751b | 375 | test_must_be_empty actual |
751a2ac6 JH |
376 | ' |
377 | ||
0159ba32 | 378 | test_expect_success 'rev-list should succeed with empty output with empty --all' ' |
751a2ac6 JH |
379 | ( |
380 | test_create_repo empty && | |
381 | cd empty && | |
751a2ac6 | 382 | git rev-list --all >actual && |
d3c6751b | 383 | test_must_be_empty actual |
751a2ac6 JH |
384 | ) |
385 | ' | |
386 | ||
0159ba32 | 387 | test_expect_success 'rev-list should succeed with empty output with empty glob' ' |
0c5dc743 | 388 | git rev-list --glob=does-not-match-anything >actual && |
d3c6751b | 389 | test_must_be_empty actual |
04a0e985 JK |
390 | ' |
391 | ||
392 | test_expect_success 'rev-list should succeed with empty output when ignoring missing' ' | |
393 | git rev-list --ignore-missing $ZERO_OID >actual && | |
394 | test_must_be_empty actual | |
0c5dc743 JK |
395 | ' |
396 | ||
0fc63ec4 JN |
397 | test_expect_success 'shortlog accepts --glob/--tags/--remotes' ' |
398 | ||
399 | compare shortlog "subspace/one subspace/two" --branches=subspace && | |
400 | compare shortlog \ | |
1550bb6e | 401 | "main subspace-x someref other/three subspace/one subspace/two" \ |
0fc63ec4 | 402 | --branches && |
1550bb6e | 403 | compare shortlog main "--glob=heads/someref/* main" && |
0fc63ec4 JN |
404 | compare shortlog "subspace/one subspace/two other/three" \ |
405 | "--glob=heads/subspace/* --glob=heads/other/*" && | |
406 | compare shortlog \ | |
1550bb6e | 407 | "main other/three someref subspace-x subspace/one subspace/two" \ |
0fc63ec4 JN |
408 | "--glob=heads/*" && |
409 | compare shortlog foo/bar --tags=foo && | |
9d55dca2 | 410 | compare shortlog "foo/bar qux/one qux/two qux/x" --tags && |
0fc63ec4 JN |
411 | compare shortlog foo/baz --remotes=foo |
412 | ||
413 | ' | |
414 | ||
415 | test_expect_failure 'shortlog accepts --glob as detached option' ' | |
416 | ||
417 | compare shortlog \ | |
1550bb6e | 418 | "main other/three someref subspace-x subspace/one subspace/two" \ |
0fc63ec4 JN |
419 | "--glob heads/*" |
420 | ||
421 | ' | |
422 | ||
423 | test_expect_failure 'shortlog --glob is not confused by option-like argument' ' | |
424 | ||
1550bb6e | 425 | compare shortlog main "--glob -e main" |
0fc63ec4 JN |
426 | |
427 | ' | |
428 | ||
d08bae7e | 429 | test_done |