Imported Upstream version 2.8.4
[platform/upstream/git.git] / t / t1450-fsck.sh
index 956673b..7ee8ea0 100755 (executable)
@@ -77,11 +77,31 @@ test_expect_success 'object with bad sha1' '
 test_expect_success 'branch pointing to non-commit' '
        git rev-parse HEAD^{tree} >.git/refs/heads/invalid &&
        test_when_finished "git update-ref -d refs/heads/invalid" &&
-       git fsck 2>out &&
+       test_must_fail git fsck 2>out &&
        cat out &&
        grep "not a commit" out
 '
 
+test_expect_success 'HEAD link pointing at a funny object' '
+       test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
+       mv .git/HEAD .git/SAVED_HEAD &&
+       echo 0000000000000000000000000000000000000000 >.git/HEAD &&
+       # avoid corrupt/broken HEAD from interfering with repo discovery
+       test_must_fail env GIT_DIR=.git git fsck 2>out &&
+       cat out &&
+       grep "detached HEAD points" out
+'
+
+test_expect_success 'HEAD link pointing at a funny place' '
+       test_when_finished "mv .git/SAVED_HEAD .git/HEAD" &&
+       mv .git/HEAD .git/SAVED_HEAD &&
+       echo "ref: refs/funny/place" >.git/HEAD &&
+       # avoid corrupt/broken HEAD from interfering with repo discovery
+       test_must_fail env GIT_DIR=.git git fsck 2>out &&
+       cat out &&
+       grep "HEAD points to something strange" out
+'
+
 test_expect_success 'email without @ is okay' '
        git cat-file commit HEAD >basis &&
        sed "s/@/AT/" basis >okay &&
@@ -156,6 +176,18 @@ test_expect_success 'integer overflow in timestamps is reported' '
        grep "error in commit $new.*integer overflow" out
 '
 
+test_expect_success 'commit with NUL in header' '
+       git cat-file commit HEAD >basis &&
+       sed "s/author ./author Q/" <basis | q_to_nul >commit-NUL-header &&
+       new=$(git hash-object -t commit -w --stdin <commit-NUL-header) &&
+       test_when_finished "remove_object $new" &&
+       git update-ref refs/heads/bogus "$new" &&
+       test_when_finished "git update-ref -d refs/heads/bogus" &&
+       test_must_fail git fsck 2>out &&
+       cat out &&
+       grep "error in commit $new.*unterminated header: NUL at offset" out
+'
+
 test_expect_success 'malformatted tree object' '
        test_when_finished "git update-ref -d refs/tags/wrong" &&
        test_when_finished "remove_object \$T" &&
@@ -256,6 +288,26 @@ test_expect_success 'tag with bad tagger' '
        grep "error in tag .*: invalid author/committer" out
 '
 
+test_expect_success 'tag with NUL in header' '
+       sha=$(git rev-parse HEAD) &&
+       q_to_nul >tag-NUL-header <<-EOF &&
+       object $sha
+       type commit
+       tag contains-Q-in-header
+       tagger T A Gger <tagger@example.com> 1234567890 -0000
+
+       This is an invalid tag.
+       EOF
+
+       tag=$(git hash-object --literally -t tag -w --stdin <tag-NUL-header) &&
+       test_when_finished "remove_object $tag" &&
+       echo $tag >.git/refs/tags/wrong &&
+       test_when_finished "git update-ref -d refs/tags/wrong" &&
+       test_must_fail git fsck --tags 2>out &&
+       cat out &&
+       grep "error in tag $tag.*unterminated header: NUL at offset" out
+'
+
 test_expect_success 'cleaned up' '
        git fsck >actual 2>&1 &&
        test_cmp empty actual
@@ -375,6 +427,24 @@ test_expect_success 'fsck allows .Ňit' '
        )
 '
 
+test_expect_success 'NUL in commit' '
+       rm -fr nul-in-commit &&
+       git init nul-in-commit &&
+       (
+               cd nul-in-commit &&
+               git commit --allow-empty -m "initial commitQNUL after message" &&
+               git cat-file commit HEAD >original &&
+               q_to_nul <original >munged &&
+               git hash-object -w -t commit --stdin <munged >name &&
+               git branch bad $(cat name) &&
+
+               test_must_fail git -c fsck.nulInCommit=error fsck 2>warn.1 &&
+               grep nulInCommit warn.1 &&
+               git fsck 2>warn.2 &&
+               grep nulInCommit warn.2
+       )
+'
+
 # create a static test repo which is broken by omitting
 # one particular object ($1, which is looked up via rev-parse
 # in the new repository).