reflog: fix expire --single-worktree
[git/gitster.git] / t / t1419-exclude-refs.sh
blob5d8c86b657399e0d8852909a33491449f1eaefa9
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 grep -q "name:jumps_made value:$nr$" $trace
28 assert_no_jumps () {
29 ! assert_jumps ".*" "$1"
32 test_expect_success 'setup' '
33 test_commit --no-tag base &&
34 base="$(git rev-parse HEAD)" &&
36 for name in foo bar baz quux
38 for i in 1 2 3
40 echo "create refs/heads/$name/$i $base" || return 1
41 done || return 1
42 done >in &&
43 echo "delete refs/heads/main" >>in &&
45 git update-ref --stdin <in &&
46 git pack-refs --all
49 test_expect_success 'excluded region in middle' '
50 for_each_ref__exclude refs/heads refs/heads/foo >actual 2>perf &&
51 for_each_ref refs/heads/bar refs/heads/baz refs/heads/quux >expect &&
53 test_cmp expect actual &&
54 assert_jumps 1 perf
57 test_expect_success 'excluded region at beginning' '
58 for_each_ref__exclude refs/heads refs/heads/bar >actual 2>perf &&
59 for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect &&
61 test_cmp expect actual &&
62 assert_jumps 1 perf
65 test_expect_success 'excluded region at end' '
66 for_each_ref__exclude refs/heads refs/heads/quux >actual 2>perf &&
67 for_each_ref refs/heads/foo refs/heads/bar refs/heads/baz >expect &&
69 test_cmp expect actual &&
70 assert_jumps 1 perf
73 test_expect_success 'disjoint excluded regions' '
74 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/quux >actual 2>perf &&
75 for_each_ref refs/heads/baz refs/heads/foo >expect &&
77 test_cmp expect actual &&
78 assert_jumps 2 perf
81 test_expect_success 'adjacent, non-overlapping excluded regions' '
82 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/baz >actual 2>perf &&
83 for_each_ref refs/heads/foo refs/heads/quux >expect &&
85 test_cmp expect actual &&
86 assert_jumps 1 perf
89 test_expect_success 'overlapping excluded regions' '
90 for_each_ref__exclude refs/heads refs/heads/ba refs/heads/baz >actual 2>perf &&
91 for_each_ref refs/heads/foo refs/heads/quux >expect &&
93 test_cmp expect actual &&
94 assert_jumps 1 perf
97 test_expect_success 'several overlapping excluded regions' '
98 for_each_ref__exclude refs/heads \
99 refs/heads/bar refs/heads/baz refs/heads/foo >actual 2>perf &&
100 for_each_ref refs/heads/quux >expect &&
102 test_cmp expect actual &&
103 assert_jumps 1 perf
106 test_expect_success 'non-matching excluded section' '
107 for_each_ref__exclude refs/heads refs/heads/does/not/exist >actual 2>perf &&
108 for_each_ref >expect &&
110 test_cmp expect actual &&
111 assert_no_jumps perf
114 test_expect_success 'meta-characters are discarded' '
115 for_each_ref__exclude refs/heads "refs/heads/ba*" >actual 2>perf &&
116 for_each_ref >expect &&
118 test_cmp expect actual &&
119 assert_no_jumps perf
122 test_done