| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='check that diff --max-depth will limit recursion' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | make_dir() { |
| 7 | mkdir -p "$1" && |
| 8 | echo "$2" >"$1/file" |
| 9 | } |
| 10 | |
| 11 | make_files() { |
| 12 | echo "$1" >file && |
| 13 | make_dir one "$1" && |
| 14 | make_dir one/two "$1" && |
| 15 | make_dir one/two/three "$1" |
| 16 | } |
| 17 | |
| 18 | test_expect_success 'setup' ' |
| 19 | git commit --allow-empty -m empty && |
| 20 | git tag empty && |
| 21 | make_files added && |
| 22 | git add . && |
| 23 | git commit -m added && |
| 24 | make_files modified && |
| 25 | git add . && |
| 26 | git commit -m modified && |
| 27 | make_files index && |
| 28 | git add . && |
| 29 | make_files worktree |
| 30 | ' |
| 31 | |
| 32 | test_expect_success '--max-depth is disallowed with wildcard pathspecs' ' |
| 33 | test_must_fail git diff-tree --max-depth=0 HEAD^ HEAD -- "f*" |
| 34 | ' |
| 35 | |
| 36 | check_one() { |
| 37 | type=$1; shift |
| 38 | args=$1; shift |
| 39 | path=$1; shift |
| 40 | depth=$1; shift |
| 41 | test_expect_${expect:-success} "diff-$type $args, path=$path, depth=$depth" " |
| 42 | for i in $*; do echo \$i; done >expect && |
| 43 | git diff-$type --max-depth=$depth --name-only $args -- $path >actual && |
| 44 | test_cmp expect actual |
| 45 | " |
| 46 | } |
| 47 | |
| 48 | # For tree comparisons, we expect to see subtrees at the boundary |
| 49 | # get their own entry. |
| 50 | check_trees() { |
| 51 | check_one tree "$*" '' 0 file one |
| 52 | check_one tree "$*" '' 1 file one/file one/two |
| 53 | check_one tree "$*" '' 2 file one/file one/two/file one/two/three |
| 54 | check_one tree "$*" '' 3 file one/file one/two/file one/two/three/file |
| 55 | check_one tree "$*" '' -1 file one/file one/two/file one/two/three/file |
| 56 | check_one tree "$*" one 0 one |
| 57 | check_one tree "$*" one 1 one/file one/two |
| 58 | check_one tree "$*" one 2 one/file one/two/file one/two/three |
| 59 | check_one tree "$*" one 3 one/file one/two/file one/two/three/file |
| 60 | check_one tree "$*" one/two 0 one/two |
| 61 | check_one tree "$*" one/two 1 one/two/file one/two/three |
| 62 | check_one tree "$*" one/two 2 one/two/file one/two/three/file |
| 63 | check_one tree "$*" one/two 2 one/two/file one/two/three/file |
| 64 | check_one tree "$*" one/two/three 0 one/two/three |
| 65 | check_one tree "$*" one/two/three 1 one/two/three/file |
| 66 | } |
| 67 | |
| 68 | # But for index comparisons, we do not store subtrees at all, so we do not |
| 69 | # expect them. |
| 70 | check_index() { |
| 71 | check_one "$@" '' 0 file |
| 72 | check_one "$@" '' 1 file one/file |
| 73 | check_one "$@" '' 2 file one/file one/two/file |
| 74 | check_one "$@" '' 3 file one/file one/two/file one/two/three/file |
| 75 | check_one "$@" one 0 |
| 76 | check_one "$@" one 1 one/file |
| 77 | check_one "$@" one 2 one/file one/two/file |
| 78 | check_one "$@" one 3 one/file one/two/file one/two/three/file |
| 79 | check_one "$@" one/two 0 |
| 80 | check_one "$@" one/two 1 one/two/file |
| 81 | check_one "$@" one/two 2 one/two/file one/two/three/file |
| 82 | check_one "$@" one/two/three 0 |
| 83 | check_one "$@" one/two/three 1 one/two/three/file |
| 84 | |
| 85 | # Value '-1' for '--max-depth is the same as recursion without limit, |
| 86 | # and thus should always succeed. |
| 87 | local expect= |
| 88 | check_one "$@" '' -1 file one/file one/two/file one/two/three/file |
| 89 | } |
| 90 | |
| 91 | # Check as a modification... |
| 92 | check_trees HEAD^ HEAD |
| 93 | # ...and as an addition... |
| 94 | check_trees empty HEAD |
| 95 | # ...and as a deletion. |
| 96 | check_trees HEAD empty |
| 97 | |
| 98 | # We currently only implement max-depth for trees. |
| 99 | expect=failure |
| 100 | # Check index against a tree |
| 101 | check_index index "--cached HEAD" |
| 102 | # and index against the worktree |
| 103 | check_index files "" |
| 104 | expect= |
| 105 | |
| 106 | test_expect_success 'find shortest path within embedded pathspecs' ' |
| 107 | cat >expect <<-\EOF && |
| 108 | one/file |
| 109 | one/two/file |
| 110 | one/two/three/file |
| 111 | EOF |
| 112 | git diff-tree --max-depth=2 --name-only HEAD^ HEAD -- one one/two >actual && |
| 113 | test_cmp expect actual |
| 114 | ' |
| 115 | |
| 116 | test_done |