Merge branch 'tb/precompose-prefix-simplify'
[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-lib.sh
9
10 commit () {
11         test_tick &&
12         echo $1 > foo &&
13         git add foo &&
14         git commit -m "$1"
15 }
16
17 compare () {
18         # Split arguments on whitespace.
19         git $1 $2 >expected &&
20         git $1 $3 >actual &&
21         test_cmp expected actual
22 }
23
24 test_expect_success 'setup' '
25
26         commit main &&
27         git checkout -b subspace/one main &&
28         commit one &&
29         git checkout -b subspace/two main &&
30         commit two &&
31         git checkout -b subspace-x main &&
32         commit subspace-x &&
33         git checkout -b other/three main &&
34         commit three &&
35         git checkout -b someref main &&
36         commit some &&
37         git checkout main &&
38         commit topic_2 &&
39         git tag foo/bar main &&
40         commit topic_3 &&
41         git update-ref refs/remotes/foo/baz main &&
42         commit topic_4 &&
43         git update-ref refs/remotes/upstream/one subspace/one &&
44         git update-ref refs/remotes/upstream/two subspace/two &&
45         git update-ref refs/remotes/upstream/x subspace-x &&
46         git tag qux/one subspace/one &&
47         git tag qux/two subspace/two &&
48         git tag qux/x subspace-x
49 '
50
51 test_expect_success 'rev-parse --glob=refs/heads/subspace/*' '
52
53         compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
54
55 '
56
57 test_expect_success 'rev-parse --glob=heads/subspace/*' '
58
59         compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/*"
60
61 '
62
63 test_expect_success 'rev-parse --glob=refs/heads/subspace/' '
64
65         compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/"
66
67 '
68
69 test_expect_success 'rev-parse --glob=heads/subspace/' '
70
71         compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/"
72
73 '
74
75 test_expect_success 'rev-parse --glob=heads/subspace' '
76
77         compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace"
78
79 '
80
81 test_expect_failure 'rev-parse accepts --glob as detached option' '
82
83         compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"
84
85 '
86
87 test_expect_failure 'rev-parse is not confused by option-like glob' '
88
89         compare rev-parse "main" "--glob --symbolic main"
90
91 '
92
93 test_expect_success 'rev-parse --branches=subspace/*' '
94
95         compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
96
97 '
98
99 test_expect_success 'rev-parse --branches=subspace/' '
100
101         compare rev-parse "subspace/one subspace/two" "--branches=subspace/"
102
103 '
104
105 test_expect_success 'rev-parse --branches=subspace' '
106
107         compare rev-parse "subspace/one subspace/two" "--branches=subspace"
108
109 '
110
111 test_expect_success 'rev-parse --glob=heads/subspace/* --glob=heads/other/*' '
112
113         compare rev-parse "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
114
115 '
116
117 test_expect_success 'rev-parse --glob=heads/someref/* main' '
118
119         compare rev-parse "main" "--glob=heads/someref/* main"
120
121 '
122
123 test_expect_success 'rev-parse --glob=heads/*' '
124
125         compare rev-parse "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
126
127 '
128
129 test_expect_success 'rev-parse --tags=foo' '
130
131         compare rev-parse "foo/bar" "--tags=foo"
132
133 '
134
135 test_expect_success 'rev-parse --remotes=foo' '
136
137         compare rev-parse "foo/baz" "--remotes=foo"
138
139 '
140
141 test_expect_success 'rev-parse --exclude with --branches' '
142         compare rev-parse "--exclude=*/* --branches" "main someref subspace-x"
143 '
144
145 test_expect_success 'rev-parse --exclude with --all' '
146         compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags"
147 '
148
149 test_expect_success 'rev-parse accumulates multiple --exclude' '
150         compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
151 '
152
153 test_expect_success 'rev-parse --branches clears --exclude' '
154         compare rev-parse "--exclude=* --branches --branches" "--branches"
155 '
156
157 test_expect_success 'rev-parse --tags clears --exclude' '
158         compare rev-parse "--exclude=* --tags --tags" "--tags"
159 '
160
161 test_expect_success 'rev-parse --all clears --exclude' '
162         compare rev-parse "--exclude=* --all --all" "--all"
163 '
164
165 test_expect_success 'rev-parse --exclude=glob with --branches=glob' '
166         compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
167 '
168
169 test_expect_success 'rev-parse --exclude=glob with --tags=glob' '
170         compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
171 '
172
173 test_expect_success 'rev-parse --exclude=glob with --remotes=glob' '
174         compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
175 '
176
177 test_expect_success 'rev-parse --exclude=ref with --branches=glob' '
178         compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
179 '
180
181 test_expect_success 'rev-parse --exclude=ref with --tags=glob' '
182         compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
183 '
184
185 test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
186         compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
187 '
188
189 test_expect_success 'rev-list --exclude=glob with --branches=glob' '
190         compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
191 '
192
193 test_expect_success 'rev-list --exclude=glob with --tags=glob' '
194         compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
195 '
196
197 test_expect_success 'rev-list --exclude=glob with --remotes=glob' '
198         compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
199 '
200
201 test_expect_success 'rev-list --exclude=ref with --branches=glob' '
202         compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
203 '
204
205 test_expect_success 'rev-list --exclude=ref with --tags=glob' '
206         compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
207 '
208
209 test_expect_success 'rev-list --exclude=ref with --remotes=glob' '
210         compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
211 '
212
213 test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
214
215         compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
216
217 '
218
219 test_expect_success 'rev-list --glob refs/heads/subspace/*' '
220
221         compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*"
222
223 '
224
225 test_expect_success 'rev-list not confused by option-like --glob arg' '
226
227         compare rev-list "main" "--glob -0 main"
228
229 '
230
231 test_expect_success 'rev-list --glob=heads/subspace/*' '
232
233         compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
234
235 '
236
237 test_expect_success 'rev-list --glob=refs/heads/subspace/' '
238
239         compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/"
240
241 '
242
243 test_expect_success 'rev-list --glob=heads/subspace/' '
244
245         compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/"
246
247 '
248
249 test_expect_success 'rev-list --glob=heads/subspace' '
250
251         compare rev-list "subspace/one subspace/two" "--glob=heads/subspace"
252
253 '
254
255 test_expect_success 'rev-list --branches=subspace/*' '
256
257         compare rev-list "subspace/one subspace/two" "--branches=subspace/*"
258
259 '
260
261 test_expect_success 'rev-list --branches=subspace/' '
262
263         compare rev-list "subspace/one subspace/two" "--branches=subspace/"
264
265 '
266
267 test_expect_success 'rev-list --branches=subspace' '
268
269         compare rev-list "subspace/one subspace/two" "--branches=subspace"
270
271 '
272
273 test_expect_success 'rev-list --branches' '
274
275         compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches"
276
277 '
278
279 test_expect_success 'rev-list --glob=heads/someref/* main' '
280
281         compare rev-list "main" "--glob=heads/someref/* main"
282
283 '
284
285 test_expect_success 'rev-list --glob=heads/subspace/* --glob=heads/other/*' '
286
287         compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
288
289 '
290
291 test_expect_success 'rev-list --glob=heads/*' '
292
293         compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
294
295 '
296
297 test_expect_success 'rev-list --tags=foo' '
298
299         compare rev-list "foo/bar" "--tags=foo"
300
301 '
302
303 test_expect_success 'rev-list --tags' '
304
305         compare rev-list "foo/bar qux/x qux/two qux/one" "--tags"
306
307 '
308
309 test_expect_success 'rev-list --remotes=foo' '
310
311         compare rev-list "foo/baz" "--remotes=foo"
312
313 '
314
315 test_expect_success 'rev-list --exclude with --branches' '
316         compare rev-list "--exclude=*/* --branches" "main someref subspace-x"
317 '
318
319 test_expect_success 'rev-list --exclude with --all' '
320         compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags"
321 '
322
323 test_expect_success 'rev-list accumulates multiple --exclude' '
324         compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
325 '
326
327 test_expect_success 'rev-list should succeed with empty output on empty stdin' '
328         git rev-list --stdin </dev/null >actual &&
329         test_must_be_empty actual
330 '
331
332 test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
333         git rev-list --exclude=* --all >actual &&
334         test_must_be_empty actual
335 '
336
337 test_expect_success 'rev-list should succeed with empty output with empty --all' '
338         (
339                 test_create_repo empty &&
340                 cd empty &&
341                 git rev-list --all >actual &&
342                 test_must_be_empty actual
343         )
344 '
345
346 test_expect_success 'rev-list should succeed with empty output with empty glob' '
347         git rev-list --glob=does-not-match-anything >actual &&
348         test_must_be_empty actual
349 '
350
351 test_expect_success 'rev-list should succeed with empty output when ignoring missing' '
352         git rev-list --ignore-missing $ZERO_OID >actual &&
353         test_must_be_empty actual
354 '
355
356 test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
357
358         compare shortlog "subspace/one subspace/two" --branches=subspace &&
359         compare shortlog \
360           "main subspace-x someref other/three subspace/one subspace/two" \
361           --branches &&
362         compare shortlog main "--glob=heads/someref/* main" &&
363         compare shortlog "subspace/one subspace/two other/three" \
364           "--glob=heads/subspace/* --glob=heads/other/*" &&
365         compare shortlog \
366           "main other/three someref subspace-x subspace/one subspace/two" \
367           "--glob=heads/*" &&
368         compare shortlog foo/bar --tags=foo &&
369         compare shortlog "foo/bar qux/one qux/two qux/x" --tags &&
370         compare shortlog foo/baz --remotes=foo
371
372 '
373
374 test_expect_failure 'shortlog accepts --glob as detached option' '
375
376         compare shortlog \
377           "main other/three someref subspace-x subspace/one subspace/two" \
378           "--glob heads/*"
379
380 '
381
382 test_expect_failure 'shortlog --glob is not confused by option-like argument' '
383
384         compare shortlog main "--glob -e main"
385
386 '
387
388 test_done