Skip to content

Commit 0e15ad9

Browse files
peffgitster
authored andcommitted
add tests for cloning corrupted repositories
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9c31e1 commit 0e15ad9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

t/t1060-object-corruption.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ test_expect_success 'setup repo with missing object' '
3333
)
3434
'
3535

36+
test_expect_success 'setup repo with misnamed object' '
37+
git init misnamed &&
38+
(
39+
cd misnamed &&
40+
test_commit content &&
41+
good=$(obj_to_file HEAD:content.t) &&
42+
blob=$(echo corrupt | git hash-object -w --stdin) &&
43+
bad=$(obj_to_file $blob) &&
44+
rm -f "$good" &&
45+
mv "$bad" "$good"
46+
)
47+
'
48+
3649
test_expect_success 'streaming a corrupt blob fails' '
3750
(
3851
cd bit-error &&
@@ -56,4 +69,32 @@ test_expect_success 'read-tree -u detects missing objects' '
5669
)
5770
'
5871

72+
# We use --bare to make sure that the transport detects it, not the checkout
73+
# phase.
74+
test_expect_success 'clone --no-local --bare detects corruption' '
75+
test_must_fail git clone --no-local --bare bit-error corrupt-transport
76+
'
77+
78+
test_expect_success 'clone --no-local --bare detects missing object' '
79+
test_must_fail git clone --no-local --bare missing missing-transport
80+
'
81+
82+
test_expect_failure 'clone --no-local --bare detects misnamed object' '
83+
test_must_fail git clone --no-local --bare misnamed misnamed-transport
84+
'
85+
86+
# We do not expect --local to detect corruption at the transport layer,
87+
# so we are really checking the checkout() code path.
88+
test_expect_success 'clone --local detects corruption' '
89+
test_must_fail git clone --local bit-error corrupt-checkout
90+
'
91+
92+
test_expect_failure 'clone --local detects missing objects' '
93+
test_must_fail git clone --local missing missing-checkout
94+
'
95+
96+
test_expect_failure 'clone --local detects misnamed objects' '
97+
test_must_fail git clone --local misnamed misnamed-checkout
98+
'
99+
59100
test_done

0 commit comments

Comments
 (0)