]> git.ipfire.org Git - thirdparty/git.git/blob - t/t1419-exclude-refs.sh
The second batch
[thirdparty/git.git] / t / t1419-exclude-refs.sh
1 #!/bin/sh
2
3 test_description='test exclude_patterns functionality in main ref store'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10
11 if test_have_prereq !REFFILES
12 then
13 skip_all='skipping `git for-each-ref --exclude` tests; need files backend'
14 test_done
15 fi
16
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
21 }
22
23 for_each_ref () {
24 git for-each-ref --format='%(refname)' "$@"
25 }
26
27 assert_jumps () {
28 local nr="$1"
29 local trace="$2"
30
31 grep -q "name:jumps_made value:$nr$" $trace
32 }
33
34 assert_no_jumps () {
35 ! assert_jumps ".*" "$1"
36 }
37
38 test_expect_success 'setup' '
39 test_commit --no-tag base &&
40 base="$(git rev-parse HEAD)" &&
41
42 for name in foo bar baz quux
43 do
44 for i in 1 2 3
45 do
46 echo "create refs/heads/$name/$i $base" || return 1
47 done || return 1
48 done >in &&
49 echo "delete refs/heads/main" >>in &&
50
51 git update-ref --stdin <in &&
52 git pack-refs --all
53 '
54
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 &&
58
59 test_cmp expect actual &&
60 assert_jumps 1 perf
61 '
62
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 &&
66
67 test_cmp expect actual &&
68 assert_jumps 1 perf
69 '
70
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 &&
74
75 test_cmp expect actual &&
76 assert_jumps 1 perf
77 '
78
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 &&
82
83 test_cmp expect actual &&
84 assert_jumps 2 perf
85 '
86
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 &&
90
91 test_cmp expect actual &&
92 assert_jumps 1 perf
93 '
94
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 &&
98
99 test_cmp expect actual &&
100 assert_jumps 1 perf
101 '
102
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 &&
107
108 test_cmp expect actual &&
109 assert_jumps 1 perf
110 '
111
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 &&
115
116 test_cmp expect actual &&
117 assert_no_jumps perf
118 '
119
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 &&
123
124 test_cmp expect actual &&
125 assert_no_jumps perf
126 '
127
128 test_done