Git fork
at reftables-rust 180 lines 4.5 kB view raw
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 8. ./test-lib.sh 9 10for_each_ref__exclude () { 11 GIT_TRACE2_PERF=1 test-tool ref-store main \ 12 for-each-ref--exclude "$@" >actual.raw 13 cut -d ' ' -f 2 actual.raw 14} 15 16for_each_ref () { 17 git for-each-ref --format='%(refname)' "$@" 18} 19 20assert_jumps () { 21 local nr="$1" 22 local trace="$2" 23 24 case "$GIT_DEFAULT_REF_FORMAT" in 25 files) 26 grep -q "name:jumps_made value:$nr$" $trace;; 27 reftable) 28 grep -q "name:reseeks_made value:$nr$" $trace;; 29 *) 30 BUG "unhandled ref format $GIT_DEFAULT_REF_FORMAT";; 31 esac 32} 33 34assert_no_jumps () { 35 ! assert_jumps ".*" "$1" 36} 37 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 for i in 5 6 7 50 do 51 echo "create refs/heads/bar/4/$i $base" || return 1 52 done >>in && 53 echo "delete refs/heads/main" >>in && 54 55 git update-ref --stdin <in && 56 git pack-refs --all 57' 58 59test_expect_success 'excluded region in middle' ' 60 for_each_ref__exclude refs/heads refs/heads/foo >actual 2>perf && 61 for_each_ref refs/heads/bar refs/heads/baz refs/heads/quux >expect && 62 63 test_cmp expect actual && 64 assert_jumps 1 perf 65' 66 67test_expect_success 'excluded region at beginning' ' 68 for_each_ref__exclude refs/heads refs/heads/bar >actual 2>perf && 69 for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect && 70 71 test_cmp expect actual && 72 assert_jumps 1 perf 73' 74 75test_expect_success 'excluded region at end' ' 76 for_each_ref__exclude refs/heads refs/heads/quux >actual 2>perf && 77 for_each_ref refs/heads/foo refs/heads/bar refs/heads/baz >expect && 78 79 test_cmp expect actual && 80 assert_jumps 1 perf 81' 82 83test_expect_success 'disjoint excluded regions' ' 84 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/quux >actual 2>perf && 85 for_each_ref refs/heads/baz refs/heads/foo >expect && 86 87 test_cmp expect actual && 88 assert_jumps 2 perf 89' 90 91test_expect_success 'adjacent, non-overlapping excluded regions' ' 92 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/baz >actual 2>perf && 93 for_each_ref refs/heads/foo refs/heads/quux >expect && 94 95 test_cmp expect actual && 96 case "$GIT_DEFAULT_REF_FORMAT" in 97 files) 98 assert_jumps 1 perf;; 99 reftable) 100 assert_jumps 2 perf;; 101 *) 102 BUG "unhandled ref format $GIT_DEFAULT_REF_FORMAT";; 103 esac 104' 105 106test_expect_success 'non-directory excluded regions' ' 107 for_each_ref__exclude refs/heads refs/heads/ba refs/heads/baz >actual 2>perf && 108 for_each_ref refs/heads/bar refs/heads/foo refs/heads/quux >expect && 109 110 test_cmp expect actual && 111 assert_jumps 1 perf 112' 113 114test_expect_success 'overlapping excluded regions' ' 115 for_each_ref__exclude refs/heads refs/heads/bar refs/heads/bar/4 >actual 2>perf && 116 for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect && 117 118 test_cmp expect actual && 119 assert_jumps 1 perf 120' 121 122test_expect_success 'several overlapping excluded regions' ' 123 for_each_ref__exclude refs/heads \ 124 refs/heads/bar refs/heads/baz refs/heads/foo >actual 2>perf && 125 for_each_ref refs/heads/quux >expect && 126 127 test_cmp expect actual && 128 case "$GIT_DEFAULT_REF_FORMAT" in 129 files) 130 assert_jumps 1 perf;; 131 reftable) 132 assert_jumps 3 perf;; 133 *) 134 BUG "unhandled ref format $GIT_DEFAULT_REF_FORMAT";; 135 esac 136' 137 138test_expect_success 'unordered excludes' ' 139 for_each_ref__exclude refs/heads \ 140 refs/heads/foo refs/heads/baz >actual 2>perf && 141 for_each_ref refs/heads/bar refs/heads/quux >expect && 142 143 test_cmp expect actual && 144 case "$GIT_DEFAULT_REF_FORMAT" in 145 files) 146 assert_jumps 1 perf;; 147 reftable) 148 assert_jumps 2 perf;; 149 *) 150 BUG "unhandled ref format $GIT_DEFAULT_REF_FORMAT";; 151 esac 152' 153 154test_expect_success 'non-matching excluded section' ' 155 for_each_ref__exclude refs/heads refs/heads/does/not/exist >actual 2>perf && 156 for_each_ref >expect && 157 158 test_cmp expect actual && 159 assert_no_jumps perf 160' 161 162test_expect_success 'meta-characters are discarded' ' 163 for_each_ref__exclude refs/heads "refs/heads/ba*" >actual 2>perf && 164 for_each_ref >expect && 165 166 test_cmp expect actual && 167 assert_no_jumps perf 168' 169 170test_expect_success 'empty string exclude pattern is ignored' ' 171 git update-ref refs/heads/loose $(git rev-parse refs/heads/foo/1) && 172 173 for_each_ref__exclude refs/heads "" >actual 2>perf && 174 for_each_ref >expect && 175 176 test_cmp expect actual && 177 assert_no_jumps perf 178' 179 180test_done