Fix overzealous <host>:/<path> -> ssh://<host>/<path> transformation
[msysgit/historical-msysgit.git] / git / t / t3100-ls-tree-restrict.sh
blob4794fdd9eb3122bff43f0529340c18e39b3931d9
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git ls-tree test.
8 This test runs git ls-tree with the following in a tree.
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
16 The new path restriction code should do the right thing for path2 and
17 path2/baz. Also path0/ should snow nothing.
19 . ./test-lib.sh
21 test "$no_symlinks" && {
22 function ln () {
23 test "$1" = -s && shift
24 date > "$2"
26 function diff () {
27 sed s/^120000/100644/ < "$1" > "$1".doof
28 git diff "$1".doof "$2"
33 test_expect_success \
34 'setup' \
35 'mkdir path2 path2/baz &&
36 echo Hi >path0 &&
37 ln -s path0 path1 &&
38 echo Lo >path2/foo &&
39 ln -s ../path1 path2/bazbo &&
40 echo Mi >path2/baz/b &&
41 /usr/bin/find path? \( -type f -o -type l \) -print |
42 xargs git update-index --add &&
43 tree=`git write-tree` &&
44 echo $tree'
46 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
47 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
48 test_output () {
49 sed -e "s/ $_x40 / X /" <current >check
50 diff expected check
53 test_expect_success \
54 'ls-tree plain' \
55 'git ls-tree $tree >current &&
56 cat >expected <<\EOF &&
57 100644 blob X path0
58 120000 blob X path1
59 040000 tree X path2
60 EOF
61 test_output'
63 test_expect_success \
64 'ls-tree recursive' \
65 'git ls-tree -r $tree >current &&
66 cat >expected <<\EOF &&
67 100644 blob X path0
68 120000 blob X path1
69 100644 blob X path2/baz/b
70 120000 blob X path2/bazbo
71 100644 blob X path2/foo
72 EOF
73 test_output'
75 test_expect_success \
76 'ls-tree recursive with -t' \
77 'git ls-tree -r -t $tree >current &&
78 cat >expected <<\EOF &&
79 100644 blob X path0
80 120000 blob X path1
81 040000 tree X path2
82 040000 tree X path2/baz
83 100644 blob X path2/baz/b
84 120000 blob X path2/bazbo
85 100644 blob X path2/foo
86 EOF
87 test_output'
89 test_expect_success \
90 'ls-tree recursive with -d' \
91 'git ls-tree -r -d $tree >current &&
92 cat >expected <<\EOF &&
93 040000 tree X path2
94 040000 tree X path2/baz
95 EOF
96 test_output'
98 test_expect_success \
99 'ls-tree filtered with path' \
100 'git ls-tree $tree path >current &&
101 cat >expected <<\EOF &&
103 test_output'
106 # it used to be path1 and then path0, but with pathspec semantics
107 # they are shown in canonical order.
108 test_expect_success \
109 'ls-tree filtered with path1 path0' \
110 'git ls-tree $tree path1 path0 >current &&
111 cat >expected <<\EOF &&
112 100644 blob X path0
113 120000 blob X path1
115 test_output'
117 test_expect_success \
118 'ls-tree filtered with path0/' \
119 'git ls-tree $tree path0/ >current &&
120 cat >expected <<\EOF &&
122 test_output'
124 # It used to show path2 and its immediate children but
125 # with pathspec semantics it shows only path2
126 test_expect_success \
127 'ls-tree filtered with path2' \
128 'git ls-tree $tree path2 >current &&
129 cat >expected <<\EOF &&
130 040000 tree X path2
132 test_output'
134 # ... and path2/ shows the children.
135 test_expect_success \
136 'ls-tree filtered with path2/' \
137 'git ls-tree $tree path2/ >current &&
138 cat >expected <<\EOF &&
139 040000 tree X path2/baz
140 120000 blob X path2/bazbo
141 100644 blob X path2/foo
143 test_output'
145 # The same change -- exact match does not show children of
146 # path2/baz
147 test_expect_success \
148 'ls-tree filtered with path2/baz' \
149 'git ls-tree $tree path2/baz >current &&
150 cat >expected <<\EOF &&
151 040000 tree X path2/baz
153 test_output'
155 test_expect_success \
156 'ls-tree filtered with path2/bak' \
157 'git ls-tree $tree path2/bak >current &&
158 cat >expected <<\EOF &&
160 test_output'
162 test_expect_success \
163 'ls-tree -t filtered with path2/bak' \
164 'git ls-tree -t $tree path2/bak >current &&
165 cat >expected <<\EOF &&
166 040000 tree X path2
168 test_output'
170 test_done