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
36 for j in $(test_seq 1 9)
38 git reset --hard commit-$j-1 &&
41 git branch -f commit-$x-1 &&
43 for i in $(test_seq 2 10)
45 git merge commit-$j-$i -m "$x-$i" &&
46 git branch -f commit-$x-$i
49 git commit-graph write --reachable &&
50 mv .git/objects/info/commit-graph commit-graph-full &&
51 git show-ref -s commit-5-5 | git commit-graph write --stdin-commits &&
52 mv .git/objects/info/commit-graph commit-graph-half &&
53 git config core.commitGraph true
57 test_when_finished rm -rf .git/objects/info/commit-graph &&
58 "$@" <input >actual &&
59 test_cmp expect actual &&
60 cp commit-graph-full .git/objects/info/commit-graph &&
61 "$@" <input >actual &&
62 test_cmp expect actual &&
63 cp commit-graph-half .git/objects/info/commit-graph &&
64 "$@" <input >actual &&
65 test_cmp expect actual
69 run_three_modes test-tool reach "$@"
72 test_expect_success 'ref_newer:miss' '
77 echo "ref_newer(A,B):0" >expect &&
78 test_three_modes ref_newer
81 test_expect_success 'ref_newer:hit' '
86 echo "ref_newer(A,B):1" >expect &&
87 test_three_modes ref_newer
90 test_expect_success 'in_merge_bases:hit' '
95 echo "in_merge_bases(A,B):1" >expect &&
96 test_three_modes in_merge_bases
99 test_expect_success 'in_merge_bases:miss' '
100 cat >input <<-\EOF &&
104 echo "in_merge_bases(A,B):0" >expect &&
105 test_three_modes in_merge_bases
108 test_expect_success 'is_descendant_of:hit' '
109 cat >input <<-\EOF &&
115 echo "is_descendant_of(A,X):1" >expect &&
116 test_three_modes is_descendant_of
119 test_expect_success 'is_descendant_of:miss' '
120 cat >input <<-\EOF &&
126 echo "is_descendant_of(A,X):0" >expect &&
127 test_three_modes is_descendant_of
130 test_expect_success 'get_merge_bases_many' '
131 cat >input <<-\EOF &&
138 echo "get_merge_bases_many(A,X):" &&
139 git rev-parse commit-5-6 \
142 test_three_modes get_merge_bases_many
145 test_expect_success 'reduce_heads' '
146 cat >input <<-\EOF &&
157 echo "reduce_heads(X):" &&
158 git rev-parse commit-5-1 \
164 test_three_modes reduce_heads
167 test_expect_success 'can_all_from_reach:hit' '
168 cat >input <<-\EOF &&
186 echo "can_all_from_reach(X,Y):1" >expect &&
187 test_three_modes can_all_from_reach
190 test_expect_success 'can_all_from_reach:miss' '
191 cat >input <<-\EOF &&
208 echo "can_all_from_reach(X,Y):0" >expect &&
209 test_three_modes can_all_from_reach
212 test_expect_success 'commit_contains:hit' '
213 cat >input <<-\EOF &&
224 echo "commit_contains(_,A,X,_):1" >expect &&
225 test_three_modes commit_contains &&
226 test_three_modes commit_contains --tag
229 test_expect_success 'commit_contains:miss' '
230 cat >input <<-\EOF &&
241 echo "commit_contains(_,A,X,_):0" >expect &&
242 test_three_modes commit_contains &&
243 test_three_modes commit_contains --tag
246 test_expect_success 'rev-list: basic topo-order' '
248 commit-6-6 commit-5-6 commit-4-6 commit-3-6 commit-2-6 commit-1-6 \
249 commit-6-5 commit-5-5 commit-4-5 commit-3-5 commit-2-5 commit-1-5 \
250 commit-6-4 commit-5-4 commit-4-4 commit-3-4 commit-2-4 commit-1-4 \
251 commit-6-3 commit-5-3 commit-4-3 commit-3-3 commit-2-3 commit-1-3 \
252 commit-6-2 commit-5-2 commit-4-2 commit-3-2 commit-2-2 commit-1-2 \
253 commit-6-1 commit-5-1 commit-4-1 commit-3-1 commit-2-1 commit-1-1 \
255 run_three_modes git rev-list --topo-order commit-6-6
258 test_expect_success 'rev-list: first-parent topo-order' '
265 commit-6-1 commit-5-1 commit-4-1 commit-3-1 commit-2-1 commit-1-1 \
267 run_three_modes git rev-list --first-parent --topo-order commit-6-6
270 test_expect_success 'rev-list: range topo-order' '
272 commit-6-6 commit-5-6 commit-4-6 commit-3-6 commit-2-6 commit-1-6 \
273 commit-6-5 commit-5-5 commit-4-5 commit-3-5 commit-2-5 commit-1-5 \
274 commit-6-4 commit-5-4 commit-4-4 commit-3-4 commit-2-4 commit-1-4 \
275 commit-6-3 commit-5-3 commit-4-3 \
276 commit-6-2 commit-5-2 commit-4-2 \
277 commit-6-1 commit-5-1 commit-4-1 \
279 run_three_modes git rev-list --topo-order commit-3-3..commit-6-6
282 test_expect_success 'rev-list: range topo-order' '
284 commit-6-6 commit-5-6 commit-4-6 \
285 commit-6-5 commit-5-5 commit-4-5 \
286 commit-6-4 commit-5-4 commit-4-4 \
287 commit-6-3 commit-5-3 commit-4-3 \
288 commit-6-2 commit-5-2 commit-4-2 \
289 commit-6-1 commit-5-1 commit-4-1 \
291 run_three_modes git rev-list --topo-order commit-3-8..commit-6-6
294 test_expect_success 'rev-list: first-parent range topo-order' '
301 commit-6-1 commit-5-1 commit-4-1 \
303 run_three_modes git rev-list --first-parent --topo-order commit-3-8..commit-6-6
306 test_expect_success 'rev-list: ancestry-path topo-order' '
308 commit-6-6 commit-5-6 commit-4-6 commit-3-6 \
309 commit-6-5 commit-5-5 commit-4-5 commit-3-5 \
310 commit-6-4 commit-5-4 commit-4-4 commit-3-4 \
311 commit-6-3 commit-5-3 commit-4-3 \
313 run_three_modes git rev-list --topo-order --ancestry-path commit-3-3..commit-6-6
316 test_expect_success 'rev-list: symmetric difference topo-order' '
318 commit-6-6 commit-5-6 commit-4-6 \
319 commit-6-5 commit-5-5 commit-4-5 \
320 commit-6-4 commit-5-4 commit-4-4 \
321 commit-6-3 commit-5-3 commit-4-3 \
322 commit-6-2 commit-5-2 commit-4-2 \
323 commit-6-1 commit-5-1 commit-4-1 \
324 commit-3-8 commit-2-8 commit-1-8 \
325 commit-3-7 commit-2-7 commit-1-7 \
327 run_three_modes git rev-list --topo-order commit-3-8...commit-6-6