3 test_description='commit graph'
6 test_expect_success 'setup full repo' '
11 git config core.commitGraph true &&
15 test_expect_success 'write graph with no packs' '
16 git commit-graph write --object-dir . &&
17 test_path_is_missing info/graph-latest
20 test_expect_success 'create commits and repack' '
21 for i in $(test_seq 3)
29 graph_git_two_modes() {
30 git -c core.graph=true $1 >output
31 git -c core.graph=false $1 >expect
32 test_cmp output expect
35 graph_git_behavior() {
39 test_expect_success "check normal git operations: $MSG" '
40 graph_git_two_modes "log --oneline $BRANCH" &&
41 graph_git_two_modes "log --topo-order $BRANCH" &&
42 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
43 graph_git_two_modes "branch -vv" &&
44 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
48 graph_git_behavior 'no graph' commits/3 commits/1
56 NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
59 header: 43475048 1 1 $NUM_CHUNKS 0
61 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
65 test_expect_success 'write graph' '
66 graph1=$(git commit-graph write) &&
67 test_path_is_file $objdir/info/$graph1 &&
68 test_path_is_missing $objdir/info/graph-latest &&
69 git commit-graph read --file=$graph1 >output &&
70 graph_read_expect "3" &&
71 test_cmp expect output
74 graph_git_behavior 'graph exists, no head' commits/3 commits/1
76 test_expect_success 'Add more commits' '
77 git reset --hard commits/1 &&
78 for i in $(test_seq 4 5)
83 git reset --hard commits/2 &&
84 for i in $(test_seq 6 7)
89 git reset --hard commits/2 &&
90 git merge commits/4 &&
92 git reset --hard commits/4 &&
93 git merge commits/6 &&
95 git reset --hard commits/3 &&
96 git merge commits/5 commits/7 &&
101 # Current graph structure:
111 test_expect_success 'write graph with merges' '
112 graph2=$(git commit-graph write --set-latest)&&
113 test_path_is_file $objdir/info/$graph2 &&
114 test_path_is_file $objdir/info/graph-latest &&
115 printf $graph2 >expect &&
116 test_cmp expect $objdir/info/graph-latest &&
117 git commit-graph read --file=$graph2 >output &&
118 graph_read_expect "10" "large_edges" &&
119 test_cmp expect output
122 graph_git_behavior 'merge 1 vs 2' merge/1 merge/2
123 graph_git_behavior 'merge 1 vs 3' merge/1 merge/3
124 graph_git_behavior 'merge 2 vs 3' merge/2 merge/3
126 test_expect_success 'Add one more commit' '
128 git branch commits/8 &&
129 ls $objdir/pack | grep idx >existing-idx &&
131 ls $objdir/pack| grep idx | grep -v --file=existing-idx >new-idx
134 # Current graph structure:
146 graph_git_behavior 'mixed mode, commit 8 vs merge 1' commits/8 merge/1
147 graph_git_behavior 'mixed mode, commit 8 vs merge 2' commits/8 merge/2
149 test_expect_success 'write graph with new commit' '
150 graph3=$(git commit-graph write --set-latest --delete-expired) &&
151 test_path_is_file $objdir/info/$graph3 &&
152 test_path_is_file $objdir/info/$graph2 &&
153 test_path_is_missing $objdir/info/$graph1 &&
154 test_path_is_file $objdir/info/graph-latest &&
155 printf $graph3 >expect &&
156 test_cmp expect $objdir/info/graph-latest &&
157 git commit-graph read --file=$graph3 >output &&
158 graph_read_expect "11" "large_edges" &&
159 test_cmp expect output
162 graph_git_behavior 'full graph, commit 8 vs merge 1' commits/8 merge/1
163 graph_git_behavior 'full graph, commit 8 vs merge 2' commits/8 merge/2
165 test_expect_success 'write graph with nothing new' '
166 graph4=$(git commit-graph write --set-latest --delete-expired) &&
167 test_path_is_file $objdir/info/$graph4 &&
168 test_path_is_missing $objdir/info/$graph2 &&
169 printf $graph3 >expect &&
170 printf $graph4 >output &&
171 test_cmp expect output &&
172 test_path_is_file $objdir/info/graph-latest &&
173 printf $graph4 >expect &&
174 test_cmp expect $objdir/info/graph-latest &&
175 git commit-graph read --file=$graph4 >output &&
176 graph_read_expect "11" "large_edges" &&
177 test_cmp expect output
180 graph_git_behavior 'cleared graph, commit 8 vs merge 1' commits/8 merge/1
181 graph_git_behavior 'cleared graph, commit 8 vs merge 2' commits/8 merge/2
183 test_expect_success 'build graph from latest pack with closure' '
184 rm $objdir/info/graph-latest &&
185 graph5=$(cat new-idx | git commit-graph write --set-latest --delete-expired --stdin-packs) &&
186 test_path_is_file $objdir/info/$graph5 &&
187 test_path_is_missing $objdir/info/$graph4 &&
188 test_path_is_file $objdir/info/graph-latest &&
189 printf $graph5 >expect &&
190 test_cmp expect $objdir/info/graph-latest &&
191 git commit-graph read --file=$graph5 >output &&
192 graph_read_expect "9" "large_edges" &&
193 test_cmp expect output
196 graph_git_behavior 'graph from pack, commit 8 vs merge 1' commits/8 merge/1
197 graph_git_behavior 'graph from pack, commit 8 vs merge 2' commits/8 merge/2
199 test_expect_success 'build graph from commits with closure' '
200 git tag -a -m "merge" tag/merge merge/2 &&
201 git rev-parse tag/merge >commits-in &&
202 git rev-parse merge/1 >>commits-in &&
203 rm $objdir/info/graph-latest &&
204 graph6=$(cat commits-in | git commit-graph write --set-latest --delete-expired --stdin-commits) &&
205 test_path_is_file $objdir/info/$graph6 &&
206 test_path_is_missing $objdir/info/$graph5 &&
207 test_path_is_file $objdir/info/graph-latest &&
208 printf $graph6 >expect &&
209 test_cmp expect $objdir/info/graph-latest &&
210 git commit-graph read --file=$graph6 >output &&
211 graph_read_expect "6" &&
212 test_cmp expect output
215 graph_git_behavior 'graph from commits, commit 8 vs merge 1' commits/8 merge/1
216 graph_git_behavior 'graph from commits, commit 8 vs merge 2' commits/8 merge/2
218 test_expect_success 'setup bare repo' '
220 git clone --bare --no-local full bare &&
222 git config core.commitGraph true &&
226 graph_git_behavior 'bare repo, commit 8 vs merge 1' commits/8 merge/1
227 graph_git_behavior 'bare repo, commit 8 vs merge 2' commits/8 merge/2
229 test_expect_success 'write graph in bare repo' '
230 graphbare=$(git commit-graph write --set-latest) &&
231 test_path_is_file $baredir/info/$graphbare &&
232 test_path_is_file $baredir/info/graph-latest &&
233 printf $graphbare >expect &&
234 test_cmp expect $baredir/info/graph-latest &&
235 git commit-graph read --file=$graphbare >output &&
236 graph_read_expect "11" "large_edges" &&
237 test_cmp expect output
240 graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' commits/8 merge/1
241 graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' commits/8 merge/2