blob: 5af2dac0e4b8d5fde4d6a11dae240086473e0571 [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'
Ævar Arnfjörð Bjarmason809aeed2021-10-12 15:56:39 +020022
23TEST_PASSES_SANITIZE_LEAK=true
robfitz@273k.netab1630a2005-10-07 16:54:06 -070024. ./test-lib.sh
25
Junio C Hamanoe22148f2010-09-11 10:53:29 -070026test_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 Pinto8db32942015-12-22 16:27:44 +010040 tree=$(git write-tree) &&
Junio C Hamanoe22148f2010-09-11 10:53:29 -070041 echo $tree
42'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070043
robfitz@273k.netab1630a2005-10-07 16:54:06 -070044test_output () {
brian m. carlson2ece6ad2018-05-13 02:24:15 +000045 sed -e "s/ $OID_REGEX / X /" <current >check &&
Junio C Hamanoe22148f2010-09-11 10:53:29 -070046 test_cmp expected check
robfitz@273k.netab1630a2005-10-07 16:54:06 -070047}
48
Junio C Hamanoe22148f2010-09-11 10:53:29 -070049test_expect_success 'ls-tree plain' '
50 git ls-tree $tree >current &&
51 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -070052100644 blob X 1.txt
53100644 blob X 2.txt
54040000 tree X path0
55040000 tree X path1
56040000 tree X path2
57040000 tree X path3
58EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -070059 test_output
60'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070061
Junio C Hamano246cc522005-11-28 02:32:42 -080062# Recursive does not show tree nodes anymore...
Junio C Hamanoe22148f2010-09-11 10:53:29 -070063test_expect_success 'ls-tree recursive' '
64 git ls-tree -r $tree >current &&
65 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -070066100644 blob X 1.txt
67100644 blob X 2.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -070068100644 blob X path0/a/b/c/1.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -070069100644 blob X path1/b/c/1.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -070070100644 blob X path2/1.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -070071100644 blob X path3/1.txt
72100644 blob X path3/2.txt
73EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -070074 test_output
75'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070076
Junio C Hamanoe22148f2010-09-11 10:53:29 -070077test_expect_success 'ls-tree filter 1.txt' '
78 git ls-tree $tree 1.txt >current &&
79 cat >expected <<\EOF &&
robfitz@273k.netab1630a2005-10-07 16:54:06 -070080100644 blob X 1.txt
81EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -070082 test_output
83'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070084
Junio C Hamanoe22148f2010-09-11 10:53:29 -070085test_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.netab1630a2005-10-07 16:54:06 -070088100644 blob X path1/b/c/1.txt
89EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -070090 test_output
91'
robfitz@273k.netab1630a2005-10-07 16:54:06 -070092
Junio C Hamanoe22148f2010-09-11 10:53:29 -070093test_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.netab1630a2005-10-07 16:54:06 -070097100644 blob X 1.txt
98100644 blob X path0/a/b/c/1.txt
99100644 blob X path1/b/c/1.txt
100100644 blob X path2/1.txt
101100644 blob X path3/1.txt
102EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700103 test_output
104'
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700105
Junio C Hamano246cc522005-11-28 02:32:42 -0800106# 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 Hamanoe22148f2010-09-11 10:53:29 -0700109test_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.netab1630a2005-10-07 16:54:06 -0700112040000 tree X path0/a/b/c
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700113040000 tree X path1/b/c
Junio C Hamano246cc522005-11-28 02:32:42 -0800114040000 tree X path2
115040000 tree X path3
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700116EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700117 test_output
118'
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700119
Junio C Hamano246cc522005-11-28 02:32:42 -0800120# Again, duplicates are filtered away so this is equivalent to
121# having 1.txt and path3
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700122test_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.netab1630a2005-10-07 16:54:06 -0700126100644 blob X 1.txt
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700127100644 blob X path3/1.txt
128100644 blob X path3/2.txt
129EOF
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700130 test_output
131'
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700132
Junio C Hamanoe22148f2010-09-11 10:53:29 -0700133test_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.netab1630a2005-10-07 16:54:06 -0700139
Junio C Hamano8092bfb2009-04-01 19:34:03 -0700140test_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 Boyd3ea60252009-11-13 20:34:07 -0800146test_expect_success 'ls-tree --full-name' '
147 (
148 cd path0 &&
149 git ls-tree --full-name $tree a
150 ) >current &&
151 cat >expected <<\EOF &&
152040000 tree X path0/a
153EOF
154 test_output
155'
156
René Scharfe991c5522023-07-18 17:44:13 +0200157test_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 Boyd3ea60252009-11-13 20:34:07 -0800165test_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 &&
171100644 blob X 1.txt
172100644 blob X 2.txt
173040000 tree X path0
174040000 tree X path1
175040000 tree X path2
176040000 tree X path3
177EOF
178 test_output
179'
180
181test_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 &&
187100644 blob X 1.txt
188100644 blob X 2.txt
189100644 blob X path0/a/b/c/1.txt
190100644 blob X path1/b/c/1.txt
191100644 blob X path2/1.txt
192100644 blob X path3/1.txt
193100644 blob X path3/2.txt
194EOF
195 test_output
196'
197
198test_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 &&
202100644 blob X 1.txt
203100644 blob X 2.txt
204040000 tree X path0
205040000 tree X path1
206040000 tree X path2
207040000 tree X path3
208EOF
209 test_cmp expected check
210'
211
Ævar Arnfjörð Bjarmasona53343e2022-03-23 17:13:01 +0800212for opt in --name-only --name-status
213do
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 Boyd3ea60252009-11-13 20:34:07 -0800226
Ævar Arnfjörð Bjarmasona53343e2022-03-23 17:13:01 +0800227 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 '
240done
Stephen Boyd3ea60252009-11-13 20:34:07 -0800241
robfitz@273k.netab1630a2005-10-07 16:54:06 -0700242test_done