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