Skip to content

Commit 8de6b38

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff4cb42 commit 8de6b38

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

t/t1450-fsck.sh

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ test_description='git fsck random collection of tests
99
. ./test-lib.sh
1010

1111
test_expect_success setup '
12+
test_oid_init &&
1213
git config gc.auto 0 &&
1314
git config i18n.commitencoding ISO-8859-1 &&
1415
test_commit A fileA one &&
@@ -54,8 +55,8 @@ test_expect_success 'setup: helpers for corruption tests' '
5455

5556
test_expect_success 'object with bad sha1' '
5657
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) &&
5960
sha="$(dirname $new)$(basename $new)" &&
6061
mv .git/objects/$old .git/objects/$new &&
6162
test_when_finished "remove_object $sha" &&
@@ -84,7 +85,7 @@ test_expect_success 'branch pointing to non-commit' '
8485
test_expect_success 'HEAD link pointing at a funny object' '
8586
test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
8687
mv .git/HEAD .git/SAVED_HEAD &&
87-
echo 0000000000000000000000000000000000000000 >.git/HEAD &&
88+
echo $ZERO_OID >.git/HEAD &&
8889
# avoid corrupt/broken HEAD from interfering with repo discovery
8990
test_must_fail env GIT_DIR=.git git fsck 2>out &&
9091
cat out &&
@@ -244,10 +245,16 @@ test_expect_success 'tree object with duplicate entries' '
244245
'
245246

246247
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+
247253
test_when_finished "git update-ref -d refs/heads/wrong" &&
248254
test_when_finished "remove_object \$tree_sha1" &&
249255
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) &&
251258
commit_sha1=$(git commit-tree $tree_sha1) &&
252259
git update-ref refs/heads/wrong $commit_sha1 &&
253260
test_must_fail git fsck 2>out &&
@@ -275,8 +282,9 @@ test_expect_success 'tree entry with type mismatch' '
275282
'
276283

277284
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
280288
type commit
281289
tag invalid
282290
tagger T A Gger <[email protected]> 1234567890 -0000
@@ -386,8 +394,8 @@ test_expect_success 'rev-list --verify-objects' '
386394

387395
test_expect_success 'rev-list --verify-objects with bad sha1' '
388396
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) &&
391399
sha="$(dirname $new)$(basename $new)" &&
392400
mv .git/objects/$old .git/objects/$new &&
393401
test_when_finished "remove_object $sha" &&
@@ -402,7 +410,7 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
402410
403411
test_might_fail git rev-list --verify-objects refs/heads/bogus >/dev/null 2>out &&
404412
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
406414
'
407415

408416
test_expect_success 'force fsck to ignore double author' '
@@ -417,13 +425,12 @@ test_expect_success 'force fsck to ignore double author' '
417425
'
418426

419427
_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')
422429

423430
test_expect_success 'fsck notices blob entry pointing to null sha1' '
424431
(git init null-blob &&
425432
cd null-blob &&
426-
sha=$(printf "100644 file$_bz$_bz20" |
433+
sha=$(printf "100644 file$_bz$_bzoid" |
427434
git hash-object -w --stdin -t tree) &&
428435
git fsck 2>out &&
429436
cat out &&
@@ -434,7 +441,7 @@ test_expect_success 'fsck notices blob entry pointing to null sha1' '
434441
test_expect_success 'fsck notices submodule entry pointing to null sha1' '
435442
(git init null-commit &&
436443
cd null-commit &&
437-
sha=$(printf "160000 submodule$_bz$_bz20" |
444+
sha=$(printf "160000 submodule$_bz$_bzoid" |
438445
git hash-object -w --stdin -t tree) &&
439446
git fsck 2>out &&
440447
cat out &&
@@ -586,7 +593,7 @@ test_expect_success 'fsck --connectivity-only' '
586593
# its type. That lets us see that --connectivity-only is
587594
# not actually looking at the contents, but leaves it
588595
# free to examine the type if it chooses.
589-
empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
596+
empty=.git/objects/$(test_oid_to_path $EMPTY_BLOB) &&
590597
blob=$(echo unrelated | git hash-object -w --stdin) &&
591598
mv -f $(sha1_file $blob) $empty &&
592599
@@ -631,10 +638,12 @@ test_expect_success 'fsck --name-objects' '
631638

632639
test_expect_success 'alternate objects are correctly blamed' '
633640
test_when_finished "rm -rf alt.git .git/objects/info/alternates" &&
641+
name=$(test_oid numeric) &&
642+
path=$(test_oid_to_path "$name") &&
634643
git init --bare alt.git &&
635644
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) &&
638647
test_must_fail git fsck >out 2>&1 &&
639648
test_i18ngrep alt.git out
640649
'

0 commit comments

Comments
 (0)