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