robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # Copyright (c) 2005 Robert Fitzsimons |
| 5 | # |
| 6 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 7 | test_description='git ls-tree directory and filenames handling. |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 8 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 9 | This test runs git ls-tree with the following in a tree. |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 10 | |
| 11 | 1.txt - a file |
| 12 | 2.txt - a file |
| 13 | path0/a/b/c/1.txt - a file in a directory |
| 14 | path1/b/c/1.txt - a file in a directory |
| 15 | path2/1.txt - a file in a directory |
| 16 | path3/1.txt - a file in a directory |
| 17 | path3/2.txt - a file in a directory |
| 18 | |
Ville Skyttä | 2e3a16b | 2016-08-09 11:53:38 +0300 | [diff] [blame] | 19 | Test the handling of multiple directories which have matching file |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 20 | entries. Also test odd filename and missing entries handling. |
| 21 | ' |
Ævar Arnfjörð Bjarmason | 809aeed | 2021-10-12 15:56:39 +0200 | [diff] [blame] | 22 | |
| 23 | TEST_PASSES_SANITIZE_LEAK=true |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 24 | . ./test-lib.sh |
| 25 | |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 26 | test_expect_success 'setup' ' |
| 27 | echo 111 >1.txt && |
| 28 | echo 222 >2.txt && |
| 29 | mkdir path0 path0/a path0/a/b path0/a/b/c && |
| 30 | echo 111 >path0/a/b/c/1.txt && |
| 31 | mkdir path1 path1/b path1/b/c && |
| 32 | echo 111 >path1/b/c/1.txt && |
| 33 | mkdir path2 && |
| 34 | echo 111 >path2/1.txt && |
| 35 | mkdir path3 && |
| 36 | echo 111 >path3/1.txt && |
| 37 | echo 222 >path3/2.txt && |
| 38 | find *.txt path* \( -type f -o -type l \) -print | |
| 39 | xargs git update-index --add && |
Elia Pinto | 8db3294 | 2015-12-22 16:27:44 +0100 | [diff] [blame] | 40 | tree=$(git write-tree) && |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 41 | echo $tree |
| 42 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 43 | |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 44 | test_output () { |
brian m. carlson | 2ece6ad | 2018-05-13 02:24:15 +0000 | [diff] [blame] | 45 | sed -e "s/ $OID_REGEX / X /" <current >check && |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 46 | test_cmp expected check |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 49 | test_expect_success 'ls-tree plain' ' |
| 50 | git ls-tree $tree >current && |
| 51 | cat >expected <<\EOF && |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 52 | 100644 blob X 1.txt |
| 53 | 100644 blob X 2.txt |
| 54 | 040000 tree X path0 |
| 55 | 040000 tree X path1 |
| 56 | 040000 tree X path2 |
| 57 | 040000 tree X path3 |
| 58 | EOF |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 59 | test_output |
| 60 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 61 | |
Junio C Hamano | 246cc52 | 2005-11-28 02:32:42 -0800 | [diff] [blame] | 62 | # Recursive does not show tree nodes anymore... |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 63 | test_expect_success 'ls-tree recursive' ' |
| 64 | git ls-tree -r $tree >current && |
| 65 | cat >expected <<\EOF && |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 66 | 100644 blob X 1.txt |
| 67 | 100644 blob X 2.txt |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 68 | 100644 blob X path0/a/b/c/1.txt |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 69 | 100644 blob X path1/b/c/1.txt |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 70 | 100644 blob X path2/1.txt |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 71 | 100644 blob X path3/1.txt |
| 72 | 100644 blob X path3/2.txt |
| 73 | EOF |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 74 | test_output |
| 75 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 76 | |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 77 | test_expect_success 'ls-tree filter 1.txt' ' |
| 78 | git ls-tree $tree 1.txt >current && |
| 79 | cat >expected <<\EOF && |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 80 | 100644 blob X 1.txt |
| 81 | EOF |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 82 | test_output |
| 83 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 84 | |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 85 | test_expect_success 'ls-tree filter path1/b/c/1.txt' ' |
| 86 | git ls-tree $tree path1/b/c/1.txt >current && |
| 87 | cat >expected <<\EOF && |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 88 | 100644 blob X path1/b/c/1.txt |
| 89 | EOF |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 90 | test_output |
| 91 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 92 | |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 93 | test_expect_success 'ls-tree filter all 1.txt files' ' |
| 94 | git ls-tree $tree 1.txt path0/a/b/c/1.txt \ |
| 95 | path1/b/c/1.txt path2/1.txt path3/1.txt >current && |
| 96 | cat >expected <<\EOF && |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 97 | 100644 blob X 1.txt |
| 98 | 100644 blob X path0/a/b/c/1.txt |
| 99 | 100644 blob X path1/b/c/1.txt |
| 100 | 100644 blob X path2/1.txt |
| 101 | 100644 blob X path3/1.txt |
| 102 | EOF |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 103 | test_output |
| 104 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 105 | |
Junio C Hamano | 246cc52 | 2005-11-28 02:32:42 -0800 | [diff] [blame] | 106 | # I am not so sure about this one after ls-tree doing pathspec match. |
| 107 | # Having both path0/a and path0/a/b/c makes path0/a redundant, and |
| 108 | # it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified. |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 109 | test_expect_success 'ls-tree filter directories' ' |
| 110 | git ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current && |
| 111 | cat >expected <<\EOF && |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 112 | 040000 tree X path0/a/b/c |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 113 | 040000 tree X path1/b/c |
Junio C Hamano | 246cc52 | 2005-11-28 02:32:42 -0800 | [diff] [blame] | 114 | 040000 tree X path2 |
| 115 | 040000 tree X path3 |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 116 | EOF |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 117 | test_output |
| 118 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 119 | |
Junio C Hamano | 246cc52 | 2005-11-28 02:32:42 -0800 | [diff] [blame] | 120 | # Again, duplicates are filtered away so this is equivalent to |
| 121 | # having 1.txt and path3 |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 122 | test_expect_success 'ls-tree filter odd names' ' |
| 123 | git ls-tree $tree 1.txt ./1.txt .//1.txt \ |
| 124 | path3/1.txt path3/./1.txt path3 path3// >current && |
| 125 | cat >expected <<\EOF && |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 126 | 100644 blob X 1.txt |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 127 | 100644 blob X path3/1.txt |
| 128 | 100644 blob X path3/2.txt |
| 129 | EOF |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 130 | test_output |
| 131 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 132 | |
Junio C Hamano | e22148f | 2010-09-11 10:53:29 -0700 | [diff] [blame] | 133 | test_expect_success 'ls-tree filter missing files and extra slashes' ' |
| 134 | git ls-tree $tree 1.txt/ abc.txt \ |
| 135 | path3//23.txt path3/2.txt/// >current && |
| 136 | >expected && |
| 137 | test_output |
| 138 | ' |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 139 | |
Junio C Hamano | 8092bfb | 2009-04-01 19:34:03 -0700 | [diff] [blame] | 140 | test_expect_success 'ls-tree filter is leading path match' ' |
| 141 | git ls-tree $tree pa path3/a >current && |
| 142 | >expected && |
| 143 | test_output |
| 144 | ' |
| 145 | |
Stephen Boyd | 3ea6025 | 2009-11-13 20:34:07 -0800 | [diff] [blame] | 146 | test_expect_success 'ls-tree --full-name' ' |
| 147 | ( |
| 148 | cd path0 && |
| 149 | git ls-tree --full-name $tree a |
| 150 | ) >current && |
| 151 | cat >expected <<\EOF && |
| 152 | 040000 tree X path0/a |
| 153 | EOF |
| 154 | test_output |
| 155 | ' |
| 156 | |
René Scharfe | 991c552 | 2023-07-18 17:44:13 +0200 | [diff] [blame] | 157 | test_expect_success 'ls-tree --no-full-name' ' |
| 158 | git -C path0 ls-tree --no-full-name $tree a >current && |
| 159 | cat >expected <<-EOF && |
| 160 | 040000 tree X a |
| 161 | EOF |
| 162 | test_output |
| 163 | ' |
| 164 | |
Stephen Boyd | 3ea6025 | 2009-11-13 20:34:07 -0800 | [diff] [blame] | 165 | test_expect_success 'ls-tree --full-tree' ' |
| 166 | ( |
| 167 | cd path1/b/c && |
| 168 | git ls-tree --full-tree $tree |
| 169 | ) >current && |
| 170 | cat >expected <<\EOF && |
| 171 | 100644 blob X 1.txt |
| 172 | 100644 blob X 2.txt |
| 173 | 040000 tree X path0 |
| 174 | 040000 tree X path1 |
| 175 | 040000 tree X path2 |
| 176 | 040000 tree X path3 |
| 177 | EOF |
| 178 | test_output |
| 179 | ' |
| 180 | |
| 181 | test_expect_success 'ls-tree --full-tree -r' ' |
| 182 | ( |
| 183 | cd path3/ && |
| 184 | git ls-tree --full-tree -r $tree |
| 185 | ) >current && |
| 186 | cat >expected <<\EOF && |
| 187 | 100644 blob X 1.txt |
| 188 | 100644 blob X 2.txt |
| 189 | 100644 blob X path0/a/b/c/1.txt |
| 190 | 100644 blob X path1/b/c/1.txt |
| 191 | 100644 blob X path2/1.txt |
| 192 | 100644 blob X path3/1.txt |
| 193 | 100644 blob X path3/2.txt |
| 194 | EOF |
| 195 | test_output |
| 196 | ' |
| 197 | |
| 198 | test_expect_success 'ls-tree --abbrev=5' ' |
| 199 | git ls-tree --abbrev=5 $tree >current && |
| 200 | sed -e "s/ $_x05[0-9a-f]* / X /" <current >check && |
| 201 | cat >expected <<\EOF && |
| 202 | 100644 blob X 1.txt |
| 203 | 100644 blob X 2.txt |
| 204 | 040000 tree X path0 |
| 205 | 040000 tree X path1 |
| 206 | 040000 tree X path2 |
| 207 | 040000 tree X path3 |
| 208 | EOF |
| 209 | test_cmp expected check |
| 210 | ' |
| 211 | |
Ævar Arnfjörð Bjarmason | a53343e | 2022-03-23 17:13:01 +0800 | [diff] [blame] | 212 | for opt in --name-only --name-status |
| 213 | do |
| 214 | test_expect_success "ls-tree $opt" ' |
| 215 | git ls-tree $opt $tree >current && |
| 216 | cat >expected <<-\EOF && |
| 217 | 1.txt |
| 218 | 2.txt |
| 219 | path0 |
| 220 | path1 |
| 221 | path2 |
| 222 | path3 |
| 223 | EOF |
| 224 | test_output |
| 225 | ' |
Stephen Boyd | 3ea6025 | 2009-11-13 20:34:07 -0800 | [diff] [blame] | 226 | |
Ævar Arnfjörð Bjarmason | a53343e | 2022-03-23 17:13:01 +0800 | [diff] [blame] | 227 | test_expect_success "ls-tree $opt -r" ' |
| 228 | git ls-tree $opt -r $tree >current && |
| 229 | cat >expected <<-\EOF && |
| 230 | 1.txt |
| 231 | 2.txt |
| 232 | path0/a/b/c/1.txt |
| 233 | path1/b/c/1.txt |
| 234 | path2/1.txt |
| 235 | path3/1.txt |
| 236 | path3/2.txt |
| 237 | EOF |
| 238 | test_output |
| 239 | ' |
| 240 | done |
Stephen Boyd | 3ea6025 | 2009-11-13 20:34:07 -0800 | [diff] [blame] | 241 | |
robfitz@273k.net | ab1630a | 2005-10-07 16:54:06 -0700 | [diff] [blame] | 242 | test_done |