add tests for cloning corrupted repositories
authorJeff King <peff@peff.net>
Mon, 25 Mar 2013 20:22:29 +0000 (16:22 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Mar 2013 20:47:11 +0000 (13:47 -0700)
We try not to let corruption pass unnoticed over fetches and
clones. For the most part, this works, but there are some
broken corner cases, including:

1. We do not detect missing objects over git-aware
transports. This is a little hard to test, because the
sending side will actually complain about the missing
object.

To fool it, we corrupt a repository such that we have a
"misnamed" object: it claims to be sha1 X, but is
really Y. This lets the sender blindly transmit it, but
it is the receiver's responsibility to verify that what
it got is sane (and it does not).

2. We do not detect missing or misnamed blobs during the
checkout phase of clone.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t1060-object-corruption.sh
index cfd1f23a119fa3ac30304506f54ab50f8073b71f..e29406e27ae84b2b3c18de18b93014466d6dc0d8 100755 (executable)
@@ -33,6 +33,19 @@ test_expect_success 'setup repo with missing object' '
        )
 '
 
+test_expect_success 'setup repo with misnamed object' '
+       git init misnamed &&
+       (
+               cd misnamed &&
+               test_commit content &&
+               good=$(obj_to_file HEAD:content.t) &&
+               blob=$(echo corrupt | git hash-object -w --stdin) &&
+               bad=$(obj_to_file $blob) &&
+               rm -f "$good" &&
+               mv "$bad" "$good"
+       )
+'
+
 test_expect_success 'streaming a corrupt blob fails' '
        (
                cd bit-error &&
@@ -56,4 +69,32 @@ test_expect_success 'read-tree -u detects missing objects' '
        )
 '
 
+# We use --bare to make sure that the transport detects it, not the checkout
+# phase.
+test_expect_success 'clone --no-local --bare detects corruption' '
+       test_must_fail git clone --no-local --bare bit-error corrupt-transport
+'
+
+test_expect_success 'clone --no-local --bare detects missing object' '
+       test_must_fail git clone --no-local --bare missing missing-transport
+'
+
+test_expect_failure 'clone --no-local --bare detects misnamed object' '
+       test_must_fail git clone --no-local --bare misnamed misnamed-transport
+'
+
+# We do not expect --local to detect corruption at the transport layer,
+# so we are really checking the checkout() code path.
+test_expect_success 'clone --local detects corruption' '
+       test_must_fail git clone --local bit-error corrupt-checkout
+'
+
+test_expect_failure 'clone --local detects missing objects' '
+       test_must_fail git clone --local missing missing-checkout
+'
+
+test_expect_failure 'clone --local detects misnamed objects' '
+       test_must_fail git clone --local misnamed misnamed-checkout
+'
+
 test_done