3 test_description='basic commit reachability tests'
7 # Construct a grid-like commit graph with points (x,y)
8 # with 1 <= x <= 10, 1 <= y <= 10, where (x,y) has
9 # parents (x-1, y) and (x, y-1), keeping in mind that
10 # we drop a parent if a coordinate is nonpositive.
26 # We use branch 'commit-x-y' to refer to (x,y).
27 # This grid allows interesting reachability and
28 # non-reachability queries: (x,y) can reach (x',y')
29 # if and only if x' <= x and y' <= y.
30 test_expect_success 'setup' '
31 for i in $(test_seq 1 10)
34 git branch -f commit-1-$i &&
35 git tag -a -m "1-$i" tag-1-$i commit-1-$i
37 for j in $(test_seq 1 9)
39 git reset --hard commit-$j-1 &&
42 git branch -f commit-$x-1 &&
43 git tag -a -m "$x-1" tag-$x-1 commit-$x-1 &&
45 for i in $(test_seq 2 10)
47 git merge commit-$j-$i -m "$x-$i" &&
48 git branch -f commit-$x-$i &&
49 git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i
52 git commit-graph write --reachable &&
53 mv .git/objects/info/commit-graph commit-graph-full &&
54 git show-ref -s commit-5-5 | git commit-graph write --stdin-commits &&
55 mv .git/objects/info/commit-graph commit-graph-half &&
56 git config core.commitGraph true
60 test_when_finished rm -rf .git/objects/info/commit-graph &&
61 test-tool reach $1 <input >actual &&
62 test_cmp expect actual &&
63 cp commit-graph-full .git/objects/info/commit-graph &&
64 test-tool reach $1 <input >actual &&
65 test_cmp expect actual &&
66 cp commit-graph-half .git/objects/info/commit-graph &&
67 test-tool reach $1 <input >actual &&
68 test_cmp expect actual
71 test_expect_success 'ref_newer:miss' '
76 echo "ref_newer(A,B):0" >expect &&
77 test_three_modes ref_newer
80 test_expect_success 'ref_newer:hit' '
85 echo "ref_newer(A,B):1" >expect &&
86 test_three_modes ref_newer
89 test_expect_success 'in_merge_bases:hit' '
94 echo "in_merge_bases(A,B):1" >expect &&
95 test_three_modes in_merge_bases
98 test_expect_success 'in_merge_bases:miss' '
103 echo "in_merge_bases(A,B):0" >expect &&
104 test_three_modes in_merge_bases
107 test_expect_success 'is_descendant_of:hit' '
108 cat >input <<-\EOF &&
114 echo "is_descendant_of(A,X):1" >expect &&
115 test_three_modes is_descendant_of
118 test_expect_success 'is_descendant_of:miss' '
119 cat >input <<-\EOF &&
125 echo "is_descendant_of(A,X):0" >expect &&
126 test_three_modes is_descendant_of
129 test_expect_success 'get_merge_bases_many' '
130 cat >input <<-\EOF &&
137 echo "get_merge_bases_many(A,X):" &&
138 git rev-parse commit-5-6 \
141 test_three_modes get_merge_bases_many
144 test_expect_success 'reduce_heads' '
145 cat >input <<-\EOF &&
156 echo "reduce_heads(X):" &&
157 git rev-parse commit-5-1 \
163 test_three_modes reduce_heads
166 test_expect_success 'can_all_from_reach:hit' '
167 cat >input <<-\EOF &&
185 echo "can_all_from_reach(X,Y):1" >expect &&
186 test_three_modes can_all_from_reach
189 test_expect_success 'can_all_from_reach:miss' '
190 cat >input <<-\EOF &&
207 echo "can_all_from_reach(X,Y):0" >expect &&
208 test_three_modes can_all_from_reach
211 test_expect_success 'can_all_from_reach_with_flag: tags case' '
212 cat >input <<-\EOF &&
230 echo "can_all_from_reach_with_flag(X,_,_,0,0):1" >expect &&
231 test_three_modes can_all_from_reach_with_flag
234 test_expect_success 'commit_contains:hit' '
235 cat >input <<-\EOF &&
246 echo "commit_contains(_,A,X,_):1" >expect &&
247 test_three_modes commit_contains &&
248 test_three_modes commit_contains --tag
251 test_expect_success 'commit_contains:miss' '
252 cat >input <<-\EOF &&
263 echo "commit_contains(_,A,X,_):0" >expect &&
264 test_three_modes commit_contains &&
265 test_three_modes commit_contains --tag
268 test_expect_success 'get_reachable_subset:all' '
269 cat >input <<-\EOF &&
280 echo "get_reachable_subset(X,Y)" &&
281 git rev-parse commit-3-3 \
285 test_three_modes get_reachable_subset
288 test_expect_success 'get_reachable_subset:some' '
289 cat >input <<-\EOF &&
299 echo "get_reachable_subset(X,Y)" &&
300 git rev-parse commit-3-3 \
303 test_three_modes get_reachable_subset
306 test_expect_success 'get_reachable_subset:none' '
307 cat >input <<-\EOF &&
316 echo "get_reachable_subset(X,Y)" >expect &&
317 test_three_modes get_reachable_subset