3 test_description='split commit graph'
6 GIT_TEST_COMMIT_GRAPH=0
7 GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
9 test_expect_success 'setup repo' '
11 git config core.commitGraph true &&
12 git config gc.writeCommitGraph false &&
13 infodir=".git/objects/info" &&
14 graphdir="$infodir/commit-graphs" &&
34 header: 43475048 1 $(test_oid oid_version) 3 $NUM_BASE
36 chunks: oid_fanout oid_lookup commit_metadata
38 test-tool read-graph >output &&
39 test_cmp expect output
42 test_expect_success POSIXPERM 'tweak umask for modebit tests' '
46 test_expect_success 'create commits and write commit-graph' '
47 for i in $(test_seq 3)
50 git branch commits/$i || return 1
52 git commit-graph write --reachable &&
53 test_path_is_file $infodir/commit-graph &&
57 graph_git_two_modes() {
58 git -c core.commitGraph=true $1 >output
59 git -c core.commitGraph=false $1 >expect
60 test_cmp expect output
63 graph_git_behavior() {
67 test_expect_success "check normal git operations: $MSG" '
68 graph_git_two_modes "log --oneline $BRANCH" &&
69 graph_git_two_modes "log --topo-order $BRANCH" &&
70 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
71 graph_git_two_modes "branch -vv" &&
72 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
76 graph_git_behavior 'graph exists' commits/3 commits/1
78 verify_chain_files_exist() {
79 for hash in $(cat $1/commit-graph-chain)
81 test_path_is_file $1/graph-$hash.graph || return 1
85 test_expect_success 'add more commits, and write a new base graph' '
86 git reset --hard commits/1 &&
87 for i in $(test_seq 4 5)
90 git branch commits/$i || return 1
92 git reset --hard commits/2 &&
93 for i in $(test_seq 6 10)
96 git branch commits/$i || return 1
98 git reset --hard commits/2 &&
99 git merge commits/4 &&
100 git branch merge/1 &&
101 git reset --hard commits/4 &&
102 git merge commits/6 &&
103 git branch merge/2 &&
104 git commit-graph write --reachable &&
108 test_expect_success 'fork and fail to base a chain on a commit-graph file' '
109 test_when_finished rm -rf fork &&
113 rm .git/objects/info/commit-graph &&
114 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
115 test_commit new-commit &&
116 git commit-graph write --reachable --split &&
117 test_path_is_file $graphdir/commit-graph-chain &&
118 test_line_count = 1 $graphdir/commit-graph-chain &&
119 verify_chain_files_exist $graphdir
123 test_expect_success 'add three more commits, write a tip graph' '
124 git reset --hard commits/3 &&
126 git merge commits/5 &&
128 git branch merge/3 &&
129 git commit-graph write --reachable --split &&
130 test_path_is_missing $infodir/commit-graph &&
131 test_path_is_file $graphdir/commit-graph-chain &&
132 ls $graphdir/graph-*.graph >graph-files &&
133 test_line_count = 2 graph-files &&
134 verify_chain_files_exist $graphdir
137 graph_git_behavior 'split commit-graph: merge 3 vs 2' merge/3 merge/2
139 test_expect_success 'add one commit, write a tip graph' '
141 git branch commits/11 &&
142 git commit-graph write --reachable --split &&
143 test_path_is_missing $infodir/commit-graph &&
144 test_path_is_file $graphdir/commit-graph-chain &&
145 ls $graphdir/graph-*.graph >graph-files &&
146 test_line_count = 3 graph-files &&
147 verify_chain_files_exist $graphdir
150 graph_git_behavior 'three-layer commit-graph: commit 11 vs 6' commits/11 commits/6
152 test_expect_success 'add one commit, write a merged graph' '
154 git branch commits/12 &&
155 git commit-graph write --reachable --split &&
156 test_path_is_file $graphdir/commit-graph-chain &&
157 test_line_count = 2 $graphdir/commit-graph-chain &&
158 ls $graphdir/graph-*.graph >graph-files &&
159 test_line_count = 2 graph-files &&
160 verify_chain_files_exist $graphdir
163 graph_git_behavior 'merged commit-graph: commit 12 vs 6' commits/12 commits/6
165 test_expect_success 'create fork and chain across alternate' '
169 git config core.commitGraph true &&
171 echo "$(pwd)/../.git/objects" >.git/objects/info/alternates &&
173 git branch commits/13 &&
174 git commit-graph write --reachable --split &&
175 test_path_is_file $graphdir/commit-graph-chain &&
176 test_line_count = 3 $graphdir/commit-graph-chain &&
177 ls $graphdir/graph-*.graph >graph-files &&
178 test_line_count = 1 graph-files &&
179 git -c core.commitGraph=true rev-list HEAD >expect &&
180 git -c core.commitGraph=false rev-list HEAD >actual &&
181 test_cmp expect actual &&
183 git commit-graph write --reachable --split --object-dir=.git/objects/ &&
184 test_line_count = 3 $graphdir/commit-graph-chain &&
185 ls $graphdir/graph-*.graph >graph-files &&
186 test_line_count = 1 graph-files
190 graph_git_behavior 'alternate: commit 13 vs 6' commits/13 commits/6
192 test_expect_success 'test merge stragety constants' '
193 git clone . merge-2 &&
196 git config core.commitGraph true &&
197 test_line_count = 2 $graphdir/commit-graph-chain &&
199 git commit-graph write --reachable --split --size-multiple=2 &&
200 test_line_count = 3 $graphdir/commit-graph-chain
203 git clone . merge-10 &&
206 git config core.commitGraph true &&
207 test_line_count = 2 $graphdir/commit-graph-chain &&
209 git commit-graph write --reachable --split --size-multiple=10 &&
210 test_line_count = 1 $graphdir/commit-graph-chain &&
211 ls $graphdir/graph-*.graph >graph-files &&
212 test_line_count = 1 graph-files
214 git clone . merge-10-expire &&
216 cd merge-10-expire &&
217 git config core.commitGraph true &&
218 test_line_count = 2 $graphdir/commit-graph-chain &&
220 touch $graphdir/to-delete.graph $graphdir/to-keep.graph &&
221 test-tool chmtime =1546362000 $graphdir/to-delete.graph &&
222 test-tool chmtime =1546362001 $graphdir/to-keep.graph &&
223 git commit-graph write --reachable --split --size-multiple=10 \
224 --expire-time="2019-01-01 12:00 -05:00" &&
225 test_line_count = 1 $graphdir/commit-graph-chain &&
226 test_path_is_missing $graphdir/to-delete.graph &&
227 test_path_is_file $graphdir/to-keep.graph &&
228 ls $graphdir/graph-*.graph >graph-files &&
229 test_line_count = 3 graph-files
231 git clone --no-hardlinks . max-commits &&
234 git config core.commitGraph true &&
235 test_line_count = 2 $graphdir/commit-graph-chain &&
238 git commit-graph write --reachable --split --max-commits=1 &&
239 test_line_count = 1 $graphdir/commit-graph-chain &&
240 ls $graphdir/graph-*.graph >graph-files &&
241 test_line_count = 1 graph-files
245 test_expect_success 'remove commit-graph-chain file after flattening' '
246 git clone . flatten &&
249 test_line_count = 2 $graphdir/commit-graph-chain &&
250 git commit-graph write --reachable &&
251 test_path_is_missing $graphdir/commit-graph-chain &&
252 ls $graphdir >graph-files &&
253 test_line_count = 0 graph-files
262 printf "$data" | dd of="$file" bs=1 seek="$pos" conv=notrunc
265 test_expect_success 'verify hashes along chain, even in shallow' '
266 git clone --no-hardlinks . verify &&
269 git commit-graph verify &&
270 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
271 corrupt_file "$base_file" $(test_oid shallow) "\01" &&
272 test_must_fail git commit-graph verify --shallow 2>test_err &&
273 grep -v "^+" test_err >err &&
274 test_i18ngrep "incorrect checksum" err
278 test_expect_success 'verify --shallow does not check base contents' '
279 git clone --no-hardlinks . verify-shallow &&
282 git commit-graph verify &&
283 base_file=$graphdir/graph-$(head -n 1 $graphdir/commit-graph-chain).graph &&
284 corrupt_file "$base_file" 1000 "\01" &&
285 git commit-graph verify --shallow &&
286 test_must_fail git commit-graph verify 2>test_err &&
287 grep -v "^+" test_err >err &&
288 test_i18ngrep "incorrect checksum" err
292 test_expect_success 'warn on base graph chunk incorrect' '
293 git clone --no-hardlinks . base-chunk &&
296 git commit-graph verify &&
297 base_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
298 corrupt_file "$base_file" $(test_oid base) "\01" &&
299 git commit-graph verify --shallow 2>test_err &&
300 grep -v "^+" test_err >err &&
301 test_i18ngrep "commit-graph chain does not match" err
305 test_expect_success 'verify after commit-graph-chain corruption' '
306 git clone --no-hardlinks . verify-chain &&
309 corrupt_file "$graphdir/commit-graph-chain" 60 "G" &&
310 git commit-graph verify 2>test_err &&
311 grep -v "^+" test_err >err &&
312 test_i18ngrep "invalid commit-graph chain" err &&
313 corrupt_file "$graphdir/commit-graph-chain" 60 "A" &&
314 git commit-graph verify 2>test_err &&
315 grep -v "^+" test_err >err &&
316 test_i18ngrep "unable to find all commit-graph files" err
320 test_expect_success 'verify across alternates' '
321 git clone --no-hardlinks . verify-alt &&
325 altdir="$(pwd)/../.git/objects" &&
326 echo "$altdir" >.git/objects/info/alternates &&
327 git commit-graph verify --object-dir="$altdir/" &&
329 git commit-graph write --reachable --split &&
330 tip_file=$graphdir/graph-$(tail -n 1 $graphdir/commit-graph-chain).graph &&
331 corrupt_file "$tip_file" 100 "\01" &&
332 test_must_fail git commit-graph verify --shallow 2>test_err &&
333 grep -v "^+" test_err >err &&
334 test_i18ngrep "commit-graph has incorrect fanout value" err
338 test_expect_success 'add octopus merge' '
339 git reset --hard commits/10 &&
340 git merge commits/3 commits/4 &&
341 git branch merge/octopus &&
342 git commit-graph write --reachable --split &&
343 git commit-graph verify --progress 2>err &&
344 test_line_count = 3 err &&
345 test_i18ngrep ! warning err &&
346 test_line_count = 3 $graphdir/commit-graph-chain
349 graph_git_behavior 'graph exists' merge/octopus commits/12
351 test_expect_success 'split across alternate where alternate is not split' '
352 git commit-graph write --reachable &&
353 test_path_is_file .git/objects/info/commit-graph &&
354 cp .git/objects/info/commit-graph . &&
355 git clone --no-hardlinks . alt-split &&
358 rm -f .git/objects/info/commit-graph &&
359 echo "$(pwd)"/../.git/objects >.git/objects/info/alternates &&
361 git commit-graph write --reachable --split &&
362 test_line_count = 1 $graphdir/commit-graph-chain
364 test_cmp commit-graph .git/objects/info/commit-graph
367 test_expect_success '--split=no-merge always writes an incremental' '
368 test_when_finished rm -rf a b &&
369 rm -rf $graphdir $infodir/commit-graph &&
370 git reset --hard commits/2 &&
371 git rev-list HEAD~1 >a &&
372 git rev-list HEAD >b &&
373 git commit-graph write --split --stdin-commits <a &&
374 git commit-graph write --split=no-merge --stdin-commits <b &&
375 test_line_count = 2 $graphdir/commit-graph-chain
378 test_expect_success '--split=replace replaces the chain' '
379 rm -rf $graphdir $infodir/commit-graph &&
380 git reset --hard commits/3 &&
381 git rev-list -1 HEAD~2 >a &&
382 git rev-list -1 HEAD~1 >b &&
383 git rev-list -1 HEAD >c &&
384 git commit-graph write --split=no-merge --stdin-commits <a &&
385 git commit-graph write --split=no-merge --stdin-commits <b &&
386 git commit-graph write --split=no-merge --stdin-commits <c &&
387 test_line_count = 3 $graphdir/commit-graph-chain &&
388 git commit-graph write --stdin-commits --split=replace <b &&
389 test_path_is_missing $infodir/commit-graph &&
390 test_path_is_file $graphdir/commit-graph-chain &&
391 ls $graphdir/graph-*.graph >graph-files &&
392 test_line_count = 1 graph-files &&
393 verify_chain_files_exist $graphdir &&
397 test_expect_success ULIMIT_FILE_DESCRIPTORS 'handles file descriptor exhaustion' '
401 for i in $(test_seq 64)
404 run_with_limited_open_files test_might_fail git commit-graph write \
405 --split=no-merge --reachable || return 1
410 while read mode modebits
412 test_expect_success POSIXPERM "split commit-graph respects core.sharedrepository $mode" '
413 rm -rf $graphdir $infodir/commit-graph &&
414 git reset --hard commits/1 &&
415 test_config core.sharedrepository "$mode" &&
416 git commit-graph write --split --reachable &&
417 ls $graphdir/graph-*.graph >graph-files &&
418 test_line_count = 1 graph-files &&
419 echo "$modebits" >expect &&
420 test_modebits $graphdir/graph-*.graph >actual &&
421 test_cmp expect actual &&
422 test_modebits $graphdir/commit-graph-chain >actual &&
423 test_cmp expect actual