]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3100-ls-tree-restrict.sh
Merge branch 'js/maint-merge-one-file-osx-expr'
[thirdparty/git.git] / t / t3100-ls-tree-restrict.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 test_description='git ls-tree test.
7
8 This test runs git ls-tree with the following in a tree.
9
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
15
16 The new path restriction code should do the right thing for path2 and
17 path2/baz. Also path0/ should snow nothing.
18 '
19 . ./test-lib.sh
20
21 test_expect_success \
22 'setup' \
23 'mkdir path2 path2/baz &&
24 echo Hi >path0 &&
25 if test_have_prereq SYMLINKS
26 then
27 ln -s path0 path1 &&
28 ln -s ../path1 path2/bazbo
29 make_expected () {
30 cat >expected
31 }
32 else
33 printf path0 > path1 &&
34 printf ../path1 > path2/bazbo
35 make_expected () {
36 sed -e "s/120000 /100644 /" >expected
37 }
38 fi &&
39 echo Lo >path2/foo &&
40 echo Mi >path2/baz/b &&
41 find path? \( -type f -o -type l \) -print |
42 xargs git update-index --add &&
43 tree=`git write-tree` &&
44 echo $tree'
45
46 test_output () {
47 sed -e "s/ $_x40 / X /" <current >check
48 test_cmp expected check
49 }
50
51 test_expect_success \
52 'ls-tree plain' \
53 'git ls-tree $tree >current &&
54 make_expected <<\EOF &&
55 100644 blob X path0
56 120000 blob X path1
57 040000 tree X path2
58 EOF
59 test_output'
60
61 test_expect_success \
62 'ls-tree recursive' \
63 'git ls-tree -r $tree >current &&
64 make_expected <<\EOF &&
65 100644 blob X path0
66 120000 blob X path1
67 100644 blob X path2/baz/b
68 120000 blob X path2/bazbo
69 100644 blob X path2/foo
70 EOF
71 test_output'
72
73 test_expect_success \
74 'ls-tree recursive with -t' \
75 'git ls-tree -r -t $tree >current &&
76 make_expected <<\EOF &&
77 100644 blob X path0
78 120000 blob X path1
79 040000 tree X path2
80 040000 tree X path2/baz
81 100644 blob X path2/baz/b
82 120000 blob X path2/bazbo
83 100644 blob X path2/foo
84 EOF
85 test_output'
86
87 test_expect_success \
88 'ls-tree recursive with -d' \
89 'git ls-tree -r -d $tree >current &&
90 make_expected <<\EOF &&
91 040000 tree X path2
92 040000 tree X path2/baz
93 EOF
94 test_output'
95
96 test_expect_success \
97 'ls-tree filtered with path' \
98 'git ls-tree $tree path >current &&
99 make_expected <<\EOF &&
100 EOF
101 test_output'
102
103
104 # it used to be path1 and then path0, but with pathspec semantics
105 # they are shown in canonical order.
106 test_expect_success \
107 'ls-tree filtered with path1 path0' \
108 'git ls-tree $tree path1 path0 >current &&
109 make_expected <<\EOF &&
110 100644 blob X path0
111 120000 blob X path1
112 EOF
113 test_output'
114
115 test_expect_success \
116 'ls-tree filtered with path0/' \
117 'git ls-tree $tree path0/ >current &&
118 make_expected <<\EOF &&
119 EOF
120 test_output'
121
122 # It used to show path2 and its immediate children but
123 # with pathspec semantics it shows only path2
124 test_expect_success \
125 'ls-tree filtered with path2' \
126 'git ls-tree $tree path2 >current &&
127 make_expected <<\EOF &&
128 040000 tree X path2
129 EOF
130 test_output'
131
132 # ... and path2/ shows the children.
133 test_expect_success \
134 'ls-tree filtered with path2/' \
135 'git ls-tree $tree path2/ >current &&
136 make_expected <<\EOF &&
137 040000 tree X path2/baz
138 120000 blob X path2/bazbo
139 100644 blob X path2/foo
140 EOF
141 test_output'
142
143 # The same change -- exact match does not show children of
144 # path2/baz
145 test_expect_success \
146 'ls-tree filtered with path2/baz' \
147 'git ls-tree $tree path2/baz >current &&
148 make_expected <<\EOF &&
149 040000 tree X path2/baz
150 EOF
151 test_output'
152
153 test_expect_success \
154 'ls-tree filtered with path2/bak' \
155 'git ls-tree $tree path2/bak >current &&
156 make_expected <<\EOF &&
157 EOF
158 test_output'
159
160 test_expect_success \
161 'ls-tree -t filtered with path2/bak' \
162 'git ls-tree -t $tree path2/bak >current &&
163 make_expected <<\EOF &&
164 040000 tree X path2
165 EOF
166 test_output'
167
168 test_expect_success \
169 'ls-tree with one path a prefix of the other' \
170 'git ls-tree $tree path2/baz path2/bazbo >current &&
171 make_expected <<\EOF &&
172 040000 tree X path2/baz
173 120000 blob X path2/bazbo
174 EOF
175 test_output'
176
177 test_done