]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6018-rev-list-glob.sh
The third batch
[thirdparty/git.git] / t / t6018-rev-list-glob.sh
1 #!/bin/sh
2
3 test_description='rev-list/rev-parse --glob'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 TEST_PASSES_SANITIZE_LEAK=true
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
27 commit main &&
28 git checkout -b subspace/one main &&
29 commit one &&
30 git checkout -b subspace/two main &&
31 commit two &&
32 git checkout -b subspace-x main &&
33 commit subspace-x &&
34 git checkout -b other/three main &&
35 commit three &&
36 git checkout -b someref main &&
37 commit some &&
38 git checkout main &&
39 commit topic_2 &&
40 git tag foo/bar main &&
41 commit topic_3 &&
42 git update-ref refs/remotes/foo/baz main &&
43 commit topic_4 &&
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
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
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
90 compare rev-parse "main" "--glob --symbolic main"
91
92 '
93
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
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
118 test_expect_success 'rev-parse --glob=heads/someref/* main' '
119
120 compare rev-parse "main" "--glob=heads/someref/* main"
121
122 '
123
124 test_expect_success 'rev-parse --glob=heads/*' '
125
126 compare rev-parse "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
127
128 '
129
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
142 test_expect_success 'rev-parse --exclude with --branches' '
143 compare rev-parse "--exclude=*/* --branches" "main someref subspace-x"
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
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
166 test_expect_success 'rev-parse --exclude=glob with --branches=glob' '
167 compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
168 '
169
170 test_expect_success 'rev-parse --exclude=glob with --tags=glob' '
171 compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
172 '
173
174 test_expect_success 'rev-parse --exclude=glob with --remotes=glob' '
175 compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
176 '
177
178 test_expect_success 'rev-parse --exclude=ref with --branches=glob' '
179 compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
180 '
181
182 test_expect_success 'rev-parse --exclude=ref with --tags=glob' '
183 compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
184 '
185
186 test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
187 compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
188 '
189
190 for section in fetch receive uploadpack
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 test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt 2>err &&
218 test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err
219 '
220
221 test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt=pattern" '
222 test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt=pattern 2>err &&
223 test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err
224 '
225 done
226 done
227
228 test_expect_success 'rev-list --exclude=glob with --branches=glob' '
229 compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
230 '
231
232 test_expect_success 'rev-list --exclude=glob with --tags=glob' '
233 compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
234 '
235
236 test_expect_success 'rev-list --exclude=glob with --remotes=glob' '
237 compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
238 '
239
240 test_expect_success 'rev-list --exclude=ref with --branches=glob' '
241 compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
242 '
243
244 test_expect_success 'rev-list --exclude=ref with --tags=glob' '
245 compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
246 '
247
248 test_expect_success 'rev-list --exclude=ref with --remotes=glob' '
249 compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
250 '
251
252 test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
253
254 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
255
256 '
257
258 test_expect_success 'rev-list --glob refs/heads/subspace/*' '
259
260 compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*"
261
262 '
263
264 test_expect_success 'rev-list not confused by option-like --glob arg' '
265
266 compare rev-list "main" "--glob -0 main"
267
268 '
269
270 test_expect_success 'rev-list --glob=heads/subspace/*' '
271
272 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
273
274 '
275
276 test_expect_success 'rev-list --glob=refs/heads/subspace/' '
277
278 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/"
279
280 '
281
282 test_expect_success 'rev-list --glob=heads/subspace/' '
283
284 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/"
285
286 '
287
288 test_expect_success 'rev-list --glob=heads/subspace' '
289
290 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace"
291
292 '
293
294 test_expect_success 'rev-list --branches=subspace/*' '
295
296 compare rev-list "subspace/one subspace/two" "--branches=subspace/*"
297
298 '
299
300 test_expect_success 'rev-list --branches=subspace/' '
301
302 compare rev-list "subspace/one subspace/two" "--branches=subspace/"
303
304 '
305
306 test_expect_success 'rev-list --branches=subspace' '
307
308 compare rev-list "subspace/one subspace/two" "--branches=subspace"
309
310 '
311
312 test_expect_success 'rev-list --branches' '
313
314 compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches"
315
316 '
317
318 test_expect_success 'rev-list --glob=heads/someref/* main' '
319
320 compare rev-list "main" "--glob=heads/someref/* main"
321
322 '
323
324 test_expect_success 'rev-list --glob=heads/subspace/* --glob=heads/other/*' '
325
326 compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
327
328 '
329
330 test_expect_success 'rev-list --glob=heads/*' '
331
332 compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
333
334 '
335
336 test_expect_success 'rev-list --tags=foo' '
337
338 compare rev-list "foo/bar" "--tags=foo"
339
340 '
341
342 test_expect_success 'rev-list --tags' '
343
344 compare rev-list "foo/bar qux/x qux/two qux/one" "--tags"
345
346 '
347
348 test_expect_success 'rev-list --remotes=foo' '
349
350 compare rev-list "foo/baz" "--remotes=foo"
351
352 '
353
354 test_expect_success 'rev-list --exclude with --branches' '
355 compare rev-list "--exclude=*/* --branches" "main someref subspace-x"
356 '
357
358 test_expect_success 'rev-list --exclude with --all' '
359 compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags"
360 '
361
362 test_expect_success 'rev-list accumulates multiple --exclude' '
363 compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
364 '
365
366 test_expect_success 'rev-list should succeed with empty output on empty stdin' '
367 git rev-list --stdin </dev/null >actual &&
368 test_must_be_empty actual
369 '
370
371 test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
372 git rev-list --exclude=* --all >actual &&
373 test_must_be_empty actual
374 '
375
376 test_expect_success 'rev-list should succeed with empty output with empty --all' '
377 (
378 test_create_repo empty &&
379 cd empty &&
380 git rev-list --all >actual &&
381 test_must_be_empty actual
382 )
383 '
384
385 test_expect_success 'rev-list should succeed with empty output with empty glob' '
386 git rev-list --glob=does-not-match-anything >actual &&
387 test_must_be_empty actual
388 '
389
390 test_expect_success 'rev-list should succeed with empty output when ignoring missing' '
391 git rev-list --ignore-missing $ZERO_OID >actual &&
392 test_must_be_empty actual
393 '
394
395 test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
396
397 compare shortlog "subspace/one subspace/two" --branches=subspace &&
398 compare shortlog \
399 "main subspace-x someref other/three subspace/one subspace/two" \
400 --branches &&
401 compare shortlog main "--glob=heads/someref/* main" &&
402 compare shortlog "subspace/one subspace/two other/three" \
403 "--glob=heads/subspace/* --glob=heads/other/*" &&
404 compare shortlog \
405 "main other/three someref subspace-x subspace/one subspace/two" \
406 "--glob=heads/*" &&
407 compare shortlog foo/bar --tags=foo &&
408 compare shortlog "foo/bar qux/one qux/two qux/x" --tags &&
409 compare shortlog foo/baz --remotes=foo
410
411 '
412
413 test_expect_failure 'shortlog accepts --glob as detached option' '
414
415 compare shortlog \
416 "main other/three someref subspace-x subspace/one subspace/two" \
417 "--glob heads/*"
418
419 '
420
421 test_expect_failure 'shortlog --glob is not confused by option-like argument' '
422
423 compare shortlog main "--glob -e main"
424
425 '
426
427 test_done