3 test_description='split commit graph'
6 GIT_TEST_COMMIT_GRAPH=0
8 test_expect_success 'setup repo' '
10 git config core.commitGraph true &&
11 git config gc.writeCommitGraph false &&
12 infodir=".git/objects/info" &&
13 graphdir="$infodir/commit-graphs" &&
31 header: 43475048 1 1 3 $NUM_BASE
33 chunks: oid_fanout oid_lookup commit_metadata
35 test-tool read-graph >output &&
36 test_cmp expect output
39 test_expect_success 'create commits and write commit-graph' '
40 for i in $(test_seq 3)
43 git branch commits/$i || return 1
45 git commit-graph write --reachable &&
46 test_path_is_file $infodir/commit-graph &&
50 graph_git_two_modes() {
51 git -c core.commitGraph=true $1 >output
52 git -c core.commitGraph=false $1 >expect
53 test_cmp expect output
56 graph_git_behavior() {
60 test_expect_success "check normal git operations: $MSG" '
61 graph_git_two_modes "log --oneline $BRANCH" &&
62 graph_git_two_modes "log --topo-order $BRANCH" &&
63 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
64 graph_git_two_modes "branch -vv" &&
65 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
69 graph_git_behavior 'graph exists' commits/3 commits/1
71 verify_chain_files_exist() {
72 for hash in $(cat $1/commit-graph-chain)
74 test_path_is_file $1/graph-$hash.graph || return 1
78 test_expect_success 'add more commits, and write a new base graph' '
79 git reset --hard commits/1 &&
80 for i in $(test_seq 4 5)
83 git branch commits/$i || return 1
85 git reset --hard commits/2 &&
86 for i in $(test_seq 6 10)
89 git branch commits/$i || return 1
91 git reset --hard commits/2 &&
92 git merge commits/4 &&
94 git reset --hard commits/4 &&
95 git merge commits/6 &&
97 git commit-graph write --reachable &&
101 test_expect_success 'fork and fail to base a chain on a commit-graph file' '
102 test_when_finished rm -rf fork &&
106 rm .git/objects/info/commit-graph &&
107 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
108 test_commit new-commit &&
109 git commit-graph write --reachable --split &&
110 test_path_is_file $graphdir/commit-graph-chain &&
111 test_line_count = 1 $graphdir/commit-graph-chain &&
112 verify_chain_files_exist $graphdir
116 test_expect_success 'add three more commits, write a tip graph' '
117 git reset --hard commits/3 &&
119 git merge commits/5 &&
121 git branch merge/3 &&
122 git commit-graph write --reachable --split &&
123 test_path_is_missing $infodir/commit-graph &&
124 test_path_is_file $graphdir/commit-graph-chain &&
125 ls $graphdir/graph-*.graph >graph-files &&
126 test_line_count = 2 graph-files &&
127 verify_chain_files_exist $graphdir
130 graph_git_behavior 'split commit-graph: merge 3 vs 2' merge/3 merge/2
132 test_expect_success 'add one commit, write a tip graph' '
134 git branch commits/11 &&
135 git commit-graph write --reachable --split &&
136 test_path_is_missing $infodir/commit-graph &&
137 test_path_is_file $graphdir/commit-graph-chain &&
138 ls $graphdir/graph-*.graph >graph-files &&
139 test_line_count = 3 graph-files &&
140 verify_chain_files_exist $graphdir
143 graph_git_behavior 'three-layer commit-graph: commit 11 vs 6' commits/11 commits/6
145 test_expect_success 'add one commit, write a merged graph' '
147 git branch commits/12 &&
148 git commit-graph write --reachable --split &&
149 test_path_is_file $graphdir/commit-graph-chain &&
150 test_line_count = 2 $graphdir/commit-graph-chain &&
151 ls $graphdir/graph-*.graph >graph-files &&
152 test_line_count = 2 graph-files &&
153 verify_chain_files_exist $graphdir
156 graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6
158 test_expect_success 'create fork and chain across alternate' '
162 git config core.commitGraph true &&
164 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
166 git branch commits/13 &&
167 git commit-graph write --reachable --split &&
168 test_path_is_file $graphdir/commit-graph-chain &&
169 test_line_count = 3 $graphdir/commit-graph-chain &&
170 ls $graphdir/graph-*.graph >graph-files &&
171 test_line_count = 1 graph-files &&
172 git -c core.commitGraph=true rev-list HEAD >expect &&
173 git -c core.commitGraph=false rev-list HEAD >actual &&
174 test_cmp expect actual &&
176 git commit-graph write --reachable --split --object-dir=.git/objects/ &&
177 test_line_count = 3 $graphdir/commit-graph-chain &&
178 ls $graphdir/graph-*.graph >graph-files &&
179 test_line_count = 1 graph-files
183 graph_git_behavior 'alternate: commit 13 vs 6' commits/13 commits/6
185 test_expect_success 'test merge stragety constants' '
186 git clone . merge-2 &&
189 git config core.commitGraph true &&
190 test_line_count = 2 $graphdir/commit-graph-chain &&
192 git commit-graph write --reachable --split --size-multiple=2 &&
193 test_line_count = 3 $graphdir/commit-graph-chain
196 git clone . merge-10 &&
199 git config core.commitGraph true &&
200 test_line_count = 2 $graphdir/commit-graph-chain &&
202 git commit-graph write --reachable --split --size-multiple=10 &&
203 test_line_count = 1 $graphdir/commit-graph-chain &&
204 ls $graphdir/graph-*.graph >graph-files &&
205 test_line_count = 1 graph-files
207 git clone . merge-10-expire &&
209 cd merge-10-expire &&
210 git config core.commitGraph true &&
211 test_line_count = 2 $graphdir/commit-graph-chain &&
213 git commit-graph write --reachable --split --size-multiple=10 --expire-time=1980-01-01 &&
214 test_line_count = 1 $graphdir/commit-graph-chain &&
215 ls $graphdir/graph-*.graph >graph-files &&
216 test_line_count = 3 graph-files
218 git clone --no-hardlinks . max-commits &&
221 git config core.commitGraph true &&
222 test_line_count = 2 $graphdir/commit-graph-chain &&
225 git commit-graph write --reachable --split --max-commits=1 &&
226 test_line_count = 1 $graphdir/commit-graph-chain &&
227 ls $graphdir/graph-*.graph >graph-files &&
228 test_line_count = 1 graph-files
232 test_expect_success 'remove commit-graph-chain file after flattening' '
233 git clone . flatten &&
236 test_line_count = 2 $graphdir/commit-graph-chain &&
237 git commit-graph write --reachable &&
238 test_path_is_missing $graphdir/commit-graph-chain &&
239 ls $graphdir >graph-files &&
240 test_line_count = 0 graph-files
249 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
252 test_expect_success 'verify hashes along chain, even in shallow' '
253 git clone --no-hardlinks . verify &&
256 git commit-graph verify &&
257 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
258 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
259 test_must_fail git commit-graph verify --shallow 2>test_err &&
260 grep -v "^+" test_err >err &&
261 test_i18ngrep "incorrect checksum" err
265 test_expect_success 'verify --shallow does not check base contents' '
266 git clone --no-hardlinks . verify-shallow &&
269 git commit-graph verify &&
270 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
271 corrupt_file "$base_file" 1000 "\01" &&
272 git commit-graph verify --shallow &&
273 test_must_fail git commit-graph verify 2>test_err &&
274 grep -v "^+" test_err >err &&
275 test_i18ngrep "incorrect checksum" err
279 test_expect_success 'warn on base graph chunk incorrect' '
280 git clone --no-hardlinks . base-chunk &&
283 git commit-graph verify &&
284 base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
285 corrupt_file "$base_file" $(test_oid base) "\01" &&
286 git commit-graph verify --shallow 2>test_err &&
287 grep -v "^+" test_err >err &&
288 test_i18ngrep "commit-graph chain does not match" err
292 test_expect_success 'verify after commit-graph-chain corruption' '
293 git clone --no-hardlinks . verify-chain &&
296 corrupt_file "$graphdir/commit-graph-chain" 60 "G" &&
297 git commit-graph verify 2>test_err &&
298 grep -v "^+" test_err >err &&
299 test_i18ngrep "invalid commit-graph chain" err &&
300 corrupt_file "$graphdir/commit-graph-chain" 60 "A" &&
301 git commit-graph verify 2>test_err &&
302 grep -v "^+" test_err >err &&
303 test_i18ngrep "unable to find all commit-graph files" err
307 test_expect_success 'verify across alternates' '
308 git clone --no-hardlinks . verify-alt &&
312 altdir="$(pwd)/../.git/objects" &&
313 echo "$altdir" >.git/objects/info/alternates &&
314 git commit-graph verify --object-dir="$altdir/" &&
316 git commit-graph write --reachable --split &&
317 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
318 corrupt_file "$tip_file" 100 "\01" &&
319 test_must_fail git commit-graph verify --shallow 2>test_err &&
320 grep -v "^+" test_err >err &&
321 test_i18ngrep "commit-graph has incorrect fanout value" err
325 test_expect_success 'add octopus merge' '
326 git reset --hard commits/10 &&
327 git merge commits/3 commits/4 &&
328 git branch merge/octopus &&
329 git commit-graph write --reachable --split &&
330 git commit-graph verify --progress 2>err &&
331 test_line_count = 3 err &&
332 test_i18ngrep ! warning err &&
333 test_line_count = 3 $graphdir/commit-graph-chain
336 graph_git_behavior 'graph exists' merge/octopus commits/12
338 test_expect_success 'split across alternate where alternate is not split' '
339 git commit-graph write --reachable &&
340 test_path_is_file .git/objects/info/commit-graph &&
341 cp .git/objects/info/commit-graph . &&
342 git clone --no-hardlinks . alt-split &&
345 rm -f .git/objects/info/commit-graph &&
346 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
348 git commit-graph write --reachable --split &&
349 test_line_count = 1 $graphdir/commit-graph-chain
351 test_cmp commit-graph .git/objects/info/commit-graph