Skip to content

Commit 69c1f8b

Browse files
committed
Add regression tests for stricter tag fsck'ing
The intent of the new test case is to catch general breakages in the fsck_tag() function, not so much to test it extensively, trying to strike the proper balance between thoroughness and speed. While it *would* have been nice to test the code path where fsck_object() encounters an invalid tag object, this is not possible using git fsck: tag objects are parsed already before fsck'ing (and the parser already fails upon such objects). Even worse: we would not even be able write out invalid tag objects because git hash-object parses those objects, too, unless we resorted to really ugly hacks such as using something like this in the unit tests (essentially depending on Perl *and* Compress::Zlib): hash_invalid_object () { contents="$(printf '%s %d\0%s' "$1" ${#2} "$2")" && sha1=$(echo "$contents" | test-sha1) && suffix=${sha1#??} && mkdir -p .git/objects/${sha1%$suffix} && echo "$contents" | perl -MCompress::Zlib -e 'undef $/; print compress(<>)' \ > .git/objects/${sha1%$suffix}/$suffix && echo $sha1 } Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 517cb11 commit 69c1f8b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

t/t1450-fsck.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,26 @@ test_expect_success 'tag pointing to something else than its type' '
194194
test_must_fail git fsck --tags
195195
'
196196

197+
test_expect_success 'tag with incorrect tag name & missing tagger' '
198+
sha=$(git rev-parse HEAD) &&
199+
cat >wrong-tag <<-EOF &&
200+
object $sha
201+
type commit
202+
tag wrong name format
203+
204+
This is an invalid tag.
205+
EOF
206+
207+
tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
208+
test_when_finished "remove_object $tag" &&
209+
echo $tag >.git/refs/tags/wrong &&
210+
test_when_finished "git update-ref -d refs/tags/wrong" &&
211+
git fsck --tags 2>out &&
212+
cat out &&
213+
grep "invalid .tag. name" out &&
214+
grep "expected .tagger. line" out
215+
'
216+
197217
test_expect_success 'cleaned up' '
198218
git fsck >actual 2>&1 &&
199219
test_cmp empty actual

0 commit comments

Comments
 (0)