Git fork
1#!/bin/sh
2
3test_description='check receive input limits'
4
5. ./test-lib.sh
6
7# Let's run tests with different unpack limits: 1 and 10000
8# When the limit is 1, `git receive-pack` will call `git index-pack`.
9# When the limit is 10000, `git receive-pack` will call `git unpack-objects`.
10
11validate_store_type () {
12 git -C dest count-objects -v >actual &&
13 case "$store_type" in
14 index)
15 grep "^count: 0$" actual ;;
16 unpack)
17 grep "^packs: 0$" actual ;;
18 esac || {
19 echo "store_type is $store_type"
20 cat actual
21 false;
22 }
23}
24
25test_pack_input_limit () {
26 store_type=$1
27
28 case "$store_type" in
29 index) unpack_limit=1 other_limit=10000 ;;
30 unpack) unpack_limit=10000 other_limit=1 ;;
31 esac
32
33 test_expect_success 'prepare destination repository' '
34 rm -fr dest &&
35 git --bare init dest
36 '
37
38 test_expect_success "set unpacklimit to $unpack_limit" '
39 git --git-dir=dest config receive.unpacklimit "$unpack_limit"
40 '
41
42 test_expect_success 'setting receive.maxInputSize to 512 rejects push' '
43 git --git-dir=dest config receive.maxInputSize 512 &&
44 test_must_fail git push dest HEAD
45 '
46
47 test_expect_success 'bumping limit to 4k allows push' '
48 git --git-dir=dest config receive.maxInputSize 4k &&
49 git push dest HEAD
50 '
51
52 test_expect_success 'prepare destination repository (again)' '
53 rm -fr dest &&
54 git --bare init dest
55 '
56
57 test_expect_success 'lifting the limit allows push' '
58 git --git-dir=dest config receive.maxInputSize 0 &&
59 git push dest HEAD
60 '
61
62 test_expect_success 'prepare destination repository (once more)' '
63 rm -fr dest &&
64 git --bare init dest
65 '
66
67 test_expect_success 'receive trumps transfer' '
68 git --git-dir=dest config receive.unpacklimit "$unpack_limit" &&
69 git --git-dir=dest config transfer.unpacklimit "$other_limit" &&
70 git push dest HEAD &&
71 validate_store_type
72 '
73
74}
75
76test_expect_success "create known-size (1024 bytes) commit" '
77 test-tool genrandom foo 1024 >one-k &&
78 git add one-k &&
79 test_commit one-k
80'
81
82test_pack_input_limit index
83test_pack_input_limit unpack
84
85test_done