]>
Commit | Line | Data |
---|---|---|
6d3a5077 JM |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git ls-tree test. |
6d3a5077 | 7 | |
5be60078 | 8 | This test runs git ls-tree with the following in a tree. |
6d3a5077 JM |
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 | |
66204988 | 17 | path2/baz. Also path0/ should snow nothing. |
6d3a5077 JM |
18 | ' |
19 | . ./test-lib.sh | |
20 | ||
21 | test_expect_success \ | |
22 | 'setup' \ | |
23 | 'mkdir path2 path2/baz && | |
24 | echo Hi >path0 && | |
704a3143 JS |
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 && | |
6d3a5077 | 39 | echo Lo >path2/foo && |
6d3a5077 JM |
40 | echo Mi >path2/baz/b && |
41 | find path? \( -type f -o -type l \) -print | | |
5be60078 JH |
42 | xargs git update-index --add && |
43 | tree=`git write-tree` && | |
6d3a5077 JM |
44 | echo $tree' |
45 | ||
6d3a5077 | 46 | test_output () { |
2eab945e | 47 | sed -e "s/ $_x40 / X /" <current >check |
3af82863 | 48 | test_cmp expected check |
6d3a5077 JM |
49 | } |
50 | ||
51 | test_expect_success \ | |
52 | 'ls-tree plain' \ | |
5be60078 | 53 | 'git ls-tree $tree >current && |
704a3143 | 54 | make_expected <<\EOF && |
2eab945e JH |
55 | 100644 blob X path0 |
56 | 120000 blob X path1 | |
57 | 040000 tree X path2 | |
6d3a5077 JM |
58 | EOF |
59 | test_output' | |
60 | ||
61 | test_expect_success \ | |
62 | 'ls-tree recursive' \ | |
5be60078 | 63 | 'git ls-tree -r $tree >current && |
704a3143 | 64 | make_expected <<\EOF && |
2eab945e JH |
65 | 100644 blob X path0 |
66 | 120000 blob X path1 | |
2eab945e JH |
67 | 100644 blob X path2/baz/b |
68 | 120000 blob X path2/bazbo | |
69 | 100644 blob X path2/foo | |
6d3a5077 JM |
70 | EOF |
71 | test_output' | |
72 | ||
57ae0d09 JH |
73 | test_expect_success \ |
74 | 'ls-tree recursive with -t' \ | |
5be60078 | 75 | 'git ls-tree -r -t $tree >current && |
704a3143 | 76 | make_expected <<\EOF && |
57ae0d09 JH |
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' \ | |
5be60078 | 89 | 'git ls-tree -r -d $tree >current && |
704a3143 | 90 | make_expected <<\EOF && |
57ae0d09 JH |
91 | 040000 tree X path2 |
92 | 040000 tree X path2/baz | |
93 | EOF | |
94 | test_output' | |
95 | ||
6d3a5077 | 96 | test_expect_success \ |
66204988 | 97 | 'ls-tree filtered with path' \ |
5be60078 | 98 | 'git ls-tree $tree path >current && |
704a3143 | 99 | make_expected <<\EOF && |
6d3a5077 JM |
100 | EOF |
101 | test_output' | |
102 | ||
103 | ||
246cc52f JH |
104 | # it used to be path1 and then path0, but with pathspec semantics |
105 | # they are shown in canonical order. | |
6d3a5077 | 106 | test_expect_success \ |
66204988 | 107 | 'ls-tree filtered with path1 path0' \ |
5be60078 | 108 | 'git ls-tree $tree path1 path0 >current && |
704a3143 | 109 | make_expected <<\EOF && |
6af1f019 | 110 | 100644 blob X path0 |
246cc52f | 111 | 120000 blob X path1 |
6d3a5077 JM |
112 | EOF |
113 | test_output' | |
114 | ||
115 | test_expect_success \ | |
66204988 | 116 | 'ls-tree filtered with path0/' \ |
5be60078 | 117 | 'git ls-tree $tree path0/ >current && |
704a3143 | 118 | make_expected <<\EOF && |
66204988 JH |
119 | EOF |
120 | test_output' | |
121 | ||
246cc52f JH |
122 | # It used to show path2 and its immediate children but |
123 | # with pathspec semantics it shows only path2 | |
66204988 JH |
124 | test_expect_success \ |
125 | 'ls-tree filtered with path2' \ | |
5be60078 | 126 | 'git ls-tree $tree path2 >current && |
704a3143 | 127 | make_expected <<\EOF && |
2eab945e | 128 | 040000 tree X path2 |
6d3a5077 JM |
129 | EOF |
130 | test_output' | |
131 | ||
246cc52f | 132 | # ... and path2/ shows the children. |
66204988 | 133 | test_expect_success \ |
246cc52f | 134 | 'ls-tree filtered with path2/' \ |
5be60078 | 135 | 'git ls-tree $tree path2/ >current && |
704a3143 | 136 | make_expected <<\EOF && |
66204988 JH |
137 | 040000 tree X path2/baz |
138 | 120000 blob X path2/bazbo | |
139 | 100644 blob X path2/foo | |
140 | EOF | |
141 | test_output' | |
142 | ||
246cc52f JH |
143 | # The same change -- exact match does not show children of |
144 | # path2/baz | |
66204988 | 145 | test_expect_success \ |
246cc52f | 146 | 'ls-tree filtered with path2/baz' \ |
5be60078 | 147 | 'git ls-tree $tree path2/baz >current && |
704a3143 | 148 | make_expected <<\EOF && |
66204988 | 149 | 040000 tree X path2/baz |
66204988 JH |
150 | EOF |
151 | test_output' | |
152 | ||
57ae0d09 JH |
153 | test_expect_success \ |
154 | 'ls-tree filtered with path2/bak' \ | |
5be60078 | 155 | 'git ls-tree $tree path2/bak >current && |
704a3143 | 156 | make_expected <<\EOF && |
57ae0d09 JH |
157 | EOF |
158 | test_output' | |
159 | ||
160 | test_expect_success \ | |
161 | 'ls-tree -t filtered with path2/bak' \ | |
5be60078 | 162 | 'git ls-tree -t $tree path2/bak >current && |
704a3143 | 163 | make_expected <<\EOF && |
57ae0d09 JH |
164 | 040000 tree X path2 |
165 | EOF | |
166 | test_output' | |
167 | ||
b294ed63 JH |
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 | ||
6d3a5077 | 177 | test_done |