blob: 205a2631e7f807a72259b27eb689a0b18439d7f9 [file] [log] [blame]
Johannes Sixt4c324c02007-11-04 20:46:48 +01001#!/bin/sh
2
3test_description='errors in upload-pack'
4
5. ./test-lib.sh
6
Elia Pinto14dc2d92016-01-04 10:10:43 +01007D=$(pwd)
Johannes Sixt4c324c02007-11-04 20:46:48 +01008
9corrupt_repo () {
10 object_sha1=$(git rev-parse "$1") &&
11 ob=$(expr "$object_sha1" : "\(..\)") &&
12 ject=$(expr "$object_sha1" : "..\(..*\)") &&
13 rm -f ".git/objects/$ob/$ject"
14}
15
16test_expect_success 'setup and corrupt repository' '
Johannes Sixt4c324c02007-11-04 20:46:48 +010017 echo file >file &&
18 git add file &&
19 git rev-parse :file &&
20 git commit -a -m original &&
21 test_tick &&
22 echo changed >file &&
23 git commit -a -m changed &&
24 corrupt_repo HEAD:file
25
26'
27
Junio C Hamano41ac4142008-02-01 01:50:53 -080028test_expect_success 'fsck fails' '
Stephan Beyerd492b312008-07-12 17:47:52 +020029 test_must_fail git fsck
Johannes Sixt4c324c02007-11-04 20:46:48 +010030'
31
Nick Edelenf0cea832009-06-10 01:50:18 +020032test_expect_success 'upload-pack fails due to error in pack-objects packing' '
brian m. carlson83207222019-12-21 19:49:31 +000033 head=$(git rev-parse HEAD) &&
34 hexsz=$(test_oid hexsz) &&
35 printf "%04xwant %s\n00000009done\n0000" \
36 $(($hexsz + 10)) $head >input &&
Johannes Sixt1d8cd412010-03-06 16:40:38 +010037 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
Jiang Xin9aa98ef2012-08-27 13:36:53 +080038 test_i18ngrep "unable to read" output.err &&
39 test_i18ngrep "pack-objects died" output.err
Johannes Sixt4c324c02007-11-04 20:46:48 +010040'
41
42test_expect_success 'corrupt repo differently' '
43
44 git hash-object -w file &&
45 corrupt_repo HEAD^^{tree}
46
47'
48
Junio C Hamano41ac4142008-02-01 01:50:53 -080049test_expect_success 'fsck fails' '
Stephan Beyerd492b312008-07-12 17:47:52 +020050 test_must_fail git fsck
Johannes Sixt4c324c02007-11-04 20:46:48 +010051'
52test_expect_success 'upload-pack fails due to error in rev-list' '
53
brian m. carlson83207222019-12-21 19:49:31 +000054 printf "%04xwant %s\n%04xshallow %s00000009done\n0000" \
55 $(($hexsz + 10)) $(git rev-parse HEAD) \
56 $(($hexsz + 12)) $(git rev-parse HEAD^) >input &&
Johannes Sixt1d8cd412010-03-06 16:40:38 +010057 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
Johannes Sixt0ac77ec2009-07-04 21:26:40 +020058 grep "bad tree object" output.err
Johannes Sixt4c324c02007-11-04 20:46:48 +010059'
60
Jeff King014ade72019-04-13 01:53:34 -040061test_expect_success 'upload-pack fails due to bad want (no object)' '
Elijah Newren9f9aa762010-07-31 14:11:46 -060062
brian m. carlson83207222019-12-21 19:49:31 +000063 printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
64 $(($hexsz + 29)) $(test_oid deadbeef) >input &&
Elijah Newren9f9aa762010-07-31 14:11:46 -060065 test_must_fail git upload-pack . <input >output 2>output.err &&
Jeff King6963a4e2019-04-13 01:53:09 -040066 grep "not our ref" output.err &&
67 grep "ERR" output &&
68 ! grep multi_ack_detailed output.err
Elijah Newren9f9aa762010-07-31 14:11:46 -060069'
70
Jeff King014ade72019-04-13 01:53:34 -040071test_expect_success 'upload-pack fails due to bad want (not tip)' '
72
73 oid=$(echo an object we have | git hash-object -w --stdin) &&
brian m. carlson83207222019-12-21 19:49:31 +000074 printf "%04xwant %s multi_ack_detailed\n00000009done\n0000" \
75 $(($hexsz + 29)) "$oid" >input &&
Jeff King014ade72019-04-13 01:53:34 -040076 test_must_fail git upload-pack . <input >output 2>output.err &&
77 grep "not our ref" output.err &&
78 grep "ERR" output &&
79 ! grep multi_ack_detailed output.err
80'
81
Nick Edelenf0cea832009-06-10 01:50:18 +020082test_expect_success 'upload-pack fails due to error in pack-objects enumeration' '
83
brian m. carlson83207222019-12-21 19:49:31 +000084 printf "%04xwant %s\n00000009done\n0000" \
85 $((hexsz + 10)) $(git rev-parse HEAD) >input &&
Johannes Sixt1d8cd412010-03-06 16:40:38 +010086 test_must_fail git upload-pack . <input >/dev/null 2>output.err &&
Nick Edelenf0cea832009-06-10 01:50:18 +020087 grep "bad tree object" output.err &&
88 grep "pack-objects died" output.err
89'
90
Johannes Sixt4c324c02007-11-04 20:46:48 +010091test_expect_success 'create empty repository' '
92
93 mkdir foo &&
94 cd foo &&
95 git init
96
97'
98
Junio C Hamano41ac4142008-02-01 01:50:53 -080099test_expect_success 'fetch fails' '
Johannes Sixt4c324c02007-11-04 20:46:48 +0100100
Stephan Beyerd492b312008-07-12 17:47:52 +0200101 test_must_fail git fetch .. master
Johannes Sixt4c324c02007-11-04 20:46:48 +0100102
103'
104
105test_done