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 || return 1
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 || return 1
52 git commit-graph write --reachable &&
53 mv .git/objects/info/commit-graph commit-graph-full &&
54 chmod u+w commit-graph-full &&
55 git show-ref -s commit-5-5 | git commit-graph write --stdin-commits &&
56 mv .git/objects/info/commit-graph commit-graph-half &&
57 chmod u+w commit-graph-half &&
58 git -c commitGraph.generationVersion=1 commit-graph write --reachable &&
59 mv .git/objects/info/commit-graph commit-graph-no-gdat &&
60 chmod u+w commit-graph-no-gdat &&
61 git config core.commitGraph true
65 test_when_finished
rm -rf .git
/objects
/info
/commit-graph
&&
66 "$@" <input
>actual
&&
67 test_cmp expect actual
&&
68 cp commit-graph-full .git
/objects
/info
/commit-graph
&&
69 "$@" <input
>actual
&&
70 test_cmp expect actual
&&
71 cp commit-graph-half .git
/objects
/info
/commit-graph
&&
72 "$@" <input
>actual
&&
73 test_cmp expect actual
&&
74 cp commit-graph-no-gdat .git
/objects
/info
/commit-graph
&&
75 "$@" <input
>actual
&&
76 test_cmp expect actual
80 run_all_modes test-tool reach
"$@"
83 test_expect_success
'ref_newer:miss' '
88 echo "ref_newer(A,B):0" >expect &&
89 test_all_modes ref_newer
92 test_expect_success
'ref_newer:hit' '
97 echo "ref_newer(A,B):1" >expect &&
98 test_all_modes ref_newer
101 test_expect_success
'in_merge_bases:hit' '
102 cat >input <<-\EOF &&
106 echo "in_merge_bases(A,B):1" >expect &&
107 test_all_modes in_merge_bases
110 test_expect_success
'in_merge_bases:miss' '
111 cat >input <<-\EOF &&
115 echo "in_merge_bases(A,B):0" >expect &&
116 test_all_modes in_merge_bases
119 test_expect_success
'in_merge_bases_many:hit' '
120 cat >input <<-\EOF &&
125 echo "in_merge_bases_many(A,X):1" >expect &&
126 test_all_modes in_merge_bases_many
129 test_expect_success
'in_merge_bases_many:miss' '
130 cat >input <<-\EOF &&
135 echo "in_merge_bases_many(A,X):0" >expect &&
136 test_all_modes in_merge_bases_many
139 test_expect_success
'in_merge_bases_many:miss-heuristic' '
140 cat >input <<-\EOF &&
145 echo "in_merge_bases_many(A,X):0" >expect &&
146 test_all_modes in_merge_bases_many
149 test_expect_success
'is_descendant_of:hit' '
150 cat >input <<-\EOF &&
156 echo "is_descendant_of(A,X):1" >expect &&
157 test_all_modes is_descendant_of
160 test_expect_success
'is_descendant_of:miss' '
161 cat >input <<-\EOF &&
167 echo "is_descendant_of(A,X):0" >expect &&
168 test_all_modes is_descendant_of
171 test_expect_success
'get_merge_bases_many' '
172 cat >input <<-\EOF &&
179 echo "get_merge_bases_many(A,X):" &&
180 git rev-parse commit-5-6 \
183 test_all_modes get_merge_bases_many
186 test_expect_success
'reduce_heads' '
187 cat >input <<-\EOF &&
198 echo "reduce_heads(X):" &&
199 git rev-parse commit-5-1 \
205 test_all_modes reduce_heads
208 test_expect_success
'can_all_from_reach:hit' '
209 cat >input <<-\EOF &&
227 echo "can_all_from_reach(X,Y):1" >expect &&
228 test_all_modes can_all_from_reach
231 test_expect_success
'can_all_from_reach:miss' '
232 cat >input <<-\EOF &&
249 echo "can_all_from_reach(X,Y):0" >expect &&
250 test_all_modes can_all_from_reach
253 test_expect_success
'can_all_from_reach_with_flag: tags case' '
254 cat >input <<-\EOF &&
272 echo "can_all_from_reach_with_flag(X,_,_,0,0):1" >expect &&
273 test_all_modes can_all_from_reach_with_flag
276 test_expect_success
'commit_contains:hit' '
277 cat >input <<-\EOF &&
288 echo "commit_contains(_,A,X,_):1" >expect &&
289 test_all_modes commit_contains &&
290 test_all_modes commit_contains --tag
293 test_expect_success
'commit_contains:miss' '
294 cat >input <<-\EOF &&
305 echo "commit_contains(_,A,X,_):0" >expect &&
306 test_all_modes commit_contains &&
307 test_all_modes commit_contains --tag
310 test_expect_success
'rev-list: basic topo-order' '
312 commit-6-6 commit-5-6 commit-4-6 commit-3-6 commit-2-6 commit-1-6 \
313 commit-6-5 commit-5-5 commit-4-5 commit-3-5 commit-2-5 commit-1-5 \
314 commit-6-4 commit-5-4 commit-4-4 commit-3-4 commit-2-4 commit-1-4 \
315 commit-6-3 commit-5-3 commit-4-3 commit-3-3 commit-2-3 commit-1-3 \
316 commit-6-2 commit-5-2 commit-4-2 commit-3-2 commit-2-2 commit-1-2 \
317 commit-6-1 commit-5-1 commit-4-1 commit-3-1 commit-2-1 commit-1-1 \
319 run_all_modes git rev-list --topo-order commit-6-6
322 test_expect_success
'rev-list: first-parent topo-order' '
329 commit-6-1 commit-5-1 commit-4-1 commit-3-1 commit-2-1 commit-1-1 \
331 run_all_modes git rev-list --first-parent --topo-order commit-6-6
334 test_expect_success
'rev-list: range topo-order' '
336 commit-6-6 commit-5-6 commit-4-6 commit-3-6 commit-2-6 commit-1-6 \
337 commit-6-5 commit-5-5 commit-4-5 commit-3-5 commit-2-5 commit-1-5 \
338 commit-6-4 commit-5-4 commit-4-4 commit-3-4 commit-2-4 commit-1-4 \
339 commit-6-3 commit-5-3 commit-4-3 \
340 commit-6-2 commit-5-2 commit-4-2 \
341 commit-6-1 commit-5-1 commit-4-1 \
343 run_all_modes git rev-list --topo-order commit-3-3..commit-6-6
346 test_expect_success
'rev-list: range topo-order' '
348 commit-6-6 commit-5-6 commit-4-6 \
349 commit-6-5 commit-5-5 commit-4-5 \
350 commit-6-4 commit-5-4 commit-4-4 \
351 commit-6-3 commit-5-3 commit-4-3 \
352 commit-6-2 commit-5-2 commit-4-2 \
353 commit-6-1 commit-5-1 commit-4-1 \
355 run_all_modes git rev-list --topo-order commit-3-8..commit-6-6
358 test_expect_success
'rev-list: first-parent range topo-order' '
365 commit-6-1 commit-5-1 commit-4-1 \
367 run_all_modes git rev-list --first-parent --topo-order commit-3-8..commit-6-6
370 test_expect_success
'rev-list: ancestry-path topo-order' '
372 commit-6-6 commit-5-6 commit-4-6 commit-3-6 \
373 commit-6-5 commit-5-5 commit-4-5 commit-3-5 \
374 commit-6-4 commit-5-4 commit-4-4 commit-3-4 \
375 commit-6-3 commit-5-3 commit-4-3 \
377 run_all_modes git rev-list --topo-order --ancestry-path commit-3-3..commit-6-6
380 test_expect_success
'rev-list: symmetric difference topo-order' '
382 commit-6-6 commit-5-6 commit-4-6 \
383 commit-6-5 commit-5-5 commit-4-5 \
384 commit-6-4 commit-5-4 commit-4-4 \
385 commit-6-3 commit-5-3 commit-4-3 \
386 commit-6-2 commit-5-2 commit-4-2 \
387 commit-6-1 commit-5-1 commit-4-1 \
388 commit-3-8 commit-2-8 commit-1-8 \
389 commit-3-7 commit-2-7 commit-1-7 \
391 run_all_modes git rev-list --topo-order commit-3-8...commit-6-6
394 test_expect_success
'get_reachable_subset:all' '
395 cat >input <<-\EOF &&
406 echo "get_reachable_subset(X,Y)" &&
407 git rev-parse commit-3-3 \
411 test_all_modes get_reachable_subset
414 test_expect_success
'get_reachable_subset:some' '
415 cat >input <<-\EOF &&
425 echo "get_reachable_subset(X,Y)" &&
426 git rev-parse commit-3-3 \
429 test_all_modes get_reachable_subset
432 test_expect_success
'get_reachable_subset:none' '
433 cat >input <<-\EOF &&
442 echo "get_reachable_subset(X,Y)" >expect &&
443 test_all_modes get_reachable_subset