| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='git ls-tree test. |
| 7 | |
| 8 | This test runs git ls-tree with the following in a tree. |
| 9 | |
| 10 | path0 - a file |
| 11 | path1 - a symlink |
| 12 | path2/foo - a file in a directory |
| 13 | path2/bazbo - a symlink in a directory |
| 14 | path2/baz/b - a file in a directory in a directory |
| 15 | |
| 16 | The new path restriction code should do the right thing for path2 and |
| 17 | path2/baz. Also path0/ should snow nothing. |
| 18 | ' |
| 19 | |
| 20 | . ./test-lib.sh |
| 21 | |
| 22 | test_expect_success \ |
| 23 | 'setup' \ |
| 24 | 'mkdir path2 path2/baz && |
| 25 | echo Hi >path0 && |
| 26 | test_ln_s_add path0 path1 && |
| 27 | test_ln_s_add ../path1 path2/bazbo && |
| 28 | echo Lo >path2/foo && |
| 29 | echo Mi >path2/baz/b && |
| 30 | find path? \( -type f -o -type l \) -print | |
| 31 | xargs git update-index --add && |
| 32 | tree=$(git write-tree) && |
| 33 | echo $tree' |
| 34 | |
| 35 | test_output () { |
| 36 | sed -e "s/ $OID_REGEX / X /" <current >check |
| 37 | test_cmp expected check |
| 38 | } |
| 39 | |
| 40 | test_expect_success \ |
| 41 | 'ls-tree plain' \ |
| 42 | 'git ls-tree $tree >current && |
| 43 | cat >expected <<\EOF && |
| 44 | 100644 blob X path0 |
| 45 | 120000 blob X path1 |
| 46 | 040000 tree X path2 |
| 47 | EOF |
| 48 | test_output' |
| 49 | |
| 50 | test_expect_success \ |
| 51 | 'ls-tree recursive' \ |
| 52 | 'git ls-tree -r $tree >current && |
| 53 | cat >expected <<\EOF && |
| 54 | 100644 blob X path0 |
| 55 | 120000 blob X path1 |
| 56 | 100644 blob X path2/baz/b |
| 57 | 120000 blob X path2/bazbo |
| 58 | 100644 blob X path2/foo |
| 59 | EOF |
| 60 | test_output' |
| 61 | |
| 62 | test_expect_success \ |
| 63 | 'ls-tree recursive with -t' \ |
| 64 | 'git ls-tree -r -t $tree >current && |
| 65 | cat >expected <<\EOF && |
| 66 | 100644 blob X path0 |
| 67 | 120000 blob X path1 |
| 68 | 040000 tree X path2 |
| 69 | 040000 tree X path2/baz |
| 70 | 100644 blob X path2/baz/b |
| 71 | 120000 blob X path2/bazbo |
| 72 | 100644 blob X path2/foo |
| 73 | EOF |
| 74 | test_output' |
| 75 | |
| 76 | test_expect_success \ |
| 77 | 'ls-tree recursive with -d' \ |
| 78 | 'git ls-tree -r -d $tree >current && |
| 79 | cat >expected <<\EOF && |
| 80 | 040000 tree X path2 |
| 81 | 040000 tree X path2/baz |
| 82 | EOF |
| 83 | test_output' |
| 84 | |
| 85 | test_expect_success \ |
| 86 | 'ls-tree filtered with path' \ |
| 87 | 'git ls-tree $tree path >current && |
| 88 | cat >expected <<\EOF && |
| 89 | EOF |
| 90 | test_output' |
| 91 | |
| 92 | |
| 93 | # it used to be path1 and then path0, but with pathspec semantics |
| 94 | # they are shown in canonical order. |
| 95 | test_expect_success \ |
| 96 | 'ls-tree filtered with path1 path0' \ |
| 97 | 'git ls-tree $tree path1 path0 >current && |
| 98 | cat >expected <<\EOF && |
| 99 | 100644 blob X path0 |
| 100 | 120000 blob X path1 |
| 101 | EOF |
| 102 | test_output' |
| 103 | |
| 104 | test_expect_success \ |
| 105 | 'ls-tree filtered with path0/' \ |
| 106 | 'git ls-tree $tree path0/ >current && |
| 107 | cat >expected <<\EOF && |
| 108 | EOF |
| 109 | test_output' |
| 110 | |
| 111 | # It used to show path2 and its immediate children but |
| 112 | # with pathspec semantics it shows only path2 |
| 113 | test_expect_success \ |
| 114 | 'ls-tree filtered with path2' \ |
| 115 | 'git ls-tree $tree path2 >current && |
| 116 | cat >expected <<\EOF && |
| 117 | 040000 tree X path2 |
| 118 | EOF |
| 119 | test_output' |
| 120 | |
| 121 | # ... and path2/ shows the children. |
| 122 | test_expect_success \ |
| 123 | 'ls-tree filtered with path2/' \ |
| 124 | 'git ls-tree $tree path2/ >current && |
| 125 | cat >expected <<\EOF && |
| 126 | 040000 tree X path2/baz |
| 127 | 120000 blob X path2/bazbo |
| 128 | 100644 blob X path2/foo |
| 129 | EOF |
| 130 | test_output' |
| 131 | |
| 132 | # The same change -- exact match does not show children of |
| 133 | # path2/baz |
| 134 | test_expect_success \ |
| 135 | 'ls-tree filtered with path2/baz' \ |
| 136 | 'git ls-tree $tree path2/baz >current && |
| 137 | cat >expected <<\EOF && |
| 138 | 040000 tree X path2/baz |
| 139 | EOF |
| 140 | test_output' |
| 141 | |
| 142 | test_expect_success \ |
| 143 | 'ls-tree filtered with path2/bak' \ |
| 144 | 'git ls-tree $tree path2/bak >current && |
| 145 | cat >expected <<\EOF && |
| 146 | EOF |
| 147 | test_output' |
| 148 | |
| 149 | test_expect_success \ |
| 150 | 'ls-tree -t filtered with path2/bak' \ |
| 151 | 'git ls-tree -t $tree path2/bak >current && |
| 152 | cat >expected <<\EOF && |
| 153 | 040000 tree X path2 |
| 154 | EOF |
| 155 | test_output' |
| 156 | |
| 157 | test_expect_success \ |
| 158 | 'ls-tree with one path a prefix of the other' \ |
| 159 | 'git ls-tree $tree path2/baz path2/bazbo >current && |
| 160 | cat >expected <<\EOF && |
| 161 | 040000 tree X path2/baz |
| 162 | 120000 blob X path2/bazbo |
| 163 | EOF |
| 164 | test_output' |
| 165 | |
| 166 | test_done |