Subject: Re: [PATCH v3] Test fsck a bit harder

From: Johannes Sixt <[email-masked]>
Date: Fri, 20 Feb 2009 21:29:51 +0100

Thomas Rast schrieb:
> +test_expect_success 'object with bad sha1' '
> +	sha=$(echo blob | git hash-object -w --stdin) &&
> +	echo $sha &&
> +	old=$(echo $sha | sed "s+^..+&/+") &&
> +	new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff &&

	new=${old%/*}/ffffffffffffffffffffffffffffffffffffff &&

> +	sha="$(dirname $new)$(basename $new)"

	sha=${new%/*}${new##*/} &&

note the '&&'!

> +	mv .git/objects/$old .git/objects/$new &&
> +	git update-index --add --cacheinfo 100644 $sha foo &&
> +	tree=$(git write-tree) &&
> +	cmt=$(echo bogus | git commit-tree $tree) &&
> +	git update-ref refs/heads/bogus $cmt &&
> +	(git fsck 2>out; true) &&

Any particular reason not to use

	test_must_fail git fsck 2>out &&

here?

> +	grep "$sha.*corrupt" out &&
> +	rm -f .git/objects/$new &&
> +	git update-ref -d refs/heads/bogus &&
> +	git read-tree -u --reset HEAD
> +'

Shouldn't the cleanup be outside the test_expect_success so that later 
tests work even if this one fails? (Ditto for subsequent tests.)

> +test_expect_success 'tag pointing to nonexistent' '
> +	tag=$(git hash-object -t tag -w --stdin < invalid-tag) &&
> +	echo $tag > .git/refs/tags/invalid &&
> +	git fsck 2>&1 | tee out &&

	test_must_fail git fsck > out 2>&1 &&

> +	grep "missing commit ffffffffffffffffffffffffffffffffffffffff" out &&
...
> +test_expect_success 'tag pointing to something else than its type' '
> +	tag=$(git hash-object -t tag -w --stdin < wrong-tag) &&
> +	echo $tag > .git/refs/tags/wrong &&
> +	git fsck 2>&1 | tee out &&

	test_must_fail git fsck > out 2>&1 &&

> +	grep "Object.*is a blob, not a commit" out &&
...

-- Hannes