3 test_description
='see how we handle various forms of corruption'
6 # convert "1234abcd" to ".git/objects/12/34abcd"
8 echo "$(git rev-parse --git-dir)/objects/$(git rev-parse "$1" | sed 's,..,&/,')"
11 # Convert byte at offset "$2" of object "$1" into '\0'
13 obj_file
=$
(obj_to_file
"$1") &&
14 chmod +w
"$obj_file" &&
15 printf '\0' |
dd of
="$obj_file" bs
=1 seek
="$2" conv
=notrunc
18 test_expect_success
'setup corrupt repo' '
22 test_commit content &&
23 corrupt_byte HEAD:content.t 10
27 test_expect_success
'setup repo with missing object' '
31 test_commit content &&
32 rm -f "$(obj_to_file HEAD:content.t)"
36 test_expect_success
'setup repo with misnamed object' '
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) &&
49 test_expect_success
'streaming a corrupt blob fails' '
52 test_must_fail git cat-file blob HEAD:content.t
56 test_expect_success
'getting type of a corrupt blob fails' '
59 test_must_fail git cat-file -s HEAD:content.t
63 test_expect_success
'read-tree -u detects bit-errors in blobs' '
67 test_must_fail git read-tree --reset -u HEAD
71 test_expect_success
'read-tree -u detects missing objects' '
75 test_must_fail git read-tree --reset -u HEAD
79 # We use --bare to make sure that the transport detects it, not the checkout
81 test_expect_success
'clone --no-local --bare detects corruption' '
82 test_must_fail git clone --no-local --bare bit-error corrupt-transport
85 test_expect_success
'clone --no-local --bare detects missing object' '
86 test_must_fail git clone --no-local --bare missing missing-transport
89 test_expect_success
'clone --no-local --bare detects misnamed object' '
90 test_must_fail git clone --no-local --bare misnamed misnamed-transport
93 # We do not expect --local to detect corruption at the transport layer,
94 # so we are really checking the checkout() code path.
95 test_expect_success
'clone --local detects corruption' '
96 test_must_fail git clone --local bit-error corrupt-checkout
99 test_expect_success
'error detected during checkout leaves repo intact' '
100 test_path_is_dir corrupt-checkout/.git
103 test_expect_success
'clone --local detects missing objects' '
104 test_must_fail git clone --local missing missing-checkout
107 test_expect_failure
'clone --local detects misnamed objects' '
108 test_must_fail git clone --local misnamed misnamed-checkout