]> git.ipfire.org Git - thirdparty/git.git/blame - t/t1419-exclude-refs.sh
The third batch
[thirdparty/git.git] / t / t1419-exclude-refs.sh
CommitLineData
59c35fac
TB
1#!/bin/sh
2
3test_description='test exclude_patterns functionality in main ref store'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8TEST_PASSES_SANITIZE_LEAK=true
9. ./test-lib.sh
10
61e1c560
PS
11if test_have_prereq !REFFILES
12then
13 skip_all='skipping `git for-each-ref --exclude` tests; need files backend'
14 test_done
15fi
16
59c35fac 17for_each_ref__exclude () {
c489f47a
TB
18 GIT_TRACE2_PERF=1 test-tool ref-store main \
19 for-each-ref--exclude "$@" >actual.raw
59c35fac
TB
20 cut -d ' ' -f 2 actual.raw
21}
22
23for_each_ref () {
24 git for-each-ref --format='%(refname)' "$@"
25}
26
c489f47a
TB
27assert_jumps () {
28 local nr="$1"
29 local trace="$2"
30
31 grep -q "name:jumps_made value:$nr$" $trace
32}
33
34assert_no_jumps () {
35 ! assert_jumps ".*" "$1"
36}
37
59c35fac
TB
38test_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
55test_expect_success 'excluded region in middle' '
c489f47a 56 for_each_ref__exclude refs/heads refs/heads/foo >actual 2>perf &&
59c35fac
TB
57 for_each_ref refs/heads/bar refs/heads/baz refs/heads/quux >expect &&
58
c489f47a
TB
59 test_cmp expect actual &&
60 assert_jumps 1 perf
59c35fac
TB
61'
62
63test_expect_success 'excluded region at beginning' '
c489f47a 64 for_each_ref__exclude refs/heads refs/heads/bar >actual 2>perf &&
59c35fac
TB
65 for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect &&
66
c489f47a
TB
67 test_cmp expect actual &&
68 assert_jumps 1 perf
59c35fac
TB
69'
70
71test_expect_success 'excluded region at end' '
c489f47a 72 for_each_ref__exclude refs/heads refs/heads/quux >actual 2>perf &&
59c35fac
TB
73 for_each_ref refs/heads/foo refs/heads/bar refs/heads/baz >expect &&
74
c489f47a
TB
75 test_cmp expect actual &&
76 assert_jumps 1 perf
59c35fac
TB
77'
78
79test_expect_success 'disjoint excluded regions' '
c489f47a 80 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/quux >actual 2>perf &&
59c35fac
TB
81 for_each_ref refs/heads/baz refs/heads/foo >expect &&
82
c489f47a
TB
83 test_cmp expect actual &&
84 assert_jumps 2 perf
59c35fac
TB
85'
86
87test_expect_success 'adjacent, non-overlapping excluded regions' '
c489f47a 88 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/baz >actual 2>perf &&
59c35fac
TB
89 for_each_ref refs/heads/foo refs/heads/quux >expect &&
90
c489f47a
TB
91 test_cmp expect actual &&
92 assert_jumps 1 perf
59c35fac
TB
93'
94
95test_expect_success 'overlapping excluded regions' '
c489f47a 96 for_each_ref__exclude refs/heads refs/heads/ba refs/heads/baz >actual 2>perf &&
59c35fac
TB
97 for_each_ref refs/heads/foo refs/heads/quux >expect &&
98
c489f47a
TB
99 test_cmp expect actual &&
100 assert_jumps 1 perf
59c35fac
TB
101'
102
103test_expect_success 'several overlapping excluded regions' '
104 for_each_ref__exclude refs/heads \
c489f47a 105 refs/heads/bar refs/heads/baz refs/heads/foo >actual 2>perf &&
59c35fac
TB
106 for_each_ref refs/heads/quux >expect &&
107
c489f47a
TB
108 test_cmp expect actual &&
109 assert_jumps 1 perf
59c35fac
TB
110'
111
112test_expect_success 'non-matching excluded section' '
c489f47a 113 for_each_ref__exclude refs/heads refs/heads/does/not/exist >actual 2>perf &&
59c35fac
TB
114 for_each_ref >expect &&
115
c489f47a
TB
116 test_cmp expect actual &&
117 assert_no_jumps perf
59c35fac
TB
118'
119
120test_expect_success 'meta-characters are discarded' '
c489f47a 121 for_each_ref__exclude refs/heads "refs/heads/ba*" >actual 2>perf &&
59c35fac
TB
122 for_each_ref >expect &&
123
c489f47a
TB
124 test_cmp expect actual &&
125 assert_no_jumps perf
59c35fac
TB
126'
127
128test_done