]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5318-commit-graph.sh
commit-graph: drop COMMIT_GRAPH_WRITE_CHECK_OIDS flag
[thirdparty/git.git] / t / t5318-commit-graph.sh
CommitLineData
f237c8b6
DS
1#!/bin/sh
2
3test_description='commit graph'
4. ./test-lib.sh
5
d5b873c8
GS
6GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS=0
7
f237c8b6
DS
8test_expect_success 'setup full repo' '
9 mkdir full &&
10 cd "$TRASH_DIRECTORY/full" &&
11 git init &&
177722b3 12 git config core.commitGraph true &&
ae0c89d4
DS
13 objdir=".git/objects" &&
14 test_oid_init
f237c8b6
DS
15'
16
283e68c7
DS
17test_expect_success 'verify graph with no graph file' '
18 cd "$TRASH_DIRECTORY/full" &&
19 git commit-graph verify
20'
21
f237c8b6
DS
22test_expect_success 'write graph with no packs' '
23 cd "$TRASH_DIRECTORY/full" &&
1793280e
TB
24 git commit-graph write --object-dir $objdir &&
25 test_path_is_missing $objdir/info/commit-graph
f237c8b6
DS
26'
27
7c5c9b9c 28test_expect_success 'exit with correct error on bad input to --stdin-packs' '
e103f727
DS
29 cd "$TRASH_DIRECTORY/full" &&
30 echo doesnotexist >in &&
9916073b 31 test_expect_code 1 git commit-graph write --stdin-packs <in 2>stderr &&
e103f727
DS
32 test_i18ngrep "error adding pack" stderr
33'
34
f237c8b6
DS
35test_expect_success 'create commits and repack' '
36 cd "$TRASH_DIRECTORY/full" &&
37 for i in $(test_seq 3)
38 do
39 test_commit $i &&
40 git branch commits/$i
41 done &&
42 git repack
43'
44
177722b3 45graph_git_two_modes() {
55abcb41
DS
46 git -c core.commitGraph=true $1 >output
47 git -c core.commitGraph=false $1 >expect
dcbaa0b3 48 test_cmp expect output
177722b3
DS
49}
50
51graph_git_behavior() {
52 MSG=$1
53 DIR=$2
54 BRANCH=$3
55 COMPARE=$4
56 test_expect_success "check normal git operations: $MSG" '
57 cd "$TRASH_DIRECTORY/$DIR" &&
58 graph_git_two_modes "log --oneline $BRANCH" &&
59 graph_git_two_modes "log --topo-order $BRANCH" &&
60 graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
61 graph_git_two_modes "branch -vv" &&
62 graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
63 '
64}
65
66graph_git_behavior 'no graph' full commits/3 commits/1
67
2a2e32bd
DS
68graph_read_expect() {
69 OPTIONAL=""
70 NUM_CHUNKS=3
71 if test ! -z $2
72 then
73 OPTIONAL=" $2"
74 NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
75 fi
76 cat >expect <<- EOF
77 header: 43475048 1 1 $NUM_CHUNKS 0
78 num_commits: $1
79 chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
80 EOF
4bd0593e 81 test-tool read-graph >output &&
2a2e32bd
DS
82 test_cmp expect output
83}
84
1f1304d4
TB
85test_expect_success 'exit with correct error on bad input to --stdin-commits' '
86 cd "$TRASH_DIRECTORY/full" &&
2f00c355
TB
87 # invalid, non-hex OID
88 echo HEAD >in &&
89 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
1f1304d4 90 test_i18ngrep "unexpected non-hex object ID: HEAD" stderr &&
2f00c355
TB
91 # non-existent OID
92 echo $ZERO_OID >in &&
93 test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr &&
94 test_i18ngrep "invalid object" stderr &&
95 # valid commit and tree OID
96 git rev-parse HEAD HEAD^{tree} >in &&
97 git commit-graph write --stdin-commits <in &&
98 graph_read_expect 3
1f1304d4
TB
99'
100
f237c8b6
DS
101test_expect_success 'write graph' '
102 cd "$TRASH_DIRECTORY/full" &&
0b918b75 103 git commit-graph write &&
2a2e32bd
DS
104 test_path_is_file $objdir/info/commit-graph &&
105 graph_read_expect "3"
f237c8b6
DS
106'
107
177722b3
DS
108graph_git_behavior 'graph exists' full commits/3 commits/1
109
f237c8b6
DS
110test_expect_success 'Add more commits' '
111 cd "$TRASH_DIRECTORY/full" &&
112 git reset --hard commits/1 &&
113 for i in $(test_seq 4 5)
114 do
115 test_commit $i &&
116 git branch commits/$i
117 done &&
118 git reset --hard commits/2 &&
119 for i in $(test_seq 6 7)
120 do
121 test_commit $i &&
122 git branch commits/$i
123 done &&
124 git reset --hard commits/2 &&
125 git merge commits/4 &&
126 git branch merge/1 &&
127 git reset --hard commits/4 &&
128 git merge commits/6 &&
129 git branch merge/2 &&
130 git reset --hard commits/3 &&
131 git merge commits/5 commits/7 &&
132 git branch merge/3 &&
133 git repack
134'
135
73716122
GS
136test_expect_success 'commit-graph write progress off for redirected stderr' '
137 cd "$TRASH_DIRECTORY/full" &&
138 git commit-graph write 2>err &&
139 test_line_count = 0 err
140'
141
142test_expect_success 'commit-graph write force progress on for stderr' '
143 cd "$TRASH_DIRECTORY/full" &&
44a4693b 144 GIT_PROGRESS_DELAY=0 git commit-graph write --progress 2>err &&
73716122
GS
145 test_file_not_empty err
146'
147
148test_expect_success 'commit-graph write with the --no-progress option' '
149 cd "$TRASH_DIRECTORY/full" &&
150 git commit-graph write --no-progress 2>err &&
151 test_line_count = 0 err
152'
153
154test_expect_success 'commit-graph verify progress off for redirected stderr' '
155 cd "$TRASH_DIRECTORY/full" &&
156 git commit-graph verify 2>err &&
157 test_line_count = 0 err
158'
159
160test_expect_success 'commit-graph verify force progress on for stderr' '
161 cd "$TRASH_DIRECTORY/full" &&
44a4693b 162 GIT_PROGRESS_DELAY=0 git commit-graph verify --progress 2>err &&
73716122
GS
163 test_file_not_empty err
164'
165
166test_expect_success 'commit-graph verify with the --no-progress option' '
167 cd "$TRASH_DIRECTORY/full" &&
168 git commit-graph verify --no-progress 2>err &&
169 test_line_count = 0 err
170'
171
f237c8b6
DS
172# Current graph structure:
173#
174# __M3___
175# / | \
176# 3 M1 5 M2 7
177# |/ \|/ \|
178# 2 4 6
179# |___/____/
180# 1
181
f237c8b6
DS
182test_expect_success 'write graph with merges' '
183 cd "$TRASH_DIRECTORY/full" &&
184 git commit-graph write &&
2a2e32bd 185 test_path_is_file $objdir/info/commit-graph &&
5af7417b 186 graph_read_expect "10" "extra_edges"
f237c8b6
DS
187'
188
177722b3
DS
189graph_git_behavior 'merge 1 vs 2' full merge/1 merge/2
190graph_git_behavior 'merge 1 vs 3' full merge/1 merge/3
191graph_git_behavior 'merge 2 vs 3' full merge/2 merge/3
192
f237c8b6
DS
193test_expect_success 'Add one more commit' '
194 cd "$TRASH_DIRECTORY/full" &&
195 test_commit 8 &&
196 git branch commits/8 &&
197 ls $objdir/pack | grep idx >existing-idx &&
198 git repack &&
4a3ed638 199 ls $objdir/pack| grep idx | grep -v -f existing-idx >new-idx
f237c8b6
DS
200'
201
202# Current graph structure:
203#
204# 8
205# |
206# __M3___
207# / | \
208# 3 M1 5 M2 7
209# |/ \|/ \|
210# 2 4 6
211# |___/____/
212# 1
213
177722b3
DS
214graph_git_behavior 'mixed mode, commit 8 vs merge 1' full commits/8 merge/1
215graph_git_behavior 'mixed mode, commit 8 vs merge 2' full commits/8 merge/2
216
f237c8b6
DS
217test_expect_success 'write graph with new commit' '
218 cd "$TRASH_DIRECTORY/full" &&
219 git commit-graph write &&
2a2e32bd 220 test_path_is_file $objdir/info/commit-graph &&
5af7417b 221 graph_read_expect "11" "extra_edges"
f237c8b6
DS
222'
223
177722b3
DS
224graph_git_behavior 'full graph, commit 8 vs merge 1' full commits/8 merge/1
225graph_git_behavior 'full graph, commit 8 vs merge 2' full commits/8 merge/2
226
f237c8b6
DS
227test_expect_success 'write graph with nothing new' '
228 cd "$TRASH_DIRECTORY/full" &&
229 git commit-graph write &&
2a2e32bd 230 test_path_is_file $objdir/info/commit-graph &&
5af7417b 231 graph_read_expect "11" "extra_edges"
f237c8b6
DS
232'
233
177722b3
DS
234graph_git_behavior 'cleared graph, commit 8 vs merge 1' full commits/8 merge/1
235graph_git_behavior 'cleared graph, commit 8 vs merge 2' full commits/8 merge/2
236
049d51a2
DS
237test_expect_success 'build graph from latest pack with closure' '
238 cd "$TRASH_DIRECTORY/full" &&
239 cat new-idx | git commit-graph write --stdin-packs &&
240 test_path_is_file $objdir/info/commit-graph &&
5af7417b 241 graph_read_expect "9" "extra_edges"
049d51a2
DS
242'
243
244graph_git_behavior 'graph from pack, commit 8 vs merge 1' full commits/8 merge/1
245graph_git_behavior 'graph from pack, commit 8 vs merge 2' full commits/8 merge/2
246
3d5df01b
DS
247test_expect_success 'build graph from commits with closure' '
248 cd "$TRASH_DIRECTORY/full" &&
249 git tag -a -m "merge" tag/merge merge/2 &&
250 git rev-parse tag/merge >commits-in &&
251 git rev-parse merge/1 >>commits-in &&
252 cat commits-in | git commit-graph write --stdin-commits &&
253 test_path_is_file $objdir/info/commit-graph &&
254 graph_read_expect "6"
255'
256
257graph_git_behavior 'graph from commits, commit 8 vs merge 1' full commits/8 merge/1
258graph_git_behavior 'graph from commits, commit 8 vs merge 2' full commits/8 merge/2
259
7547b95b
DS
260test_expect_success 'build graph from commits with append' '
261 cd "$TRASH_DIRECTORY/full" &&
262 git rev-parse merge/3 | git commit-graph write --stdin-commits --append &&
263 test_path_is_file $objdir/info/commit-graph &&
5af7417b 264 graph_read_expect "10" "extra_edges"
7547b95b
DS
265'
266
267graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
268graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
269
59fb8770
DS
270test_expect_success 'build graph using --reachable' '
271 cd "$TRASH_DIRECTORY/full" &&
272 git commit-graph write --reachable &&
273 test_path_is_file $objdir/info/commit-graph &&
5af7417b 274 graph_read_expect "11" "extra_edges"
59fb8770
DS
275'
276
277graph_git_behavior 'append graph, commit 8 vs merge 1' full commits/8 merge/1
278graph_git_behavior 'append graph, commit 8 vs merge 2' full commits/8 merge/2
279
f237c8b6
DS
280test_expect_success 'setup bare repo' '
281 cd "$TRASH_DIRECTORY" &&
282 git clone --bare --no-local full bare &&
283 cd bare &&
177722b3 284 git config core.commitGraph true &&
f237c8b6
DS
285 baredir="./objects"
286'
287
177722b3
DS
288graph_git_behavior 'bare repo, commit 8 vs merge 1' bare commits/8 merge/1
289graph_git_behavior 'bare repo, commit 8 vs merge 2' bare commits/8 merge/2
290
f237c8b6
DS
291test_expect_success 'write graph in bare repo' '
292 cd "$TRASH_DIRECTORY/bare" &&
293 git commit-graph write &&
2a2e32bd 294 test_path_is_file $baredir/info/commit-graph &&
5af7417b 295 graph_read_expect "11" "extra_edges"
f237c8b6
DS
296'
297
177722b3
DS
298graph_git_behavior 'bare repo with graph, commit 8 vs merge 1' bare commits/8 merge/1
299graph_git_behavior 'bare repo with graph, commit 8 vs merge 2' bare commits/8 merge/2
300
7adf5266
DS
301test_expect_success 'perform fast-forward merge in full repo' '
302 cd "$TRASH_DIRECTORY/full" &&
303 git checkout -b merge-5-to-8 commits/5 &&
304 git merge commits/8 &&
305 git show-ref -s merge-5-to-8 >output &&
306 git show-ref -s commits/8 >expect &&
307 test_cmp expect output
308'
309
d5d5d7b6
DS
310test_expect_success 'check that gc computes commit-graph' '
311 cd "$TRASH_DIRECTORY/full" &&
312 git commit --allow-empty -m "blank" &&
313 git commit-graph write --reachable &&
314 cp $objdir/info/commit-graph commit-graph-before-gc &&
315 git reset --hard HEAD~1 &&
316 git config gc.writeCommitGraph true &&
317 git gc &&
318 cp $objdir/info/commit-graph commit-graph-after-gc &&
eb7cc5bc 319 ! test_cmp_bin commit-graph-before-gc commit-graph-after-gc &&
d5d5d7b6 320 git commit-graph write --reachable &&
eb7cc5bc 321 test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
d5d5d7b6
DS
322'
323
d6538246
DS
324test_expect_success 'replace-objects invalidates commit-graph' '
325 cd "$TRASH_DIRECTORY" &&
326 test_when_finished rm -rf replace &&
327 git clone full replace &&
328 (
329 cd replace &&
330 git commit-graph write --reachable &&
331 test_path_is_file .git/objects/info/commit-graph &&
332 git replace HEAD~1 HEAD~2 &&
333 git -c core.commitGraph=false log >expect &&
334 git -c core.commitGraph=true log >actual &&
335 test_cmp expect actual &&
336 git commit-graph write --reachable &&
337 git -c core.commitGraph=false --no-replace-objects log >expect &&
338 git -c core.commitGraph=true --no-replace-objects log >actual &&
339 test_cmp expect actual &&
340 rm -rf .git/objects/info/commit-graph &&
341 git commit-graph write --reachable &&
342 test_path_is_file .git/objects/info/commit-graph
343 )
344'
345
20fd6d57
DS
346test_expect_success 'commit grafts invalidate commit-graph' '
347 cd "$TRASH_DIRECTORY" &&
348 test_when_finished rm -rf graft &&
349 git clone full graft &&
350 (
351 cd graft &&
352 git commit-graph write --reachable &&
353 test_path_is_file .git/objects/info/commit-graph &&
354 H1=$(git rev-parse --verify HEAD~1) &&
355 H3=$(git rev-parse --verify HEAD~3) &&
356 echo "$H1 $H3" >.git/info/grafts &&
357 git -c core.commitGraph=false log >expect &&
358 git -c core.commitGraph=true log >actual &&
359 test_cmp expect actual &&
360 git commit-graph write --reachable &&
361 git -c core.commitGraph=false --no-replace-objects log >expect &&
362 git -c core.commitGraph=true --no-replace-objects log >actual &&
363 test_cmp expect actual &&
364 rm -rf .git/objects/info/commit-graph &&
365 git commit-graph write --reachable &&
366 test_path_is_missing .git/objects/info/commit-graph
367 )
368'
369
370test_expect_success 'replace-objects invalidates commit-graph' '
371 cd "$TRASH_DIRECTORY" &&
372 test_when_finished rm -rf shallow &&
373 git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
374 (
375 cd shallow &&
376 git commit-graph write --reachable &&
377 test_path_is_missing .git/objects/info/commit-graph &&
378 git fetch origin --unshallow &&
379 git commit-graph write --reachable &&
380 test_path_is_file .git/objects/info/commit-graph
381 )
382'
383
d9b9f8a6
DS
384# the verify tests below expect the commit-graph to contain
385# exactly the commits reachable from the commits/8 branch.
386# If the file changes the set of commits in the list, then the
387# offsets into the binary file will result in different edits
388# and the tests will likely break.
389
283e68c7
DS
390test_expect_success 'git commit-graph verify' '
391 cd "$TRASH_DIRECTORY/full" &&
d9b9f8a6 392 git rev-parse commits/8 | git commit-graph write --stdin-commits &&
283e68c7
DS
393 git commit-graph verify >output
394'
395
96af91d4 396NUM_COMMITS=9
437787ae 397NUM_OCTOPUS_EDGES=2
ae0c89d4 398HASH_LEN="$(test_oid rawsz)"
d9b9f8a6
DS
399GRAPH_BYTE_VERSION=4
400GRAPH_BYTE_HASH=5
2bd0365f
DS
401GRAPH_BYTE_CHUNK_COUNT=6
402GRAPH_CHUNK_LOOKUP_OFFSET=8
403GRAPH_CHUNK_LOOKUP_WIDTH=12
404GRAPH_CHUNK_LOOKUP_ROWS=5
405GRAPH_BYTE_OID_FANOUT_ID=$GRAPH_CHUNK_LOOKUP_OFFSET
406GRAPH_BYTE_OID_LOOKUP_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
407 1 * $GRAPH_CHUNK_LOOKUP_WIDTH))
408GRAPH_BYTE_COMMIT_DATA_ID=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
409 2 * $GRAPH_CHUNK_LOOKUP_WIDTH))
9bda8467
DS
410GRAPH_FANOUT_OFFSET=$(($GRAPH_CHUNK_LOOKUP_OFFSET + \
411 $GRAPH_CHUNK_LOOKUP_WIDTH * $GRAPH_CHUNK_LOOKUP_ROWS))
412GRAPH_BYTE_FANOUT1=$(($GRAPH_FANOUT_OFFSET + 4 * 4))
413GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
414GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
415GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
96af91d4 416GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
2e3c0737
DS
417GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
418GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
53614b13
DS
419GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
420GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
421GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
1373e547 422GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
88968ebf 423GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
437787ae
DS
424GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
425GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
426 $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
427GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
41df0e30 428GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
d9b9f8a6 429
f6761faa
ÆAB
430corrupt_graph_setup() {
431 cd "$TRASH_DIRECTORY/full" &&
432 test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
433 cp $objdir/info/commit-graph commit-graph-backup
434}
435
436corrupt_graph_verify() {
437 grepstr=$1
438 test_must_fail git commit-graph verify 2>test_err &&
439 grep -v "^+" test_err >err &&
2ac138d5 440 test_i18ngrep "$grepstr" err &&
43d35618
ÆAB
441 if test "$2" != "no-copy"
442 then
443 cp $objdir/info/commit-graph commit-graph-pre-write-test
444 fi &&
445 git status --short &&
446 GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
447 git commit-graph verify
f6761faa
ÆAB
448}
449
d2b86fba 450# usage: corrupt_graph_and_verify <position> <data> <string> [<zero_pos>]
d9b9f8a6 451# Manipulates the commit-graph file at the position
d2b86fba
JS
452# by inserting the data, optionally zeroing the file
453# starting at <zero_pos>, then runs 'git commit-graph verify'
d9b9f8a6
DS
454# and places the output in the file 'err'. Test 'err' for
455# the given string.
456corrupt_graph_and_verify() {
457 pos=$1
458 data="${2:-\0}"
459 grepstr=$3
f6761faa 460 corrupt_graph_setup &&
d2b86fba
JS
461 orig_size=$(wc -c < $objdir/info/commit-graph) &&
462 zero_pos=${4:-${orig_size}} &&
d9b9f8a6 463 printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc &&
b9cc4056 464 dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null &&
24b451e7 465 generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" &&
f6761faa
ÆAB
466 corrupt_graph_verify "$grepstr"
467
d9b9f8a6
DS
468}
469
7b8ce9c6
ÆAB
470test_expect_success POSIXPERM,SANITY 'detect permission problem' '
471 corrupt_graph_setup &&
472 chmod 000 $objdir/info/commit-graph &&
43d35618 473 corrupt_graph_verify "Could not open" "no-copy"
7b8ce9c6
ÆAB
474'
475
945944ca
ÆAB
476test_expect_success 'detect too small' '
477 corrupt_graph_setup &&
478 echo "a small graph" >$objdir/info/commit-graph &&
479 corrupt_graph_verify "too small"
480'
481
d9b9f8a6
DS
482test_expect_success 'detect bad signature' '
483 corrupt_graph_and_verify 0 "\0" \
484 "graph signature"
485'
486
487test_expect_success 'detect bad version' '
488 corrupt_graph_and_verify $GRAPH_BYTE_VERSION "\02" \
489 "graph version"
490'
491
492test_expect_success 'detect bad hash version' '
1d86c8f0 493 corrupt_graph_and_verify $GRAPH_BYTE_HASH "\03" \
d9b9f8a6
DS
494 "hash version"
495'
496
2bd0365f
DS
497test_expect_success 'detect low chunk count' '
498 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\02" \
499 "missing the .* chunk"
500'
501
502test_expect_success 'detect missing OID fanout chunk' '
503 corrupt_graph_and_verify $GRAPH_BYTE_OID_FANOUT_ID "\0" \
504 "missing the OID Fanout chunk"
505'
506
507test_expect_success 'detect missing OID lookup chunk' '
508 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ID "\0" \
509 "missing the OID Lookup chunk"
510'
511
512test_expect_success 'detect missing commit data chunk' '
513 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATA_ID "\0" \
514 "missing the Commit Data chunk"
515'
516
9bda8467
DS
517test_expect_success 'detect incorrect fanout' '
518 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT1 "\01" \
519 "fanout value"
520'
521
522test_expect_success 'detect incorrect fanout final value' '
523 corrupt_graph_and_verify $GRAPH_BYTE_FANOUT2 "\01" \
524 "fanout value"
525'
526
527test_expect_success 'detect incorrect OID order' '
528 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_ORDER "\01" \
529 "incorrect OID order"
530'
531
96af91d4
DS
532test_expect_success 'detect OID not in object database' '
533 corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
534 "from object database"
535'
536
2e3c0737
DS
537test_expect_success 'detect incorrect tree OID' '
538 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
539 "root tree OID for commit"
540'
541
53614b13
DS
542test_expect_success 'detect incorrect parent int-id' '
543 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_PARENT "\01" \
544 "invalid parent"
545'
546
547test_expect_success 'detect extra parent int-id' '
548 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_EXTRA_PARENT "\00" \
549 "is too long"
550'
551
552test_expect_success 'detect wrong parent' '
553 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_WRONG_PARENT "\01" \
554 "commit-graph parent for"
555'
556
1373e547
DS
557test_expect_success 'detect incorrect generation number' '
558 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\070" \
559 "generation for commit"
560'
561
562test_expect_success 'detect incorrect generation number' '
563 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
564 "non-zero generation number"
565'
566
88968ebf
DS
567test_expect_success 'detect incorrect commit date' '
568 corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
569 "commit date"
570'
571
437787ae
DS
572test_expect_success 'detect incorrect parent for octopus merge' '
573 corrupt_graph_and_verify $GRAPH_BYTE_OCTOPUS "\01" \
574 "invalid parent"
575'
576
41df0e30
DS
577test_expect_success 'detect invalid checksum hash' '
578 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
579 "incorrect checksum"
580'
581
d2b86fba
JS
582test_expect_success 'detect incorrect chunk count' '
583 corrupt_graph_and_verify $GRAPH_BYTE_CHUNK_COUNT "\377" \
584 "chunk lookup table entry missing" $GRAPH_CHUNK_LOOKUP_OFFSET
585'
586
e0fd51e1
DS
587test_expect_success 'git fsck (checks commit-graph)' '
588 cd "$TRASH_DIRECTORY/full" &&
589 git fsck &&
590 corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
591 "incorrect checksum" &&
43d35618 592 cp commit-graph-pre-write-test $objdir/info/commit-graph &&
e0fd51e1
DS
593 test_must_fail git fsck
594'
595
dade47c0
JT
596test_expect_success 'setup non-the_repository tests' '
597 rm -rf repo &&
598 git init repo &&
599 test_commit -C repo one &&
600 test_commit -C repo two &&
601 git -C repo config core.commitGraph true &&
602 git -C repo rev-parse two | \
603 git -C repo commit-graph write --stdin-commits
604'
605
606test_expect_success 'parse_commit_in_graph works for non-the_repository' '
607 test-tool repository parse_commit_in_graph \
608 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
3c458630
SG
609 {
610 git -C repo log --pretty=format:"%ct " -1 &&
611 git -C repo rev-parse one
612 } >expect &&
dade47c0
JT
613 test_cmp expect actual &&
614
615 test-tool repository parse_commit_in_graph \
616 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
3c458630 617 git -C repo log --pretty="%ct" -1 one >expect &&
dade47c0
JT
618 test_cmp expect actual
619'
620
621test_expect_success 'get_commit_tree_in_graph works for non-the_repository' '
622 test-tool repository get_commit_tree_in_graph \
623 repo/.git repo "$(git -C repo rev-parse two)" >actual &&
3c458630 624 git -C repo rev-parse two^{tree} >expect &&
dade47c0
JT
625 test_cmp expect actual &&
626
627 test-tool repository get_commit_tree_in_graph \
628 repo/.git repo "$(git -C repo rev-parse one)" >actual &&
3c458630 629 git -C repo rev-parse one^{tree} >expect &&
dade47c0
JT
630 test_cmp expect actual
631'
632
16749b8d 633test_expect_success 'corrupt commit-graph write (broken parent)' '
23424ea7
TB
634 rm -rf repo &&
635 git init repo &&
636 (
637 cd repo &&
638 empty="$(git mktree </dev/null)" &&
639 cat >broken <<-EOF &&
640 tree $empty
48c10cc0 641 parent $ZERO_OID
23424ea7
TB
642 author whatever <whatever@example.com> 1234 -0000
643 committer whatever <whatever@example.com> 1234 -0000
644
645 broken commit
646 EOF
647 broken="$(git hash-object -w -t commit --literally broken)" &&
648 git commit-tree -p "$broken" -m "good commit" "$empty" >good &&
649 test_must_fail git commit-graph write --stdin-commits \
650 <good 2>test_err &&
651 test_i18ngrep "unable to parse commit" test_err
652 )
653'
654
806278de 655test_expect_success 'corrupt commit-graph write (missing tree)' '
23424ea7
TB
656 rm -rf repo &&
657 git init repo &&
658 (
659 cd repo &&
660 tree="$(git mktree </dev/null)" &&
661 cat >broken <<-EOF &&
48c10cc0 662 parent $ZERO_OID
23424ea7
TB
663 author whatever <whatever@example.com> 1234 -0000
664 committer whatever <whatever@example.com> 1234 -0000
665
666 broken commit
667 EOF
668 broken="$(git hash-object -w -t commit --literally broken)" &&
669 git commit-tree -p "$broken" -m "good" "$tree" >good &&
670 test_must_fail git commit-graph write --stdin-commits \
671 <good 2>test_err &&
228c78fb 672 test_i18ngrep "unable to parse commit" test_err
23424ea7
TB
673 )
674'
675
f237c8b6 676test_done