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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Oct 1, 2021 at 11:16 UTC
42cd635b21f3a440c775022003b168feef946fa6
1 file changed
+24
t/t1450-fsck.sh
+24
@@ -69,6 +69,30 @@ test_expect_success 'object with hash mismatch' '
69
)
70
'
71
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
+
96
test_expect_success 'branch pointing to non-commit' '
97
git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
98
test_when_finished "git update-ref -d refs/heads/invalid" &&