Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t6018-rev-list-glob.sh
blob24b34add833468dd73136689980e4ca3a051411b
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-lib.sh
10 commit () {
11 test_tick &&
12 echo $1 > foo &&
13 git add foo &&
14 git commit -m "$1"
17 compare () {
18 # Split arguments on whitespace.
19 git $1 $2 >expected &&
20 git $1 $3 >actual &&
21 test_cmp expected actual
24 test_expect_success 'setup' '
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
51 test_expect_success 'rev-parse --glob=refs/heads/subspace/*' '
53 compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
57 test_expect_success 'rev-parse --glob=heads/subspace/*' '
59 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/*"
63 test_expect_success 'rev-parse --glob=refs/heads/subspace/' '
65 compare rev-parse "subspace/one subspace/two" "--glob=refs/heads/subspace/"
69 test_expect_success 'rev-parse --glob=heads/subspace/' '
71 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace/"
75 test_expect_success 'rev-parse --glob=heads/subspace' '
77 compare rev-parse "subspace/one subspace/two" "--glob=heads/subspace"
81 test_expect_failure 'rev-parse accepts --glob as detached option' '
83 compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"
87 test_expect_failure 'rev-parse is not confused by option-like glob' '
89 compare rev-parse "main" "--glob --symbolic main"
93 test_expect_success 'rev-parse --branches=subspace/*' '
95 compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
99 test_expect_success 'rev-parse --branches=subspace/' '
101 compare rev-parse "subspace/one subspace/two" "--branches=subspace/"
105 test_expect_success 'rev-parse --branches=subspace' '
107 compare rev-parse "subspace/one subspace/two" "--branches=subspace"
111 test_expect_success 'rev-parse --glob=heads/subspace/* --glob=heads/other/*' '
113 compare rev-parse "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
117 test_expect_success 'rev-parse --glob=heads/someref/* main' '
119 compare rev-parse "main" "--glob=heads/someref/* main"
123 test_expect_success 'rev-parse --glob=heads/*' '
125 compare rev-parse "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
129 test_expect_success 'rev-parse --tags=foo' '
131 compare rev-parse "foo/bar" "--tags=foo"
135 test_expect_success 'rev-parse --remotes=foo' '
137 compare rev-parse "foo/baz" "--remotes=foo"
141 test_expect_success 'rev-parse --exclude with --branches' '
142 compare rev-parse "--exclude=*/* --branches" "main someref subspace-x"
145 test_expect_success 'rev-parse --exclude with --all' '
146 compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags"
149 test_expect_success 'rev-parse accumulates multiple --exclude' '
150 compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
153 test_expect_success 'rev-parse --branches clears --exclude' '
154 compare rev-parse "--exclude=* --branches --branches" "--branches"
157 test_expect_success 'rev-parse --tags clears --exclude' '
158 compare rev-parse "--exclude=* --tags --tags" "--tags"
161 test_expect_success 'rev-parse --all clears --exclude' '
162 compare rev-parse "--exclude=* --all --all" "--all"
165 test_expect_success 'rev-parse --exclude=glob with --branches=glob' '
166 compare rev-parse "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
169 test_expect_success 'rev-parse --exclude=glob with --tags=glob' '
170 compare rev-parse "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
173 test_expect_success 'rev-parse --exclude=glob with --remotes=glob' '
174 compare rev-parse "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
177 test_expect_success 'rev-parse --exclude=ref with --branches=glob' '
178 compare rev-parse "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
181 test_expect_success 'rev-parse --exclude=ref with --tags=glob' '
182 compare rev-parse "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
185 test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
186 compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
189 test_expect_success 'rev-list --exclude=glob with --branches=glob' '
190 compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
193 test_expect_success 'rev-list --exclude=glob with --tags=glob' '
194 compare rev-list "--exclude=qux/? --tags=qux/*" "qux/one qux/two"
197 test_expect_success 'rev-list --exclude=glob with --remotes=glob' '
198 compare rev-list "--exclude=upstream/? --remotes=upstream/*" "upstream/one upstream/two"
201 test_expect_success 'rev-list --exclude=ref with --branches=glob' '
202 compare rev-list "--exclude=subspace-x --branches=sub*" "subspace/one subspace/two"
205 test_expect_success 'rev-list --exclude=ref with --tags=glob' '
206 compare rev-list "--exclude=qux/x --tags=qux/*" "qux/one qux/two"
209 test_expect_success 'rev-list --exclude=ref with --remotes=glob' '
210 compare rev-list "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
213 test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
215 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
219 test_expect_success 'rev-list --glob refs/heads/subspace/*' '
221 compare rev-list "subspace/one subspace/two" "--glob refs/heads/subspace/*"
225 test_expect_success 'rev-list not confused by option-like --glob arg' '
227 compare rev-list "main" "--glob -0 main"
231 test_expect_success 'rev-list --glob=heads/subspace/*' '
233 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
237 test_expect_success 'rev-list --glob=refs/heads/subspace/' '
239 compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/"
243 test_expect_success 'rev-list --glob=heads/subspace/' '
245 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/"
249 test_expect_success 'rev-list --glob=heads/subspace' '
251 compare rev-list "subspace/one subspace/two" "--glob=heads/subspace"
255 test_expect_success 'rev-list --branches=subspace/*' '
257 compare rev-list "subspace/one subspace/two" "--branches=subspace/*"
261 test_expect_success 'rev-list --branches=subspace/' '
263 compare rev-list "subspace/one subspace/two" "--branches=subspace/"
267 test_expect_success 'rev-list --branches=subspace' '
269 compare rev-list "subspace/one subspace/two" "--branches=subspace"
273 test_expect_success 'rev-list --branches' '
275 compare rev-list "main subspace-x someref other/three subspace/one subspace/two" "--branches"
279 test_expect_success 'rev-list --glob=heads/someref/* main' '
281 compare rev-list "main" "--glob=heads/someref/* main"
285 test_expect_success 'rev-list --glob=heads/subspace/* --glob=heads/other/*' '
287 compare rev-list "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
291 test_expect_success 'rev-list --glob=heads/*' '
293 compare rev-list "main other/three someref subspace-x subspace/one subspace/two" "--glob=heads/*"
297 test_expect_success 'rev-list --tags=foo' '
299 compare rev-list "foo/bar" "--tags=foo"
303 test_expect_success 'rev-list --tags' '
305 compare rev-list "foo/bar qux/x qux/two qux/one" "--tags"
309 test_expect_success 'rev-list --remotes=foo' '
311 compare rev-list "foo/baz" "--remotes=foo"
315 test_expect_success 'rev-list --exclude with --branches' '
316 compare rev-list "--exclude=*/* --branches" "main someref subspace-x"
319 test_expect_success 'rev-list --exclude with --all' '
320 compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags"
323 test_expect_success 'rev-list accumulates multiple --exclude' '
324 compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
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
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
337 test_expect_success 'rev-list should succeed with empty output with empty --all' '
339 test_create_repo empty &&
340 cd empty &&
341 git rev-list --all >actual &&
342 test_must_be_empty actual
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
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
356 test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
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
374 test_expect_failure 'shortlog accepts --glob as detached option' '
376 compare shortlog \
377 "main other/three someref subspace-x subspace/one subspace/two" \
378 "--glob heads/*"
382 test_expect_failure 'shortlog --glob is not confused by option-like argument' '
384 compare shortlog main "--glob -e main"
388 test_done