]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6700-tree-depth.sh
The twentieth batch
[thirdparty/git.git] / t / t6700-tree-depth.sh
CommitLineData
f1f63a48
JK
1#!/bin/sh
2
3test_description='handling of deep trees in various commands'
be4b578c
JK
4
5TEST_PASSES_SANITIZE_LEAK=true
f1f63a48
JK
6. ./test-lib.sh
7
8# We'll test against two depths here: a small one that will let us check the
9# behavior of the config setting easily, and a large one that should be
10# forbidden by default. Testing the default depth will let us know whether our
11# default is enough to prevent segfaults on systems that run the tests.
12small_depth=50
13big_depth=4100
14
15small_ok="-c core.maxtreedepth=$small_depth"
16small_no="-c core.maxtreedepth=$((small_depth-1))"
17
18# usage: mkdeep <name> <depth>
19# Create a tag <name> containing a file whose path has depth <depth>.
20#
21# We'll use fast-import here for two reasons:
22#
23# 1. It's faster than creating $big_depth tree objects.
24#
25# 2. As we tighten tree limits, it's more likely to allow large sizes
26# than trying to stuff a deep path into the index.
27mkdeep () {
28 {
29 echo "commit refs/tags/$1" &&
30 echo "committer foo <foo@example.com> 1234 -0000" &&
31 echo "data <<EOF" &&
32 echo "the commit message" &&
33 echo "EOF" &&
34
35 printf 'M 100644 inline ' &&
36 i=0 &&
37 while test $i -lt $2
38 do
39 printf 'a/'
40 i=$((i+1))
41 done &&
42 echo "file" &&
43
44 echo "data <<EOF" &&
45 echo "the file contents" &&
46 echo "EOF" &&
47 echo
48 } | git fast-import
49}
50
51test_expect_success 'create small tree' '
52 mkdeep small $small_depth
53'
54
55test_expect_success 'create big tree' '
56 mkdeep big $big_depth
57'
58
59test_expect_success 'limit recursion of git-archive' '
60 git $small_ok archive small >/dev/null &&
61 test_must_fail git $small_no archive small >/dev/null
62'
63
64test_expect_success 'default limit for git-archive fails gracefully' '
65 test_must_fail git archive big >/dev/null
66'
67
1ee7a5c3
JK
68test_expect_success 'limit recursion of ls-tree -r' '
69 git $small_ok ls-tree -r small &&
70 test_must_fail git $small_no ls-tree -r small
71'
72
73test_expect_success 'default limit for ls-tree fails gracefully' '
74 test_must_fail git ls-tree -r big >/dev/null
75'
76
670a1dad
JK
77test_expect_success 'limit recursion of rev-list --objects' '
78 git $small_ok rev-list --objects small >/dev/null &&
79 test_must_fail git $small_no rev-list --objects small >/dev/null
80'
81
82test_expect_success 'default limit for rev-list fails gracefully' '
83 test_must_fail git rev-list --objects big >/dev/null
84'
85
7b61bd18
JK
86test_expect_success 'limit recursion of diff-tree -r' '
87 git $small_ok diff-tree -r $EMPTY_TREE small &&
88 test_must_fail git $small_no diff-tree -r $EMPTY_TREE small
89'
90
91test_expect_success 'default limit for diff-tree fails gracefully' '
92 test_must_fail git diff-tree -r $EMPTY_TREE big
93'
94
f1f63a48 95test_done