summaryrefslogtreecommitdiff
path: root/t/t1450-fsck.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t1450-fsck.sh')
-rwxr-xr-xt/t1450-fsck.sh109
1 files changed, 106 insertions, 3 deletions
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index cfb32b6..7ee8ea0 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -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" &&
@@ -231,8 +263,8 @@ test_expect_success 'tag with incorrect tag name & missing tagger' '
git fsck --tags 2>out &&
cat >expect <<-EOF &&
- warning in tag $tag: invalid '\''tag'\'' name: wrong name format
- warning in tag $tag: invalid format - expected '\''tagger'\'' line
+ warning in tag $tag: badTagName: invalid '\''tag'\'' name: wrong name format
+ warning in tag $tag: missingTaggerEntry: invalid format - expected '\''tagger'\'' line
EOF
test_cmp expect out
'
@@ -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
@@ -287,6 +339,17 @@ test_expect_success 'rev-list --verify-objects with bad sha1' '
grep -q "error: sha1 mismatch 63ffffffffffffffffffffffffffffffffffffff" out
'
+test_expect_success 'force fsck to ignore double author' '
+ git cat-file commit HEAD >basis &&
+ sed "s/^author .*/&,&/" <basis | tr , \\n >multiple-authors &&
+ new=$(git hash-object -t commit -w --stdin <multiple-authors) &&
+ 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 &&
+ git -c fsck.multipleAuthors=ignore fsck
+'
+
_bz='\0'
_bz5="$_bz$_bz$_bz$_bz$_bz"
_bz20="$_bz5$_bz5$_bz5$_bz5"
@@ -364,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).
@@ -420,4 +501,26 @@ test_expect_success 'fsck notices ref pointing to missing tag' '
test_must_fail git -C missing fsck
'
+test_expect_success 'fsck --connectivity-only' '
+ rm -rf connectivity-only &&
+ git init connectivity-only &&
+ (
+ cd connectivity-only &&
+ touch empty &&
+ git add empty &&
+ test_commit empty &&
+ empty=.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 &&
+ rm -f $empty &&
+ echo invalid >$empty &&
+ test_must_fail git fsck --strict &&
+ git fsck --strict --connectivity-only &&
+ tree=$(git rev-parse HEAD:) &&
+ suffix=${tree#??} &&
+ tree=.git/objects/${tree%$suffix}/$suffix &&
+ rm -f $tree &&
+ echo invalid >$tree &&
+ test_must_fail git fsck --strict --connectivity-only
+ )
+'
+
test_done