Skip to content

Commit 42cd635

Browse files
avargitster
authored andcommitted
fsck tests: test current hash/type mismatch behavior
If fsck we move an object around between .git/objects/?? directories to simulate a hash mismatch "git fsck" will currently hard die() in object-file.c. This behavior will be fixed in subsequent commits, but let's test for it as-is for now. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f7a0dba commit 42cd635

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

t/t1450-fsck.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ test_expect_success 'object with hash mismatch' '
6969
)
7070
'
7171

72+
test_expect_success 'object with hash and type mismatch' '
73+
git init --bare hash-type-mismatch &&
74+
(
75+
cd hash-type-mismatch &&
76+
77+
oid=$(echo blob | git hash-object -w --stdin -t garbage --literally) &&
78+
old=$(test_oid_to_path "$oid") &&
79+
new=$(dirname $old)/$(test_oid ff_2) &&
80+
oid="$(dirname $new)$(basename $new)" &&
81+
82+
mv objects/$old objects/$new &&
83+
git update-index --add --cacheinfo 100644 $oid foo &&
84+
tree=$(git write-tree) &&
85+
cmt=$(echo bogus | git commit-tree $tree) &&
86+
git update-ref refs/heads/bogus $cmt &&
87+
88+
cat >expect <<-\EOF &&
89+
fatal: invalid object type
90+
EOF
91+
test_must_fail git fsck 2>actual &&
92+
test_cmp expect actual
93+
)
94+
'
95+
7296
test_expect_success 'branch pointing to non-commit' '
7397
git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
7498
test_when_finished "git update-ref -d refs/heads/invalid" &&

0 commit comments

Comments
 (0)