3 # Copyright (c) 2005 Junio C Hamano
4 # Copyright (c) 2005 Robert Fitzsimons
7 test_description='git ls-tree directory and filenames handling.
9 This test runs git ls-tree with the following in a tree.
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
19 Test the handling of mulitple directories which have matching file
20 entries. Also test odd filename and missing entries handling.
28 mkdir path0 path0/a path0/a/b path0/a/b/c &&
29 echo 111 >path0/a/b/c/1.txt &&
30 mkdir path1 path1/b path1/b/c &&
31 echo 111 >path1/b/c/1.txt &&
33 echo 111 >path2/1.txt &&
35 echo 111 >path3/1.txt &&
36 echo 222 >path3/2.txt &&
37 find *.txt path* \( -type f -o -type l \) -print |
38 xargs git update-index --add &&
39 tree=`git write-tree` &&
42 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
43 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
45 sed -e "s/ $_x40 / X /" <current >check
46 test_cmp expected check
51 'git ls-tree $tree >current &&
52 cat >expected <<\EOF &&
62 # Recursive does not show tree nodes anymore...
65 'git ls-tree -r $tree >current &&
66 cat >expected <<\EOF &&
69 100644 blob X path0/a/b/c/1.txt
70 100644 blob X path1/b/c/1.txt
71 100644 blob X path2/1.txt
72 100644 blob X path3/1.txt
73 100644 blob X path3/2.txt
78 'ls-tree filter 1.txt' \
79 'git ls-tree $tree 1.txt >current &&
80 cat >expected <<\EOF &&
86 'ls-tree filter path1/b/c/1.txt' \
87 'git ls-tree $tree path1/b/c/1.txt >current &&
88 cat >expected <<\EOF &&
89 100644 blob X path1/b/c/1.txt
94 'ls-tree filter all 1.txt files' \
95 'git ls-tree $tree 1.txt path0/a/b/c/1.txt path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
96 cat >expected <<\EOF &&
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
105 # I am not so sure about this one after ls-tree doing pathspec match.
106 # Having both path0/a and path0/a/b/c makes path0/a redundant, and
107 # it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified.
108 test_expect_success \
109 '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 &&
112 040000 tree X path0/a/b/c
113 040000 tree X path1/b/c
119 # Again, duplicates are filtered away so this is equivalent to
120 # having 1.txt and path3
121 test_expect_success \
122 'ls-tree filter odd names' \
123 'git ls-tree $tree 1.txt ./1.txt .//1.txt path3/1.txt path3/./1.txt path3 path3// >current &&
124 cat >expected <<\EOF &&
126 100644 blob X path3/1.txt
127 100644 blob X path3/2.txt
131 test_expect_success \
132 'ls-tree filter missing files and extra slashes' \
133 'git ls-tree $tree 1.txt/ abc.txt path3//23.txt path3/2.txt/// >current &&
134 cat >expected <<\EOF &&