cfd1f23a119fa3ac30304506f54ab50f8073b71f
1#!/bin/sh
2
3test_description='see how we handle various forms of corruption'
4. ./test-lib.sh
5
6# convert "1234abcd" to ".git/objects/12/34abcd"
7obj_to_file() {
8 echo "$(git rev-parse --git-dir)/objects/$(git rev-parse "$1" | sed 's,..,&/,')"
9}
10
11# Convert byte at offset "$2" of object "$1" into '\0'
12corrupt_byte() {
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
16}
17
18test_expect_success 'setup corrupt repo' '
19 git init bit-error &&
20 (
21 cd bit-error &&
22 test_commit content &&
23 corrupt_byte HEAD:content.t 10
24 )
25'
26
27test_expect_success 'setup repo with missing object' '
28 git init missing &&
29 (
30 cd missing &&
31 test_commit content &&
32 rm -f "$(obj_to_file HEAD:content.t)"
33 )
34'
35
36test_expect_success 'streaming a corrupt blob fails' '
37 (
38 cd bit-error &&
39 test_must_fail git cat-file blob HEAD:content.t
40 )
41'
42
43test_expect_success 'read-tree -u detects bit-errors in blobs' '
44 (
45 cd bit-error &&
46 rm -f content.t &&
47 test_must_fail git read-tree --reset -u HEAD
48 )
49'
50
51test_expect_success 'read-tree -u detects missing objects' '
52 (
53 cd missing &&
54 rm -f content.t &&
55 test_must_fail git read-tree --reset -u HEAD
56 )
57'
58
59test_done