5cd6b14c69854b39d1ab22a6588cfd74308c465c
1#!/bin/sh
2
3test_description='basic commit reachability tests'
4
5. ./test-lib.sh
6
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.
11#
12# (10,10)
13# / \
14# (10,9) (9,10)
15# / \ / \
16# (10,8) (9,9) (8,10)
17# / \ / \ / \
18# ( continued...)
19# \ / \ / \ /
20# (3,1) (2,2) (1,3)
21# \ / \ /
22# (2,1) (2,1)
23# \ /
24# (1,1)
25#
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.
30test_expect_success 'setup' '
31 for i in $(test_seq 1 10)
32 do
33 test_commit "1-$i" &&
34 git branch -f commit-1-$i
35 done &&
36 for j in $(test_seq 1 9)
37 do
38 git reset --hard commit-$j-1 &&
39 x=$(($j + 1)) &&
40 test_commit "$x-1" &&
41 git branch -f commit-$x-1 &&
42
43 for i in $(test_seq 2 10)
44 do
45 git merge commit-$j-$i -m "$x-$i" &&
46 git branch -f commit-$x-$i
47 done
48 done &&
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
54'
55
56test_three_modes () {
57 test_when_finished rm -rf .git/objects/info/commit-graph &&
58 test-tool reach $1 <input >actual &&
59 test_cmp expect actual &&
60 cp commit-graph-full .git/objects/info/commit-graph &&
61 test-tool reach $1 <input >actual &&
62 test_cmp expect actual &&
63 cp commit-graph-half .git/objects/info/commit-graph &&
64 test-tool reach $1 <input >actual &&
65 test_cmp expect actual
66}
67
68test_expect_success 'ref_newer:miss' '
69 cat >input <<-\EOF &&
70 A:commit-5-7
71 B:commit-4-9
72 EOF
73 echo "ref_newer(A,B):0" >expect &&
74 test_three_modes ref_newer
75'
76
77test_expect_success 'ref_newer:hit' '
78 cat >input <<-\EOF &&
79 A:commit-5-7
80 B:commit-2-3
81 EOF
82 echo "ref_newer(A,B):1" >expect &&
83 test_three_modes ref_newer
84'
85
86test_expect_success 'in_merge_bases:hit' '
87 cat >input <<-\EOF &&
88 A:commit-5-7
89 B:commit-8-8
90 EOF
91 echo "in_merge_bases(A,B):1" >expect &&
92 test_three_modes in_merge_bases
93'
94
95test_expect_success 'in_merge_bases:miss' '
96 cat >input <<-\EOF &&
97 A:commit-6-8
98 B:commit-5-9
99 EOF
100 echo "in_merge_bases(A,B):0" >expect &&
101 test_three_modes in_merge_bases
102'
103
104test_done