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 "$@" <input
>actual
&&
62 test_cmp expect actual
&&
63 cp commit-graph-full .git
/objects
/info
/commit-graph
&&
64 "$@" <input
>actual
&&
65 test_cmp expect actual
&&
66 cp commit-graph-half .git
/objects
/info
/commit-graph
&&
67 "$@" <input
>actual
&&
68 test_cmp expect actual
72 run_three_modes test-tool reach
"$@"
75 test_expect_success
'ref_newer:miss' '
80 echo "ref_newer(A,B):0" >expect &&
81 test_three_modes ref_newer
84 test_expect_success
'ref_newer:hit' '
89 echo "ref_newer(A,B):1" >expect &&
90 test_three_modes ref_newer
93 test_expect_success
'in_merge_bases:hit' '
98 echo "in_merge_bases(A,B):1" >expect &&
99 test_three_modes in_merge_bases
102 test_expect_success
'in_merge_bases:miss' '
103 cat >input <<-\EOF &&
107 echo "in_merge_bases(A,B):0" >expect &&
108 test_three_modes in_merge_bases
111 test_expect_success
'is_descendant_of:hit' '
112 cat >input <<-\EOF &&
118 echo "is_descendant_of(A,X):1" >expect &&
119 test_three_modes is_descendant_of
122 test_expect_success
'is_descendant_of:miss' '
123 cat >input <<-\EOF &&
129 echo "is_descendant_of(A,X):0" >expect &&
130 test_three_modes is_descendant_of
133 test_expect_success
'get_merge_bases_many' '
134 cat >input <<-\EOF &&
141 echo "get_merge_bases_many(A,X):" &&
142 git rev-parse commit-5-6 \
145 test_three_modes get_merge_bases_many
148 test_expect_success
'reduce_heads' '
149 cat >input <<-\EOF &&
160 echo "reduce_heads(X):" &&
161 git rev-parse commit-5-1 \
167 test_three_modes reduce_heads
170 test_expect_success
'can_all_from_reach:hit' '
171 cat >input <<-\EOF &&
189 echo "can_all_from_reach(X,Y):1" >expect &&
190 test_three_modes can_all_from_reach
193 test_expect_success
'can_all_from_reach:miss' '
194 cat >input <<-\EOF &&
211 echo "can_all_from_reach(X,Y):0" >expect &&
212 test_three_modes can_all_from_reach
215 test_expect_success
'can_all_from_reach_with_flag: tags case' '
216 cat >input <<-\EOF &&
234 echo "can_all_from_reach_with_flag(X,_,_,0,0):1" >expect &&
235 test_three_modes can_all_from_reach_with_flag
238 test_expect_success
'commit_contains:hit' '
239 cat >input <<-\EOF &&
250 echo "commit_contains(_,A,X,_):1" >expect &&
251 test_three_modes commit_contains &&
252 test_three_modes commit_contains --tag
255 test_expect_success
'commit_contains:miss' '
256 cat >input <<-\EOF &&
267 echo "commit_contains(_,A,X,_):0" >expect &&
268 test_three_modes commit_contains &&
269 test_three_modes commit_contains --tag
272 test_expect_success
'rev-list: basic topo-order' '
274 commit-6-6 commit-5-6 commit-4-6 commit-3-6 commit-2-6 commit-1-6 \
275 commit-6-5 commit-5-5 commit-4-5 commit-3-5 commit-2-5 commit-1-5 \
276 commit-6-4 commit-5-4 commit-4-4 commit-3-4 commit-2-4 commit-1-4 \
277 commit-6-3 commit-5-3 commit-4-3 commit-3-3 commit-2-3 commit-1-3 \
278 commit-6-2 commit-5-2 commit-4-2 commit-3-2 commit-2-2 commit-1-2 \
279 commit-6-1 commit-5-1 commit-4-1 commit-3-1 commit-2-1 commit-1-1 \
281 run_three_modes git rev-list --topo-order commit-6-6
284 test_expect_success
'rev-list: first-parent topo-order' '
291 commit-6-1 commit-5-1 commit-4-1 commit-3-1 commit-2-1 commit-1-1 \
293 run_three_modes git rev-list --first-parent --topo-order commit-6-6
296 test_expect_success
'rev-list: range topo-order' '
298 commit-6-6 commit-5-6 commit-4-6 commit-3-6 commit-2-6 commit-1-6 \
299 commit-6-5 commit-5-5 commit-4-5 commit-3-5 commit-2-5 commit-1-5 \
300 commit-6-4 commit-5-4 commit-4-4 commit-3-4 commit-2-4 commit-1-4 \
301 commit-6-3 commit-5-3 commit-4-3 \
302 commit-6-2 commit-5-2 commit-4-2 \
303 commit-6-1 commit-5-1 commit-4-1 \
305 run_three_modes git rev-list --topo-order commit-3-3..commit-6-6
308 test_expect_success
'rev-list: range topo-order' '
310 commit-6-6 commit-5-6 commit-4-6 \
311 commit-6-5 commit-5-5 commit-4-5 \
312 commit-6-4 commit-5-4 commit-4-4 \
313 commit-6-3 commit-5-3 commit-4-3 \
314 commit-6-2 commit-5-2 commit-4-2 \
315 commit-6-1 commit-5-1 commit-4-1 \
317 run_three_modes git rev-list --topo-order commit-3-8..commit-6-6
320 test_expect_success
'rev-list: first-parent range topo-order' '
327 commit-6-1 commit-5-1 commit-4-1 \
329 run_three_modes git rev-list --first-parent --topo-order commit-3-8..commit-6-6
332 test_expect_success
'rev-list: ancestry-path topo-order' '
334 commit-6-6 commit-5-6 commit-4-6 commit-3-6 \
335 commit-6-5 commit-5-5 commit-4-5 commit-3-5 \
336 commit-6-4 commit-5-4 commit-4-4 commit-3-4 \
337 commit-6-3 commit-5-3 commit-4-3 \
339 run_three_modes git rev-list --topo-order --ancestry-path commit-3-3..commit-6-6
342 test_expect_success
'rev-list: symmetric difference topo-order' '
344 commit-6-6 commit-5-6 commit-4-6 \
345 commit-6-5 commit-5-5 commit-4-5 \
346 commit-6-4 commit-5-4 commit-4-4 \
347 commit-6-3 commit-5-3 commit-4-3 \
348 commit-6-2 commit-5-2 commit-4-2 \
349 commit-6-1 commit-5-1 commit-4-1 \
350 commit-3-8 commit-2-8 commit-1-8 \
351 commit-3-7 commit-2-7 commit-1-7 \
353 run_three_modes git rev-list --topo-order commit-3-8...commit-6-6
356 test_expect_success
'get_reachable_subset:all' '
357 cat >input <<-\EOF &&
368 echo "get_reachable_subset(X,Y)" &&
369 git rev-parse commit-3-3 \
373 test_three_modes get_reachable_subset
376 test_expect_success
'get_reachable_subset:some' '
377 cat >input <<-\EOF &&
387 echo "get_reachable_subset(X,Y)" &&
388 git rev-parse commit-3-3 \
391 test_three_modes get_reachable_subset
394 test_expect_success
'get_reachable_subset:none' '
395 cat >input <<-\EOF &&
404 echo "get_reachable_subset(X,Y)" >expect &&
405 test_three_modes get_reachable_subset