Commit | Line | Data |
---|---|---|
7b6257b0 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='see how we handle various forms of corruption' | |
4 | . ./test-lib.sh | |
5 | ||
6 | # convert "1234abcd" to ".git/objects/12/34abcd" | |
7 | obj_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' | |
12 | corrupt_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 | ||
18 | test_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 | ||
d9c31e14 JK |
27 | test_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 | ||
0e15ad9b JK |
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 | ||
7b6257b0 JK |
49 | test_expect_success 'streaming a corrupt blob fails' ' |
50 | ( | |
51 | cd bit-error && | |
52 | test_must_fail git cat-file blob HEAD:content.t | |
53 | ) | |
54 | ' | |
55 | ||
d9c31e14 JK |
56 | test_expect_success 'read-tree -u detects bit-errors in blobs' ' |
57 | ( | |
58 | cd bit-error && | |
59 | rm -f content.t && | |
60 | test_must_fail git read-tree --reset -u HEAD | |
61 | ) | |
62 | ' | |
63 | ||
64 | test_expect_success 'read-tree -u detects missing objects' ' | |
65 | ( | |
66 | cd missing && | |
67 | rm -f content.t && | |
68 | test_must_fail git read-tree --reset -u HEAD | |
69 | ) | |
70 | ' | |
71 | ||
0e15ad9b JK |
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 | ||
0433ad12 | 82 | test_expect_success 'clone --no-local --bare detects misnamed object' ' |
0e15ad9b JK |
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 | ||
d3b34622 JK |
92 | test_expect_success 'error detected during checkout leaves repo intact' ' |
93 | test_path_is_dir corrupt-checkout/.git | |
94 | ' | |
95 | ||
0aac7bb2 | 96 | test_expect_success 'clone --local detects missing objects' ' |
0e15ad9b JK |
97 | test_must_fail git clone --local missing missing-checkout |
98 | ' | |
99 | ||
100 | test_expect_failure 'clone --local detects misnamed objects' ' | |
101 | test_must_fail git clone --local misnamed misnamed-checkout | |
102 | ' | |
103 | ||
7b6257b0 | 104 | test_done |