blob: 12bf31022a871c4d2e43866ec6053c55205a3476 [file] [log] [blame]
robfitz@273k.netab1630a2005-10-07 16:54:06 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4# Copyright (c) 2005 Robert Fitzsimons
5#
6
Junio C Hamano5be60072007-07-02 22:52:14 -07007test_description='git ls-tree directory and filenames handling.
robfitz@273k.netab1630a2005-10-07 16:54:06 -07008
Junio C Hamano5be60072007-07-02 22:52:14 -07009This test runs git ls-tree with the following in a tree.
robfitz@273k.netab1630a2005-10-07 16:54:06 -070010
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ä2e3a16b2016-08-09 11:53:38 +030019Test the handling of multiple directories which have matching file
robfitz@273k.netab1630a2005-10-07 16:54:06 -070020entries. Also test odd filename and missing entries handling.
21'
22. ./test-lib.sh
23
Junio C Hamanoe22148f2010-09-11 10:53:29 -070024test_expect_success 'setup' '
25 echo 111 >1.txt &&
26 echo 222 >2.txt &&
27 mkdir path0 path0/a path0/a/b path0/a/b/c &&
28 echo 111 >path0/a/b/c/1.txt &&
29 mkdir path1 path1/b path1/b/c &&
30 echo 111 >path1/b/c/1.txt &&
31 mkdir path2 &&
32 echo 111 >path2/1.txt &&
33 mkdir path3 &&
34 echo 111 >path3/1.txt &&
35 echo 222 >path3/2.txt &&
36 find *.txt path* \( -type f -o -type l \) -print |
37 xargs git update-index --add &&
Elia Pinto8db32942015-12-22 16:27:44 +010038 tree=$(git write-tree) &&
Junio C Hamanoe22148f2010-09-11 10:53:29 -070039 echo $tree
40'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070041
robfitz@273k.netab1630a2005-10-07 16:54:06 -070042test_output () {
brian m. carlson2ece6ad2018-05-13 02:24:15 +000043 sed -e "s/ $OID_REGEX / X /" <current >check &&
Junio C Hamanoe22148f2010-09-11 10:53:29 -070044 test_cmp expected check
robfitz@273k.netab1630a2005-10-07 16:54:06 -070045}
46
Junio C Hamanoe22148f2010-09-11 10:53:29 -070047test_expect_success 'ls-tree plain' '
48 git ls-tree $tree >current &&
49 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -070050100644 blob X 1.txt
51100644 blob X 2.txt
52040000 tree X path0
53040000 tree X path1
54040000 tree X path2
55040000 tree X path3
56EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -070057 test_output
58'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070059
Junio C Hamano246cc522005-11-28 02:32:42 -080060# Recursive does not show tree nodes anymore...
Junio C Hamanoe22148f2010-09-11 10:53:29 -070061test_expect_success 'ls-tree recursive' '
62 git ls-tree -r $tree >current &&
63 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -070064100644 blob X 1.txt
65100644 blob X 2.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -070066100644 blob X path0/a/b/c/1.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -070067100644 blob X path1/b/c/1.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -070068100644 blob X path2/1.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -070069100644 blob X path3/1.txt
70100644 blob X path3/2.txt
71EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -070072 test_output
73'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070074
Junio C Hamanoe22148f2010-09-11 10:53:29 -070075test_expect_success 'ls-tree filter 1.txt' '
76 git ls-tree $tree 1.txt >current &&
77 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -070078100644 blob X 1.txt
79EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -070080 test_output
81'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070082
Junio C Hamanoe22148f2010-09-11 10:53:29 -070083test_expect_success 'ls-tree filter path1/b/c/1.txt' '
84 git ls-tree $tree path1/b/c/1.txt >current &&
85 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -070086100644 blob X path1/b/c/1.txt
87EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -070088 test_output
89'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070090
Junio C Hamanoe22148f2010-09-11 10:53:29 -070091test_expect_success 'ls-tree filter all 1.txt files' '
92 git ls-tree $tree 1.txt path0/a/b/c/1.txt \
93 path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
94 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -070095100644 blob X 1.txt
96100644 blob X path0/a/b/c/1.txt
97100644 blob X path1/b/c/1.txt
98100644 blob X path2/1.txt
99100644 blob X path3/1.txt
100EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700101 test_output
102'
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700103
Junio C Hamano246cc522005-11-28 02:32:42 -0800104# I am not so sure about this one after ls-tree doing pathspec match.
105# Having both path0/a and path0/a/b/c makes path0/a redundant, and
106# it behaves as if path0/a/b/c, path1/b/c, path2 and path3 are specified.
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700107test_expect_success 'ls-tree filter directories' '
108 git ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
109 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700110040000 tree X path0/a/b/c
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700111040000 tree X path1/b/c
Junio C Hamano246cc522005-11-28 02:32:42 -0800112040000 tree X path2
113040000 tree X path3
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700114EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700115 test_output
116'
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700117
Junio C Hamano246cc522005-11-28 02:32:42 -0800118# Again, duplicates are filtered away so this is equivalent to
119# having 1.txt and path3
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700120test_expect_success 'ls-tree filter odd names' '
121 git ls-tree $tree 1.txt ./1.txt .//1.txt \
122 path3/1.txt path3/./1.txt path3 path3// >current &&
123 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700124100644 blob X 1.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700125100644 blob X path3/1.txt
126100644 blob X path3/2.txt
127EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700128 test_output
129'
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700130
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700131test_expect_success 'ls-tree filter missing files and extra slashes' '
132 git ls-tree $tree 1.txt/ abc.txt \
133 path3//23.txt path3/2.txt/// >current &&
134 >expected &&
135 test_output
136'
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700137
Junio C Hamano8092bfb2009-04-01 19:34:03 -0700138test_expect_success 'ls-tree filter is leading path match' '
139 git ls-tree $tree pa path3/a >current &&
140 >expected &&
141 test_output
142'
143
Stephen Boyd3ea60252009-11-13 20:34:07 -0800144test_expect_success 'ls-tree --full-name' '
145 (
146 cd path0 &&
147 git ls-tree --full-name $tree a
148 ) >current &&
149 cat >expected <<\EOF &&
150040000 tree X path0/a
151EOF
152 test_output
153'
154
155test_expect_success 'ls-tree --full-tree' '
156 (
157 cd path1/b/c &&
158 git ls-tree --full-tree $tree
159 ) >current &&
160 cat >expected <<\EOF &&
161100644 blob X 1.txt
162100644 blob X 2.txt
163040000 tree X path0
164040000 tree X path1
165040000 tree X path2
166040000 tree X path3
167EOF
168 test_output
169'
170
171test_expect_success 'ls-tree --full-tree -r' '
172 (
173 cd path3/ &&
174 git ls-tree --full-tree -r $tree
175 ) >current &&
176 cat >expected <<\EOF &&
177100644 blob X 1.txt
178100644 blob X 2.txt
179100644 blob X path0/a/b/c/1.txt
180100644 blob X path1/b/c/1.txt
181100644 blob X path2/1.txt
182100644 blob X path3/1.txt
183100644 blob X path3/2.txt
184EOF
185 test_output
186'
187
188test_expect_success 'ls-tree --abbrev=5' '
189 git ls-tree --abbrev=5 $tree >current &&
190 sed -e "s/ $_x05[0-9a-f]* / X /" <current >check &&
191 cat >expected <<\EOF &&
192100644 blob X 1.txt
193100644 blob X 2.txt
194040000 tree X path0
195040000 tree X path1
196040000 tree X path2
197040000 tree X path3
198EOF
199 test_cmp expected check
200'
201
202test_expect_success 'ls-tree --name-only' '
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700203 git ls-tree --name-only $tree >current &&
Stephen Boyd3ea60252009-11-13 20:34:07 -0800204 cat >expected <<\EOF &&
2051.txt
2062.txt
207path0
208path1
209path2
210path3
211EOF
212 test_output
213'
214
215test_expect_success 'ls-tree --name-only -r' '
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700216 git ls-tree --name-only -r $tree >current &&
Stephen Boyd3ea60252009-11-13 20:34:07 -0800217 cat >expected <<\EOF &&
2181.txt
2192.txt
220path0/a/b/c/1.txt
221path1/b/c/1.txt
222path2/1.txt
223path3/1.txt
224path3/2.txt
225EOF
226 test_output
227'
228
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700229test_done