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