t/README: add missing value for GIT_TEST_DEFAULT_REF_FORMAT
[git/gitster.git] / t / t1419-exclude-refs.sh
blob3256e4462f96db6f45f953ddc4473a6ba05213df
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 for_each_ref__exclude () {
12 GIT_TRACE2_PERF=1 test-tool ref-store main \
13 for-each-ref--exclude "$@" >actual.raw
14 cut -d ' ' -f 2 actual.raw
17 for_each_ref () {
18 git for-each-ref --format='%(refname)' "$@"
21 assert_jumps () {
22 local nr="$1"
23 local trace="$2"
25 case "$GIT_DEFAULT_REF_FORMAT" in
26 files)
27 grep -q "name:jumps_made value:$nr$" $trace;;
28 reftable)
29 grep -q "name:reseeks_made value:$nr$" $trace;;
31 BUG "unhandled ref format $GIT_DEFAULT_REF_FORMAT";;
32 esac
35 assert_no_jumps () {
36 ! assert_jumps ".*" "$1"
39 test_expect_success 'setup' '
40 test_commit --no-tag base &&
41 base="$(git rev-parse HEAD)" &&
43 for name in foo bar baz quux
45 for i in 1 2 3
47 echo "create refs/heads/$name/$i $base" || return 1
48 done || return 1
49 done >in &&
50 echo "delete refs/heads/main" >>in &&
52 git update-ref --stdin <in &&
53 git pack-refs --all
56 test_expect_success 'excluded region in middle' '
57 for_each_ref__exclude refs/heads refs/heads/foo >actual 2>perf &&
58 for_each_ref refs/heads/bar refs/heads/baz refs/heads/quux >expect &&
60 test_cmp expect actual &&
61 assert_jumps 1 perf
64 test_expect_success 'excluded region at beginning' '
65 for_each_ref__exclude refs/heads refs/heads/bar >actual 2>perf &&
66 for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect &&
68 test_cmp expect actual &&
69 assert_jumps 1 perf
72 test_expect_success 'excluded region at end' '
73 for_each_ref__exclude refs/heads refs/heads/quux >actual 2>perf &&
74 for_each_ref refs/heads/foo refs/heads/bar refs/heads/baz >expect &&
76 test_cmp expect actual &&
77 assert_jumps 1 perf
80 test_expect_success 'disjoint excluded regions' '
81 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/quux >actual 2>perf &&
82 for_each_ref refs/heads/baz refs/heads/foo >expect &&
84 test_cmp expect actual &&
85 assert_jumps 2 perf
88 test_expect_success 'adjacent, non-overlapping excluded regions' '
89 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/baz >actual 2>perf &&
90 for_each_ref refs/heads/foo refs/heads/quux >expect &&
92 test_cmp expect actual &&
93 case "$GIT_DEFAULT_REF_FORMAT" in
94 files)
95 assert_jumps 1 perf;;
96 reftable)
97 assert_jumps 2 perf;;
99 BUG "unhandled ref format $GIT_DEFAULT_REF_FORMAT";;
100 esac
103 test_expect_success 'overlapping excluded regions' '
104 for_each_ref__exclude refs/heads refs/heads/ba refs/heads/baz >actual 2>perf &&
105 for_each_ref refs/heads/foo refs/heads/quux >expect &&
107 test_cmp expect actual &&
108 assert_jumps 1 perf
111 test_expect_success 'several overlapping excluded regions' '
112 for_each_ref__exclude refs/heads \
113 refs/heads/bar refs/heads/baz refs/heads/foo >actual 2>perf &&
114 for_each_ref refs/heads/quux >expect &&
116 test_cmp expect actual &&
117 case "$GIT_DEFAULT_REF_FORMAT" in
118 files)
119 assert_jumps 1 perf;;
120 reftable)
121 assert_jumps 3 perf;;
123 BUG "unhandled ref format $GIT_DEFAULT_REF_FORMAT";;
124 esac
127 test_expect_success 'unordered excludes' '
128 for_each_ref__exclude refs/heads \
129 refs/heads/foo refs/heads/baz >actual 2>perf &&
130 for_each_ref refs/heads/bar refs/heads/quux >expect &&
132 test_cmp expect actual &&
133 case "$GIT_DEFAULT_REF_FORMAT" in
134 files)
135 assert_jumps 1 perf;;
136 reftable)
137 assert_jumps 2 perf;;
139 BUG "unhandled ref format $GIT_DEFAULT_REF_FORMAT";;
140 esac
143 test_expect_success 'non-matching excluded section' '
144 for_each_ref__exclude refs/heads refs/heads/does/not/exist >actual 2>perf &&
145 for_each_ref >expect &&
147 test_cmp expect actual &&
148 assert_no_jumps perf
151 test_expect_success 'meta-characters are discarded' '
152 for_each_ref__exclude refs/heads "refs/heads/ba*" >actual 2>perf &&
153 for_each_ref >expect &&
155 test_cmp expect actual &&
156 assert_no_jumps perf
159 test_done