3 test_description
='rev-list/rev-parse --glob'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
19 # Split arguments on whitespace.
20 git
$1 $2 >expected
&&
22 test_cmp expected actual
25 test_expect_success
'setup' '
28 git checkout -b subspace/one main &&
30 git checkout -b subspace/two main &&
32 git checkout -b subspace-x main &&
34 git checkout -b other/three main &&
36 git checkout -b someref main &&
40 git tag foo/bar main &&
42 git update-ref refs/remotes/foo/baz main &&
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
52 test_expect_success
'rev-parse --glob=refs/heads/subspace/*' '
54 compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
58 test_expect_success
'rev-parse --glob=heads/subspace/*' '
60 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/*"
64 test_expect_success
'rev-parse --glob=refs/heads/subspace/' '
66 compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/"
70 test_expect_success
'rev-parse --glob=heads/subspace/' '
72 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/"
76 test_expect_success
'rev-parse --glob=heads/subspace' '
78 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace"
82 test_expect_failure
'rev-parse accepts --glob as detached option' '
84 compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"
88 test_expect_failure
'rev-parse is not confused by option-like glob' '
90 compare rev-parse "main" "--glob --symbolic main"
94 test_expect_success
'rev-parse --branches=subspace/*' '
96 compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
100 test_expect_success
'rev-parse --branches=subspace/' '
102 compare rev-parse "subspace/one subspace/two" "--branches=subspace/"
106 test_expect_success
'rev-parse --branches=subspace' '
108 compare rev-parse "subspace/one subspace/two" "--branches=subspace"
112 test_expect_success
'rev-parse --glob=heads/subspace/* --glob=heads/other/*' '
114 compare rev-parse "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
118 test_expect_success
'rev-parse --glob=heads/someref/* main' '
120 compare rev-parse "main" "--glob=heads/someref/* main"
124 test_expect_success
'rev-parse --glob=heads/*' '
126 compare rev-parse "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
130 test_expect_success
'rev-parse --tags=foo' '
132 compare rev-parse "foo/bar" "--tags=foo"
136 test_expect_success
'rev-parse --remotes=foo' '
138 compare rev-parse "foo/baz" "--remotes=foo"
142 test_expect_success
'rev-parse --exclude with --branches' '
143 compare rev-parse "--exclude=*/* --branches" "main someref subspace-x"
146 test_expect_success
'rev-parse --exclude with --all' '
147 compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags"
150 test_expect_success
'rev-parse accumulates multiple --exclude' '
151 compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
154 test_expect_success
'rev-parse --branches clears --exclude' '
155 compare rev-parse "--exclude=* --branches --branches" "--branches"
158 test_expect_success
'rev-parse --tags clears --exclude' '
159 compare rev-parse "--exclude=* --tags --tags" "--tags"
162 test_expect_success
'rev-parse --all clears --exclude' '
163 compare rev-parse "--exclude=* --all --all" "--all"
166 test_expect_success
'rev-parse --exclude=glob with --branches=glob' '
167 compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
170 test_expect_success
'rev-parse --exclude=glob with --tags=glob' '
171 compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
174 test_expect_success
'rev-parse --exclude=glob with --remotes=glob' '
175 compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
178 test_expect_success
'rev-parse --exclude=ref with --branches=glob' '
179 compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
182 test_expect_success
'rev-parse --exclude=ref with --tags=glob' '
183 compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
186 test_expect_success
'rev-parse --exclude=ref with --remotes=glob' '
187 compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
190 for section
in fetch receive uploadpack
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"
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"
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/*"
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"
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
214 for pseudoopt
in branches tags remotes
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
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
230 test_expect_success
'rev-list --exclude=glob with --branches=glob' '
231 compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
234 test_expect_success
'rev-list --exclude=glob with --tags=glob' '
235 compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
238 test_expect_success
'rev-list --exclude=glob with --remotes=glob' '
239 compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
242 test_expect_success
'rev-list --exclude=ref with --branches=glob' '
243 compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
246 test_expect_success
'rev-list --exclude=ref with --tags=glob' '
247 compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
250 test_expect_success
'rev-list --exclude=ref with --remotes=glob' '
251 compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
254 test_expect_success
'rev-list --glob=refs/heads/subspace/*' '
256 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
260 test_expect_success
'rev-list --glob refs/heads/subspace/*' '
262 compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*"
266 test_expect_success
'rev-list not confused by option-like --glob arg' '
268 compare rev-list "main" "--glob -0 main"
272 test_expect_success
'rev-list --glob=heads/subspace/*' '
274 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
278 test_expect_success
'rev-list --glob=refs/heads/subspace/' '
280 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/"
284 test_expect_success
'rev-list --glob=heads/subspace/' '
286 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/"
290 test_expect_success
'rev-list --glob=heads/subspace' '
292 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace"
296 test_expect_success
'rev-list --branches=subspace/*' '
298 compare rev-list "subspace/one subspace/two" "--branches=subspace/*"
302 test_expect_success
'rev-list --branches=subspace/' '
304 compare rev-list "subspace/one subspace/two" "--branches=subspace/"
308 test_expect_success
'rev-list --branches=subspace' '
310 compare rev-list "subspace/one subspace/two" "--branches=subspace"
314 test_expect_success
'rev-list --branches' '
316 compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches"
320 test_expect_success
'rev-list --glob=heads/someref/* main' '
322 compare rev-list "main" "--glob=heads/someref/* main"
326 test_expect_success
'rev-list --glob=heads/subspace/* --glob=heads/other/*' '
328 compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
332 test_expect_success
'rev-list --glob=heads/*' '
334 compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
338 test_expect_success
'rev-list --tags=foo' '
340 compare rev-list "foo/bar" "--tags=foo"
344 test_expect_success
'rev-list --tags' '
346 compare rev-list "foo/bar qux/x qux/two qux/one" "--tags"
350 test_expect_success
'rev-list --remotes=foo' '
352 compare rev-list "foo/baz" "--remotes=foo"
356 test_expect_success
'rev-list --exclude with --branches' '
357 compare rev-list "--exclude=*/* --branches" "main someref subspace-x"
360 test_expect_success
'rev-list --exclude with --all' '
361 compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags"
364 test_expect_success
'rev-list accumulates multiple --exclude' '
365 compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
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
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
378 test_expect_success
'rev-list should succeed with empty output with empty --all' '
380 test_create_repo empty &&
382 git rev-list --all >actual &&
383 test_must_be_empty actual
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
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
397 test_expect_success
'shortlog accepts --glob/--tags/--remotes' '
399 compare shortlog "subspace/one subspace/two" --branches=subspace &&
401 "main subspace-x someref other/three subspace/one subspace/two" \
403 compare shortlog main "--glob=heads/someref/* main" &&
404 compare shortlog "subspace/one subspace/two other/three" \
405 "--glob=heads/subspace/* --glob=heads/other/*" &&
407 "main other/three someref subspace-x subspace/one subspace/two" \
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
415 test_expect_failure
'shortlog accepts --glob as detached option' '
418 "main other/three someref subspace-x subspace/one subspace/two" \
423 test_expect_failure
'shortlog --glob is not confused by option-like argument' '
425 compare shortlog main "--glob -e main"