t1450: make hash size independent
Replace several hard-coded full and partial object IDs with variables or computed values. Create junk data to stuff inside an invalid tree that can be either 20 or 32 bytes long. Compute a binary all-zeros object ID instead of hard-coding a 20-byte length. Additionally, compute various object IDs by using test_oid and $EMPTY_BLOB so that this test works with multiple hash algorithms. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jun 28, 2019 at 22:59 UTC
8de6b383c15a527c222688161156eb5c5acfecc4
1 file changed
+25
-16
t/t1450-fsck.sh
+25
-16
@@ -9,6 +9,7 @@ test_description='git fsck random collection of tests
9
. ./test-lib.sh
10
11
test_expect_success setup '
12
+ test_oid_init &&
13
git config gc.auto 0 &&
14
git config i18n.commitencoding ISO-8859-1 &&
15
test_commit A fileA one &&
@@ -54,8 +55,8 @@ test_expect_success 'setup: helpers for corruption tests' '
55
56
test_expect_success 'object with bad sha1' '
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) &&
60
sha="$(dirname $new)$(basename $new)" &&
61
mv .git/objects/$old .git/objects/$new &&
62
test_when_finished "remove_object $sha" &&
@@ -84,7 +85,7 @@ test_expect_success 'branch pointing to non-commit' '
85
test_expect_success 'HEAD link pointing at a funny object' '
86
test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
87
mv .git/HEAD .git/SAVED_HEAD &&
87
- echo 0000000000000000000000000000000000000000 >.git/HEAD &&
88
+ echo $ZERO_OID >.git/HEAD &&
89
# avoid corrupt/broken HEAD from interfering with repo discovery
90
test_must_fail env GIT_DIR=.git git fsck 2>out &&
91
cat out &&
@@ -244,10 +245,16 @@ test_expect_success 'tree object with duplicate entries' '
245
'
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
+
253
test_when_finished "git update-ref -d refs/heads/wrong" &&
254
test_when_finished "remove_object \$tree_sha1" &&
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) &&
258
commit_sha1=$(git commit-tree $tree_sha1) &&
259
git update-ref refs/heads/wrong $commit_sha1 &&
260
test_must_fail git fsck 2>out &&
@@ -275,8 +282,9 @@ test_expect_success 'tree entry with type mismatch' '
282
'
283
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
288
type commit
289
tag invalid
290
tagger T A Gger <tagger@example.com> 1234567890 -0000
@@ -386,8 +394,8 @@ test_expect_success 'rev-list --verify-objects' '
394
395
test_expect_success 'rev-list --verify-objects with bad sha1' '
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) &&
399
sha="$(dirname $new)$(basename $new)" &&
400
mv .git/objects/$old .git/objects/$new &&
401
test_when_finished "remove_object $sha" &&
@@ -402,7 +410,7 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
410
411
test_might_fail git rev-list --verify-objects refs/heads/bogus >/dev/null 2>out &&
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
414
'
415
416
test_expect_success 'force fsck to ignore double author' '
@@ -417,13 +425,12 @@ test_expect_success 'force fsck to ignore double author' '
425
'
426
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')
429
430
test_expect_success 'fsck notices blob entry pointing to null sha1' '
431
(git init null-blob &&
432
cd null-blob &&
426
- sha=$(printf "100644 file$_bz$_bz20" |
433
+ sha=$(printf "100644 file$_bz$_bzoid" |
434
git hash-object -w --stdin -t tree) &&
435
git fsck 2>out &&
436
cat out &&
@@ -434,7 +441,7 @@ test_expect_success 'fsck notices blob entry pointing to null sha1' '
441
test_expect_success 'fsck notices submodule entry pointing to null sha1' '
442
(git init null-commit &&
443
cd null-commit &&
437
- sha=$(printf "160000 submodule$_bz$_bz20" |
444
+ sha=$(printf "160000 submodule$_bz$_bzoid" |
445
git hash-object -w --stdin -t tree) &&
446
git fsck 2>out &&
447
cat out &&
@@ -586,7 +593,7 @@ test_expect_success 'fsck --connectivity-only' '
593
# its type. That lets us see that --connectivity-only is
594
# not actually looking at the contents, but leaves it
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) &&
597
blob=$(echo unrelated | git hash-object -w --stdin) &&
598
mv -f $(sha1_file $blob) $empty &&
599
@@ -631,10 +638,12 @@ test_expect_success 'fsck --name-objects' '
638
639
test_expect_success 'alternate objects are correctly blamed' '
640
test_when_finished "rm -rf alt.git .git/objects/info/alternates" &&
641
+ name=$(test_oid numeric) &&
642
+ path=$(test_oid_to_path "$name") &&
643
git init --bare alt.git &&
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) &&
647
test_must_fail git fsck >out 2>&1 &&
648
test_i18ngrep alt.git out
649
'