@@ -9,6 +9,7 @@ test_description='git fsck random collection of tests
9
9
. ./test-lib.sh
10
10
11
11
test_expect_success setup '
12
+ test_oid_init &&
12
13
git config gc.auto 0 &&
13
14
git config i18n.commitencoding ISO-8859-1 &&
14
15
test_commit A fileA one &&
@@ -54,8 +55,8 @@ test_expect_success 'setup: helpers for corruption tests' '
54
55
55
56
test_expect_success ' object with bad sha1' '
56
57
sha=$(echo blob | git hash-object -w --stdin) &&
57
- old=$(echo $sha | sed "s+^..+&/+ ") &&
58
- new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&
58
+ old=$(test_oid_to_path " $sha") &&
59
+ new=$(dirname $old)/$(test_oid ff_2) &&
59
60
sha="$(dirname $new)$(basename $new)" &&
60
61
mv .git/objects/$old .git/objects/$new &&
61
62
test_when_finished "remove_object $sha" &&
@@ -84,7 +85,7 @@ test_expect_success 'branch pointing to non-commit' '
84
85
test_expect_success ' HEAD link pointing at a funny object' '
85
86
test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
86
87
mv .git/HEAD .git/SAVED_HEAD &&
87
- echo 0000000000000000000000000000000000000000 >.git/HEAD &&
88
+ echo $ZERO_OID >.git/HEAD &&
88
89
# avoid corrupt/broken HEAD from interfering with repo discovery
89
90
test_must_fail env GIT_DIR=.git git fsck 2>out &&
90
91
cat out &&
@@ -244,10 +245,16 @@ test_expect_success 'tree object with duplicate entries' '
244
245
'
245
246
246
247
test_expect_success ' unparseable tree object' '
248
+ test_oid_cache <<-\EOF &&
249
+ junk sha1:twenty-bytes-of-junk
250
+ junk sha256:twenty-bytes-of-junk-twelve-more
251
+ EOF
252
+
247
253
test_when_finished "git update-ref -d refs/heads/wrong" &&
248
254
test_when_finished "remove_object \$tree_sha1" &&
249
255
test_when_finished "remove_object \$commit_sha1" &&
250
- tree_sha1=$(printf "100644 \0twenty-bytes-of-junk" | git hash-object -t tree --stdin -w --literally) &&
256
+ junk=$(test_oid junk) &&
257
+ tree_sha1=$(printf "100644 \0$junk" | git hash-object -t tree --stdin -w --literally) &&
251
258
commit_sha1=$(git commit-tree $tree_sha1) &&
252
259
git update-ref refs/heads/wrong $commit_sha1 &&
253
260
test_must_fail git fsck 2>out &&
@@ -275,8 +282,9 @@ test_expect_success 'tree entry with type mismatch' '
275
282
'
276
283
277
284
test_expect_success ' tag pointing to nonexistent' '
278
- cat >invalid-tag <<-\EOF &&
279
- object ffffffffffffffffffffffffffffffffffffffff
285
+ badoid=$(test_oid deadbeef) &&
286
+ cat >invalid-tag <<-EOF &&
287
+ object $badoid
280
288
type commit
281
289
tag invalid
282
290
tagger T A Gger <[email protected] > 1234567890 -0000
@@ -386,8 +394,8 @@ test_expect_success 'rev-list --verify-objects' '
386
394
387
395
test_expect_success ' rev-list --verify-objects with bad sha1' '
388
396
sha=$(echo blob | git hash-object -w --stdin) &&
389
- old=$(echo $sha | sed "s+^..+&/+" ) &&
390
- new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&
397
+ old=$(test_oid_to_path $sha) &&
398
+ new=$(dirname $old)/$(test_oid ff_2) &&
391
399
sha="$(dirname $new)$(basename $new)" &&
392
400
mv .git/objects/$old .git/objects/$new &&
393
401
test_when_finished "remove_object $sha" &&
@@ -402,7 +410,7 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
402
410
403
411
test_might_fail git rev-list --verify-objects refs/heads/bogus >/dev/null 2>out &&
404
412
cat out &&
405
- test_i18ngrep -q "error: hash mismatch 63ffffffffffffffffffffffffffffffffffffff " out
413
+ test_i18ngrep -q "error: hash mismatch $(dirname $new)$(test_oid ff_2) " out
406
414
'
407
415
408
416
test_expect_success ' force fsck to ignore double author' '
@@ -417,13 +425,12 @@ test_expect_success 'force fsck to ignore double author' '
417
425
'
418
426
419
427
_bz=' \0'
420
- _bz5=" $_bz$_bz$_bz$_bz$_bz "
421
- _bz20=" $_bz5$_bz5$_bz5$_bz5 "
428
+ _bzoid=$( printf $ZERO_OID | sed -e ' s/00/\\0/g' )
422
429
423
430
test_expect_success ' fsck notices blob entry pointing to null sha1' '
424
431
(git init null-blob &&
425
432
cd null-blob &&
426
- sha=$(printf "100644 file$_bz$_bz20 " |
433
+ sha=$(printf "100644 file$_bz$_bzoid " |
427
434
git hash-object -w --stdin -t tree) &&
428
435
git fsck 2>out &&
429
436
cat out &&
@@ -434,7 +441,7 @@ test_expect_success 'fsck notices blob entry pointing to null sha1' '
434
441
test_expect_success ' fsck notices submodule entry pointing to null sha1' '
435
442
(git init null-commit &&
436
443
cd null-commit &&
437
- sha=$(printf "160000 submodule$_bz$_bz20 " |
444
+ sha=$(printf "160000 submodule$_bz$_bzoid " |
438
445
git hash-object -w --stdin -t tree) &&
439
446
git fsck 2>out &&
440
447
cat out &&
@@ -586,7 +593,7 @@ test_expect_success 'fsck --connectivity-only' '
586
593
# its type. That lets us see that --connectivity-only is
587
594
# not actually looking at the contents, but leaves it
588
595
# free to examine the type if it chooses.
589
- empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
596
+ empty=.git/objects/$(test_oid_to_path $EMPTY_BLOB) &&
590
597
blob=$(echo unrelated | git hash-object -w --stdin) &&
591
598
mv -f $(sha1_file $blob) $empty &&
592
599
@@ -631,10 +638,12 @@ test_expect_success 'fsck --name-objects' '
631
638
632
639
test_expect_success ' alternate objects are correctly blamed' '
633
640
test_when_finished "rm -rf alt.git .git/objects/info/alternates" &&
641
+ name=$(test_oid numeric) &&
642
+ path=$(test_oid_to_path "$name") &&
634
643
git init --bare alt.git &&
635
644
echo "../../alt.git/objects" >.git/objects/info/alternates &&
636
- mkdir alt.git/objects/12 &&
637
- >alt.git/objects/12/34567890123456789012345678901234567890 &&
645
+ mkdir alt.git/objects/$(dirname $path) &&
646
+ >alt.git/objects/$(dirname $path)/$(basename $path) &&
638
647
test_must_fail git fsck >out 2>&1 &&
639
648
test_i18ngrep alt.git out
640
649
'
0 commit comments