]>
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" ' | |
5ff36c9b | 217 | test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt 2>err && |
81fb70f5 | 218 | test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err |
5ff36c9b PS |
219 | ' |
220 | ||
221 | test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt=pattern" ' | |
5ff36c9b | 222 | test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt=pattern 2>err && |
81fb70f5 | 223 | test_grep "error: options .--exclude-hidden. and .--$pseudoopt. cannot be used together" err |
5ff36c9b PS |
224 | ' |
225 | done | |
226 | done | |
227 | ||
9ab9b5df | 228 | test_expect_success 'rev-list --exclude=glob with --branches=glob' ' |
9d55dca2 RA |
229 | compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" |
230 | ' | |
231 | ||
9ab9b5df | 232 | test_expect_success 'rev-list --exclude=glob with --tags=glob' ' |
9d55dca2 RA |
233 | compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two" |
234 | ' | |
235 | ||
9ab9b5df | 236 | test_expect_success 'rev-list --exclude=glob with --remotes=glob' ' |
9d55dca2 RA |
237 | compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two" |
238 | ' | |
239 | ||
9ab9b5df | 240 | test_expect_success 'rev-list --exclude=ref with --branches=glob' ' |
9d55dca2 RA |
241 | compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two" |
242 | ' | |
243 | ||
9ab9b5df | 244 | test_expect_success 'rev-list --exclude=ref with --tags=glob' ' |
9d55dca2 RA |
245 | compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two" |
246 | ' | |
247 | ||
9ab9b5df | 248 | test_expect_success 'rev-list --exclude=ref with --remotes=glob' ' |
9d55dca2 RA |
249 | compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" |
250 | ' | |
251 | ||
d08bae7e IL |
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 | ||
5adba90d MM |
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 | ||
0fc63ec4 JN |
264 | test_expect_success 'rev-list not confused by option-like --glob arg' ' |
265 | ||
1550bb6e | 266 | compare rev-list "main" "--glob -0 main" |
0fc63ec4 JN |
267 | |
268 | ' | |
269 | ||
d08bae7e IL |
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 | ||
b09fe971 IL |
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 | ' | |
9332441d MG |
311 | |
312 | test_expect_success 'rev-list --branches' ' | |
313 | ||
1550bb6e | 314 | compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches" |
9332441d MG |
315 | |
316 | ' | |
317 | ||
1550bb6e | 318 | test_expect_success 'rev-list --glob=heads/someref/* main' ' |
d08bae7e | 319 | |
1550bb6e | 320 | compare rev-list "main" "--glob=heads/someref/* main" |
d08bae7e IL |
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 | ||
1550bb6e | 332 | compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*" |
d08bae7e IL |
333 | |
334 | ' | |
335 | ||
b09fe971 IL |
336 | test_expect_success 'rev-list --tags=foo' ' |
337 | ||
338 | compare rev-list "foo/bar" "--tags=foo" | |
339 | ||
340 | ' | |
341 | ||
9332441d MG |
342 | test_expect_success 'rev-list --tags' ' |
343 | ||
9d55dca2 | 344 | compare rev-list "foo/bar qux/x qux/two qux/one" "--tags" |
9332441d MG |
345 | |
346 | ' | |
347 | ||
b09fe971 IL |
348 | test_expect_success 'rev-list --remotes=foo' ' |
349 | ||
350 | compare rev-list "foo/baz" "--remotes=foo" | |
351 | ||
352 | ' | |
353 | ||
751a2ac6 | 354 | test_expect_success 'rev-list --exclude with --branches' ' |
1550bb6e | 355 | compare rev-list "--exclude=*/* --branches" "main someref subspace-x" |
751a2ac6 JH |
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 | ||
a12cbe23 | 366 | test_expect_success 'rev-list should succeed with empty output on empty stdin' ' |
b89b4a66 | 367 | git rev-list --stdin </dev/null >actual && |
d3c6751b | 368 | test_must_be_empty actual |
751a2ac6 JH |
369 | ' |
370 | ||
0159ba32 | 371 | test_expect_success 'rev-list should succeed with empty output with all refs excluded' ' |
751a2ac6 | 372 | git rev-list --exclude=* --all >actual && |
d3c6751b | 373 | test_must_be_empty actual |
751a2ac6 JH |
374 | ' |
375 | ||
0159ba32 | 376 | test_expect_success 'rev-list should succeed with empty output with empty --all' ' |
751a2ac6 JH |
377 | ( |
378 | test_create_repo empty && | |
379 | cd empty && | |
751a2ac6 | 380 | git rev-list --all >actual && |
d3c6751b | 381 | test_must_be_empty actual |
751a2ac6 JH |
382 | ) |
383 | ' | |
384 | ||
0159ba32 | 385 | test_expect_success 'rev-list should succeed with empty output with empty glob' ' |
0c5dc743 | 386 | git rev-list --glob=does-not-match-anything >actual && |
d3c6751b | 387 | test_must_be_empty actual |
04a0e985 JK |
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 | |
0c5dc743 JK |
393 | ' |
394 | ||
0fc63ec4 JN |
395 | test_expect_success 'shortlog accepts --glob/--tags/--remotes' ' |
396 | ||
397 | compare shortlog "subspace/one subspace/two" --branches=subspace && | |
398 | compare shortlog \ | |
1550bb6e | 399 | "main subspace-x someref other/three subspace/one subspace/two" \ |
0fc63ec4 | 400 | --branches && |
1550bb6e | 401 | compare shortlog main "--glob=heads/someref/* main" && |
0fc63ec4 JN |
402 | compare shortlog "subspace/one subspace/two other/three" \ |
403 | "--glob=heads/subspace/* --glob=heads/other/*" && | |
404 | compare shortlog \ | |
1550bb6e | 405 | "main other/three someref subspace-x subspace/one subspace/two" \ |
0fc63ec4 JN |
406 | "--glob=heads/*" && |
407 | compare shortlog foo/bar --tags=foo && | |
9d55dca2 | 408 | compare shortlog "foo/bar qux/one qux/two qux/x" --tags && |
0fc63ec4 JN |
409 | compare shortlog foo/baz --remotes=foo |
410 | ||
411 | ' | |
412 | ||
413 | test_expect_failure 'shortlog accepts --glob as detached option' ' | |
414 | ||
415 | compare shortlog \ | |
1550bb6e | 416 | "main other/three someref subspace-x subspace/one subspace/two" \ |
0fc63ec4 JN |
417 | "--glob heads/*" |
418 | ||
419 | ' | |
420 | ||
421 | test_expect_failure 'shortlog --glob is not confused by option-like argument' ' | |
422 | ||
1550bb6e | 423 | compare shortlog main "--glob -e main" |
0fc63ec4 JN |
424 | |
425 | ' | |
426 | ||
d08bae7e | 427 | test_done |