Merge branch 'tb/commit-graph-genv2-upgrade-fix' into maint
[git/debian.git] / t / t6018-rev-list-glob.sh
blobe1abc5c2b32f57526c277e6ac62fa1b45f2f46bd
1 #!/bin/sh
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
9 . ./test-lib.sh
11 commit () {
12 test_tick &&
13 echo $1 > foo &&
14 git add foo &&
15 git commit -m "$1"
18 compare () {
19 # Split arguments on whitespace.
20 git $1 $2 >expected &&
21 git $1 $3 >actual &&
22 test_cmp expected actual
25 test_expect_success 'setup' '
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
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 test_expect_success 'rev-list --exclude=glob with --branches=glob' '
191 compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
194 test_expect_success 'rev-list --exclude=glob with --tags=glob' '
195 compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
198 test_expect_success 'rev-list --exclude=glob with --remotes=glob' '
199 compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
202 test_expect_success 'rev-list --exclude=ref with --branches=glob' '
203 compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
206 test_expect_success 'rev-list --exclude=ref with --tags=glob' '
207 compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
210 test_expect_success 'rev-list --exclude=ref with --remotes=glob' '
211 compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
214 test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
216 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
220 test_expect_success 'rev-list --glob refs/heads/subspace/*' '
222 compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*"
226 test_expect_success 'rev-list not confused by option-like --glob arg' '
228 compare rev-list "main" "--glob -0 main"
232 test_expect_success 'rev-list --glob=heads/subspace/*' '
234 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
238 test_expect_success 'rev-list --glob=refs/heads/subspace/' '
240 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/"
244 test_expect_success 'rev-list --glob=heads/subspace/' '
246 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/"
250 test_expect_success 'rev-list --glob=heads/subspace' '
252 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace"
256 test_expect_success 'rev-list --branches=subspace/*' '
258 compare rev-list "subspace/one subspace/two" "--branches=subspace/*"
262 test_expect_success 'rev-list --branches=subspace/' '
264 compare rev-list "subspace/one subspace/two" "--branches=subspace/"
268 test_expect_success 'rev-list --branches=subspace' '
270 compare rev-list "subspace/one subspace/two" "--branches=subspace"
274 test_expect_success 'rev-list --branches' '
276 compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches"
280 test_expect_success 'rev-list --glob=heads/someref/* main' '
282 compare rev-list "main" "--glob=heads/someref/* main"
286 test_expect_success 'rev-list --glob=heads/subspace/* --glob=heads/other/*' '
288 compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
292 test_expect_success 'rev-list --glob=heads/*' '
294 compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
298 test_expect_success 'rev-list --tags=foo' '
300 compare rev-list "foo/bar" "--tags=foo"
304 test_expect_success 'rev-list --tags' '
306 compare rev-list "foo/bar qux/x qux/two qux/one" "--tags"
310 test_expect_success 'rev-list --remotes=foo' '
312 compare rev-list "foo/baz" "--remotes=foo"
316 test_expect_success 'rev-list --exclude with --branches' '
317 compare rev-list "--exclude=*/* --branches" "main someref subspace-x"
320 test_expect_success 'rev-list --exclude with --all' '
321 compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags"
324 test_expect_success 'rev-list accumulates multiple --exclude' '
325 compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
328 test_expect_success 'rev-list should succeed with empty output on empty stdin' '
329 git rev-list --stdin </dev/null >actual &&
330 test_must_be_empty actual
333 test_expect_success 'rev-list should succeed with empty output with all refs excluded' '
334 git rev-list --exclude=* --all >actual &&
335 test_must_be_empty actual
338 test_expect_success 'rev-list should succeed with empty output with empty --all' '
340 test_create_repo empty &&
341 cd empty &&
342 git rev-list --all >actual &&
343 test_must_be_empty actual
347 test_expect_success 'rev-list should succeed with empty output with empty glob' '
348 git rev-list --glob=does-not-match-anything >actual &&
349 test_must_be_empty actual
352 test_expect_success 'rev-list should succeed with empty output when ignoring missing' '
353 git rev-list --ignore-missing $ZERO_OID >actual &&
354 test_must_be_empty actual
357 test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
359 compare shortlog "subspace/one subspace/two" --branches=subspace &&
360 compare shortlog \
361 "main subspace-x someref other/three subspace/one subspace/two" \
362 --branches &&
363 compare shortlog main "--glob=heads/someref/* main" &&
364 compare shortlog "subspace/one subspace/two other/three" \
365 "--glob=heads/subspace/* --glob=heads/other/*" &&
366 compare shortlog \
367 "main other/three someref subspace-x subspace/one subspace/two" \
368 "--glob=heads/*" &&
369 compare shortlog foo/bar --tags=foo &&
370 compare shortlog "foo/bar qux/one qux/two qux/x" --tags &&
371 compare shortlog foo/baz --remotes=foo
375 test_expect_failure 'shortlog accepts --glob as detached option' '
377 compare shortlog \
378 "main other/three someref subspace-x subspace/one subspace/two" \
379 "--glob heads/*"
383 test_expect_failure 'shortlog --glob is not confused by option-like argument' '
385 compare shortlog main "--glob -e main"
389 test_done