Merge branch 'rj/cygwin-has-dev-tty'
[git/gitster.git] / t / t1419-exclude-refs.sh
blob13595744190b54e539a581f2409ab3be5e3932d3
1 #!/bin/sh
3 test_description='test exclude_patterns functionality in main ref store'
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 if test_have_prereq !REFFILES
12 then
13 skip_all='skipping `git for-each-ref --exclude` tests; need files backend'
14 test_done
17 for_each_ref__exclude () {
18 GIT_TRACE2_PERF=1 test-tool ref-store main \
19 for-each-ref--exclude "$@" >actual.raw
20 cut -d ' ' -f 2 actual.raw
23 for_each_ref () {
24 git for-each-ref --format='%(refname)' "$@"
27 assert_jumps () {
28 local nr="$1"
29 local trace="$2"
31 grep -q "name:jumps_made value:$nr$" $trace
34 assert_no_jumps () {
35 ! assert_jumps ".*" "$1"
38 test_expect_success 'setup' '
39 test_commit --no-tag base &&
40 base="$(git rev-parse HEAD)" &&
42 for name in foo bar baz quux
44 for i in 1 2 3
46 echo "create refs/heads/$name/$i $base" || return 1
47 done || return 1
48 done >in &&
49 echo "delete refs/heads/main" >>in &&
51 git update-ref --stdin <in &&
52 git pack-refs --all
55 test_expect_success 'excluded region in middle' '
56 for_each_ref__exclude refs/heads refs/heads/foo >actual 2>perf &&
57 for_each_ref refs/heads/bar refs/heads/baz refs/heads/quux >expect &&
59 test_cmp expect actual &&
60 assert_jumps 1 perf
63 test_expect_success 'excluded region at beginning' '
64 for_each_ref__exclude refs/heads refs/heads/bar >actual 2>perf &&
65 for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect &&
67 test_cmp expect actual &&
68 assert_jumps 1 perf
71 test_expect_success 'excluded region at end' '
72 for_each_ref__exclude refs/heads refs/heads/quux >actual 2>perf &&
73 for_each_ref refs/heads/foo refs/heads/bar refs/heads/baz >expect &&
75 test_cmp expect actual &&
76 assert_jumps 1 perf
79 test_expect_success 'disjoint excluded regions' '
80 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/quux >actual 2>perf &&
81 for_each_ref refs/heads/baz refs/heads/foo >expect &&
83 test_cmp expect actual &&
84 assert_jumps 2 perf
87 test_expect_success 'adjacent, non-overlapping excluded regions' '
88 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/baz >actual 2>perf &&
89 for_each_ref refs/heads/foo refs/heads/quux >expect &&
91 test_cmp expect actual &&
92 assert_jumps 1 perf
95 test_expect_success 'overlapping excluded regions' '
96 for_each_ref__exclude refs/heads refs/heads/ba refs/heads/baz >actual 2>perf &&
97 for_each_ref refs/heads/foo refs/heads/quux >expect &&
99 test_cmp expect actual &&
100 assert_jumps 1 perf
103 test_expect_success 'several overlapping excluded regions' '
104 for_each_ref__exclude refs/heads \
105 refs/heads/bar refs/heads/baz refs/heads/foo >actual 2>perf &&
106 for_each_ref refs/heads/quux >expect &&
108 test_cmp expect actual &&
109 assert_jumps 1 perf
112 test_expect_success 'non-matching excluded section' '
113 for_each_ref__exclude refs/heads refs/heads/does/not/exist >actual 2>perf &&
114 for_each_ref >expect &&
116 test_cmp expect actual &&
117 assert_no_jumps perf
120 test_expect_success 'meta-characters are discarded' '
121 for_each_ref__exclude refs/heads "refs/heads/ba*" >actual 2>perf &&
122 for_each_ref >expect &&
124 test_cmp expect actual &&
125 assert_no_jumps perf
128 test_done