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