Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t6700-tree-depth.sh
blob9e70a7c763a210c6b1d855e2cc5dbb2ca403394a
1 #!/bin/sh
3 test_description='handling of deep trees in various commands'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
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.
12 small_depth=50
13 big_depth=4100
15 small_ok="-c core.maxtreedepth=$small_depth"
16 small_no="-c core.maxtreedepth=$((small_depth-1))"
18 # usage: mkdeep <name> <depth>
19 # Create a tag <name> containing a file whose path has depth <depth>.
21 # We'll use fast-import here for two reasons:
23 # 1. It's faster than creating $big_depth tree objects.
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.
27 mkdeep () {
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" &&
35 printf 'M 100644 inline ' &&
36 i=0 &&
37 while test $i -lt $2
39 printf 'a/'
40 i=$((i+1))
41 done &&
42 echo "file" &&
44 echo "data <<EOF" &&
45 echo "the file contents" &&
46 echo "EOF" &&
47 echo
48 } | git fast-import
51 test_expect_success 'create small tree' '
52 mkdeep small $small_depth
55 test_expect_success 'create big tree' '
56 mkdeep big $big_depth
59 test_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
64 test_expect_success 'default limit for git-archive fails gracefully' '
65 test_must_fail git archive big >/dev/null
68 test_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
73 test_expect_success 'default limit for ls-tree fails gracefully' '
74 test_must_fail git ls-tree -r big >/dev/null
77 test_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
82 test_expect_success 'default limit for rev-list fails gracefully' '
83 test_must_fail git rev-list --objects big >/dev/null
86 test_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
91 test_expect_success 'default limit for diff-tree fails gracefully' '
92 test_must_fail git diff-tree -r $EMPTY_TREE big
95 test_done