]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6018-rev-list-glob.sh
rebase: use child_process_clear() to clean
[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 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 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
230 test_expect_success 'rev-list --exclude=glob with --branches=glob' '
231 compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
232 '
233
234 test_expect_success 'rev-list --exclude=glob with --tags=glob' '
235 compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
236 '
237
238 test_expect_success 'rev-list --exclude=glob with --remotes=glob' '
239 compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
240 '
241
242 test_expect_success 'rev-list --exclude=ref with --branches=glob' '
243 compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
244 '
245
246 test_expect_success 'rev-list --exclude=ref with --tags=glob' '
247 compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
248 '
249
250 test_expect_success 'rev-list --exclude=ref with --remotes=glob' '
251 compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
252 '
253
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
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
266 test_expect_success 'rev-list not confused by option-like --glob arg' '
267
268 compare rev-list "main" "--glob -0 main"
269
270 '
271
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
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 '
313
314 test_expect_success 'rev-list --branches' '
315
316 compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches"
317
318 '
319
320 test_expect_success 'rev-list --glob=heads/someref/* main' '
321
322 compare rev-list "main" "--glob=heads/someref/* main"
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
334 compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
335
336 '
337
338 test_expect_success 'rev-list --tags=foo' '
339
340 compare rev-list "foo/bar" "--tags=foo"
341
342 '
343
344 test_expect_success 'rev-list --tags' '
345
346 compare rev-list "foo/bar qux/x qux/two qux/one" "--tags"
347
348 '
349
350 test_expect_success 'rev-list --remotes=foo' '
351
352 compare rev-list "foo/baz" "--remotes=foo"
353
354 '
355
356 test_expect_success 'rev-list --exclude with --branches' '
357 compare rev-list "--exclude=*/* --branches" "main someref subspace-x"
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
368 test_expect_success 'rev-list should succeed with empty output on empty stdin' '
369 git rev-list --stdin </dev/null >actual &&
370 test_must_be_empty actual
371 '
372
373 test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
374 git rev-list --exclude=* --all >actual &&
375 test_must_be_empty actual
376 '
377
378 test_expect_success 'rev-list should succeed with empty output with empty --all' '
379 (
380 test_create_repo empty &&
381 cd empty &&
382 git rev-list --all >actual &&
383 test_must_be_empty actual
384 )
385 '
386
387 test_expect_success 'rev-list should succeed with empty output with empty glob' '
388 git rev-list --glob=does-not-match-anything >actual &&
389 test_must_be_empty actual
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
395 '
396
397 test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
398
399 compare shortlog "subspace/one subspace/two" --branches=subspace &&
400 compare shortlog \
401 "main subspace-x someref other/three subspace/one subspace/two" \
402 --branches &&
403 compare shortlog main "--glob=heads/someref/* main" &&
404 compare shortlog "subspace/one subspace/two other/three" \
405 "--glob=heads/subspace/* --glob=heads/other/*" &&
406 compare shortlog \
407 "main other/three someref subspace-x subspace/one subspace/two" \
408 "--glob=heads/*" &&
409 compare shortlog foo/bar --tags=foo &&
410 compare shortlog "foo/bar qux/one qux/two qux/x" --tags &&
411 compare shortlog foo/baz --remotes=foo
412
413 '
414
415 test_expect_failure 'shortlog accepts --glob as detached option' '
416
417 compare shortlog \
418 "main other/three someref subspace-x subspace/one subspace/two" \
419 "--glob heads/*"
420
421 '
422
423 test_expect_failure 'shortlog --glob is not confused by option-like argument' '
424
425 compare shortlog main "--glob -e main"
426
427 '
428
429 test_done