| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='errors in upload-pack' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | corrupt_repo () { |
| 8 | object_sha1=$(git rev-parse "$1") && |
| 9 | ob=$(expr "$object_sha1" : "\(..\)") && |
| 10 | ject=$(expr "$object_sha1" : "..\(..*\)") && |
| 11 | rm -f ".git/objects/$ob/$ject" |
| 12 | } |
| 13 | |
| 14 | test_expect_success 'setup and corrupt repository' ' |
| 15 | echo file >file && |
| 16 | git add file && |
| 17 | git rev-parse :file && |
| 18 | git commit -a -m original && |
| 19 | test_tick && |
| 20 | echo changed >file && |
| 21 | git commit -a -m changed && |
| 22 | corrupt_repo HEAD:file && |
| 23 | test_must_fail git fsck |
| 24 | ' |
| 25 | |
| 26 | test_expect_success 'upload-pack fails due to error in pack-objects packing' ' |
| 27 | head=$(git rev-parse HEAD) && |
| 28 | hexsz=$(test_oid hexsz) && |
| 29 | printf "%04xwant %s\n00000009done\n0000" \ |
| 30 | $(($hexsz + 10)) $head >input && |
| 31 | test_must_fail git upload-pack . <input >/dev/null 2>output.err && |
| 32 | test_grep "unable to read" output.err && |
| 33 | test_grep "pack-objects died" output.err |
| 34 | ' |
| 35 | |
| 36 | test_expect_success 'corrupt repo differently' ' |
| 37 | git hash-object -w file && |
| 38 | corrupt_repo HEAD^^{tree} && |
| 39 | test_must_fail git fsck |
| 40 | ' |
| 41 | |
| 42 | test_expect_success 'upload-pack fails due to error in rev-list' ' |
| 43 | printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \ |
| 44 | $(($hexsz + 10)) $(git rev-parse HEAD) \ |
| 45 | $(($hexsz + 12)) $(git rev-parse HEAD^) >input && |
| 46 | test_must_fail git upload-pack . <input >/dev/null 2>output.err && |
| 47 | grep "bad tree object" output.err |
| 48 | ' |
| 49 | |
| 50 | test_expect_success 'upload-pack fails due to bad want (no object)' ' |
| 51 | printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \ |
| 52 | $(($hexsz + 29)) $(test_oid deadbeef) >input && |
| 53 | test_must_fail git upload-pack . <input >output 2>output.err && |
| 54 | grep "not our ref" output.err && |
| 55 | grep "ERR" output && |
| 56 | ! grep multi_ack_detailed output.err |
| 57 | ' |
| 58 | |
| 59 | test_expect_success 'upload-pack fails due to bad want (not tip)' ' |
| 60 | oid=$(echo an object we have | git hash-object -w --stdin) && |
| 61 | printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \ |
| 62 | $(($hexsz + 29)) "$oid" >input && |
| 63 | test_must_fail git upload-pack . <input >output 2>output.err && |
| 64 | grep "not our ref" output.err && |
| 65 | grep "ERR" output && |
| 66 | ! grep multi_ack_detailed output.err |
| 67 | ' |
| 68 | |
| 69 | test_expect_success 'upload-pack fails due to error in pack-objects enumeration' ' |
| 70 | printf "%04xwant %s\n00000009done\n0000" \ |
| 71 | $((hexsz + 10)) $(git rev-parse HEAD) >input && |
| 72 | test_must_fail git upload-pack . <input >/dev/null 2>output.err && |
| 73 | grep "bad tree object" output.err && |
| 74 | grep "pack-objects died" output.err |
| 75 | ' |
| 76 | |
| 77 | test_expect_success 'upload-pack tolerates EOF just after stateless client wants' ' |
| 78 | test_commit initial && |
| 79 | head=$(git rev-parse HEAD) && |
| 80 | |
| 81 | { |
| 82 | packetize "want $head" && |
| 83 | packetize "shallow $head" && |
| 84 | packetize "deepen 1" && |
| 85 | printf "0000" |
| 86 | } >request && |
| 87 | |
| 88 | printf "0000" >expect && |
| 89 | |
| 90 | git upload-pack --stateless-rpc . <request >actual && |
| 91 | test_cmp expect actual |
| 92 | ' |
| 93 | |
| 94 | test_expect_success 'fetch fails' ' |
| 95 | git init foo && |
| 96 | test_must_fail git -C foo fetch .. main |
| 97 | ' |
| 98 | |
| 99 | test_expect_success 'upload-pack ACKs repeated non-commit objects repeatedly (protocol v0)' ' |
| 100 | commit_id=$(git rev-parse HEAD) && |
| 101 | tree_id=$(git rev-parse HEAD^{tree}) && |
| 102 | test-tool pkt-line pack >request <<-EOF && |
| 103 | want $commit_id |
| 104 | 0000 |
| 105 | have $tree_id |
| 106 | have $tree_id |
| 107 | 0000 |
| 108 | EOF |
| 109 | git upload-pack --stateless-rpc . <request >actual && |
| 110 | depacketize <actual >actual.raw && |
| 111 | grep ^ACK actual.raw >actual.acks && |
| 112 | cat >expect <<-EOF && |
| 113 | ACK $tree_id |
| 114 | ACK $tree_id |
| 115 | EOF |
| 116 | test_cmp expect actual.acks |
| 117 | ' |
| 118 | |
| 119 | test_expect_success 'upload-pack ACKs repeated non-commit objects once only (protocol v2)' ' |
| 120 | commit_id=$(git rev-parse HEAD) && |
| 121 | tree_id=$(git rev-parse HEAD^{tree}) && |
| 122 | test-tool pkt-line pack >request <<-EOF && |
| 123 | command=fetch |
| 124 | object-format=$(test_oid algo) |
| 125 | 0001 |
| 126 | want $commit_id |
| 127 | have $tree_id |
| 128 | have $tree_id |
| 129 | 0000 |
| 130 | EOF |
| 131 | GIT_PROTOCOL=version=2 git upload-pack . <request >actual && |
| 132 | depacketize <actual >actual.raw && |
| 133 | grep ^ACK actual.raw >actual.acks && |
| 134 | echo "ACK $tree_id" >expect && |
| 135 | test_cmp expect actual.acks |
| 136 | ' |
| 137 | |
| 138 | test_done |