#!/bin/sh global test_description := ''errors in upload-pack'' source ./test-lib.sh global D := $[pwd] proc corrupt_repo { global object_sha1 := $[git rev-parse $1] && global ob := $[expr $object_sha1 : "\(..] && global ject := $[expr $object_sha1 : "..\(..*] && rm -f ".git/objects/$ob/$ject" } test_expect_success 'setup and corrupt repository' ' echo file >file && git add file && git rev-parse :file && git commit -a -m original && test_tick && echo changed >file && git commit -a -m changed && corrupt_repo HEAD:file ' test_expect_success 'fsck fails' ' test_must_fail git fsck ' test_expect_success 'upload-pack fails due to error in pack-objects packing' ' printf "0032want %s\n00000009done\n0000" \ $(git rev-parse HEAD) >input && test_must_fail git upload-pack . /dev/null 2>output.err && test_i18ngrep "unable to read" output.err && test_i18ngrep "pack-objects died" output.err ' test_expect_success 'corrupt repo differently' ' git hash-object -w file && corrupt_repo HEAD^^{tree} ' test_expect_success 'fsck fails' ' test_must_fail git fsck ' test_expect_success 'upload-pack fails due to error in rev-list' ' printf "0032want %s\n0034shallow %s00000009done\n0000" \ $(git rev-parse HEAD) $(git rev-parse HEAD^) >input && test_must_fail git upload-pack . /dev/null 2>output.err && grep "bad tree object" output.err ' test_expect_success 'upload-pack error message when bad ref requested' ' printf "0045want %s multi_ack_detailed\n00000009done\n0000" \ "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" >input && test_must_fail git upload-pack . output 2>output.err && grep -q "not our ref" output.err && ! grep -q multi_ack_detailed output.err ' test_expect_success 'upload-pack fails due to error in pack-objects enumeration' ' printf "0032want %s\n00000009done\n0000" \ $(git rev-parse HEAD) >input && test_must_fail git upload-pack . /dev/null 2>output.err && grep "bad tree object" output.err && grep "pack-objects died" output.err ' test_expect_success 'create empty repository' ' mkdir foo && cd foo && git init ' test_expect_success 'fetch fails' ' test_must_fail git fetch .. master ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"errors in upload-pack">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:D) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [16 18] ) } spids: [15] ) ] spids: [15] ) (FuncDef name: corrupt_repo body: (BraceGroup children: [ (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:object_sha1) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(git)} {(rev-parse)} {(DQ ($ VSub_Number "$1"))})] ) left_token: spids: [30 38] ) } spids: [29] ) ] spids: [29] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ob) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(expr)} {(DQ ($ VSub_Name "$object_sha1"))} {(Lit_Other ":")} { (DQ (EscapedLiteralPart token:) (..) (EscapedLiteralPart token: ) ) } ) ] ) left_token: spids: [44 58] ) } spids: [43] ) ] spids: [43] ) (AndOr children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ject) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (C {(expr)} {(DQ ($ VSub_Name "$object_sha1"))} {(Lit_Other ":")} { (DQ (..) (EscapedLiteralPart token: ) ("..*") (EscapedLiteralPart token:) ) } ) ] ) left_token: spids: [64 79] ) } spids: [63] ) ] spids: [63] ) (C {(rm)} {(-f)} {(DQ (.git/objects/) ($ VSub_Name "$ob") (/) ($ VSub_Name "$ject"))} ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] spids: [26] ) spids: [21 25] ) (C {(test_expect_success)} {(SQ <"setup and corrupt repository">)} { (SQ <"\n"> <"\n"> <"\techo file >file &&\n"> <"\tgit add file &&\n"> <"\tgit rev-parse :file &&\n"> <"\tgit commit -a -m original &&\n"> <"\ttest_tick &&\n"> <"\techo changed >file &&\n"> <"\tgit commit -a -m changed &&\n"> <"\tcorrupt_repo HEAD:file\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"fsck fails">)} {(SQ <"\n"> <"\ttest_must_fail git fsck\n">)}) (C {(test_expect_success)} {(SQ <"upload-pack fails due to error in pack-objects packing">)} { (SQ <"\n"> <"\n"> <"\tprintf \"0032want %s\\n00000009done\\n0000\" \\\n"> <"\t\t$(git rev-parse HEAD) >input &&\n"> <"\ttest_must_fail git upload-pack . /dev/null 2>output.err &&\n"> <"\ttest_i18ngrep \"unable to read\" output.err &&\n"> <"\ttest_i18ngrep \"pack-objects died\" output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"corrupt repo differently">)} { (SQ <"\n"> <"\n"> <"\tgit hash-object -w file &&\n"> <"\tcorrupt_repo HEAD^^{tree}\n"> <"\n">) } ) (C {(test_expect_success)} {(SQ <"fsck fails">)} {(SQ <"\n"> <"\ttest_must_fail git fsck\n">)}) (C {(test_expect_success)} {(SQ <"upload-pack fails due to error in rev-list">)} { (SQ <"\n"> <"\n"> <"\tprintf \"0032want %s\\n0034shallow %s00000009done\\n0000\" \\\n"> <"\t\t$(git rev-parse HEAD) $(git rev-parse HEAD^) >input &&\n"> <"\ttest_must_fail git upload-pack . /dev/null 2>output.err &&\n"> <"\tgrep \"bad tree object\" output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"upload-pack error message when bad ref requested">)} { (SQ <"\n"> <"\n"> <"\tprintf \"0045want %s multi_ack_detailed\\n00000009done\\n0000\" \\\n"> <"\t\t\"deadbeefdeadbeefdeadbeefdeadbeefdeadbeef\" >input &&\n"> <"\ttest_must_fail git upload-pack . output 2>output.err &&\n"> <"\tgrep -q \"not our ref\" output.err &&\n"> <"\t! grep -q multi_ack_detailed output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"upload-pack fails due to error in pack-objects enumeration">)} { (SQ <"\n"> <"\n"> <"\tprintf \"0032want %s\\n00000009done\\n0000\" \\\n"> <"\t\t$(git rev-parse HEAD) >input &&\n"> <"\ttest_must_fail git upload-pack . /dev/null 2>output.err &&\n"> <"\tgrep \"bad tree object\" output.err &&\n"> <"\tgrep \"pack-objects died\" output.err\n"> ) } ) (C {(test_expect_success)} {(SQ <"create empty repository">)} {(SQ <"\n"> <"\n"> <"\tmkdir foo &&\n"> <"\tcd foo &&\n"> <"\tgit init\n"> <"\n">)} ) (C {(test_expect_success)} {(SQ <"fetch fails">)} {(SQ <"\n"> <"\n"> <"\ttest_must_fail git fetch .. master\n"> <"\n">)} ) (C {(test_done)}) ] )