Add regression tests for stricter tag fsck'ing
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 11 Sep 2014 14:26:41 +0000 (16:26 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Sep 2014 21:19:09 +0000 (14:19 -0700)
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 <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1450-fsck.sh
index 8c739c96135fe942d7e76236eb34429be93937a8..1b96b4045bd270c5f3af2dd10d126d7b4b4ce706 100755 (executable)
@@ -194,6 +194,25 @@ test_expect_success 'tag pointing to something else than its type' '
        test_must_fail git fsck --tags
 '
 
+test_expect_success 'tag with incorrect tag name & missing tagger' '
+       sha=$(git rev-parse HEAD) &&
+       cat >wrong-tag <<-EOF &&
+       object $sha
+       type commit
+       tag wrong name format
+
+       This is an invalid tag.
+       EOF
+
+       tag=$(git hash-object -t tag -w --stdin <wrong-tag) &&
+       test_when_finished "remove_object $tag" &&
+       echo $tag >.git/refs/tags/wrong &&
+       test_when_finished "git update-ref -d refs/tags/wrong" &&
+       git fsck --tags 2>out &&
+       grep "invalid .tag. name" out &&
+       grep "expected .tagger. line" out
+'
+
 test_expect_success 'cleaned up' '
        git fsck >actual 2>&1 &&
        test_cmp empty actual