]>
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 | ||
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 () { | |
2eab945e | 49 | sed -e "s/ $_x40 / X /" <current >check |
3af82863 | 50 | test_cmp expected check |
6d3a5077 JM |
51 | } |
52 | ||
53 | test_expect_success \ | |
54 | 'ls-tree plain' \ | |
5be60078 | 55 | 'git ls-tree $tree >current && |
704a3143 | 56 | make_expected <<\EOF && |
2eab945e JH |
57 | 100644 blob X path0 |
58 | 120000 blob X path1 | |
59 | 040000 tree X path2 | |
6d3a5077 JM |
60 | EOF |
61 | test_output' | |
62 | ||
63 | test_expect_success \ | |
64 | 'ls-tree recursive' \ | |
5be60078 | 65 | 'git ls-tree -r $tree >current && |
704a3143 | 66 | make_expected <<\EOF && |
2eab945e JH |
67 | 100644 blob X path0 |
68 | 120000 blob X path1 | |
2eab945e JH |
69 | 100644 blob X path2/baz/b |
70 | 120000 blob X path2/bazbo | |
71 | 100644 blob X path2/foo | |
6d3a5077 JM |
72 | EOF |
73 | test_output' | |
74 | ||
57ae0d09 JH |
75 | test_expect_success \ |
76 | 'ls-tree recursive with -t' \ | |
5be60078 | 77 | 'git ls-tree -r -t $tree >current && |
704a3143 | 78 | make_expected <<\EOF && |
57ae0d09 JH |
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' | |
88 | ||
89 | test_expect_success \ | |
90 | 'ls-tree recursive with -d' \ | |
5be60078 | 91 | 'git ls-tree -r -d $tree >current && |
704a3143 | 92 | make_expected <<\EOF && |
57ae0d09 JH |
93 | 040000 tree X path2 |
94 | 040000 tree X path2/baz | |
95 | EOF | |
96 | test_output' | |
97 | ||
6d3a5077 | 98 | test_expect_success \ |
66204988 | 99 | 'ls-tree filtered with path' \ |
5be60078 | 100 | 'git ls-tree $tree path >current && |
704a3143 | 101 | make_expected <<\EOF && |
6d3a5077 JM |
102 | EOF |
103 | test_output' | |
104 | ||
105 | ||
246cc52f JH |
106 | # it used to be path1 and then path0, but with pathspec semantics |
107 | # they are shown in canonical order. | |
6d3a5077 | 108 | test_expect_success \ |
66204988 | 109 | 'ls-tree filtered with path1 path0' \ |
5be60078 | 110 | 'git ls-tree $tree path1 path0 >current && |
704a3143 | 111 | make_expected <<\EOF && |
6af1f019 | 112 | 100644 blob X path0 |
246cc52f | 113 | 120000 blob X path1 |
6d3a5077 JM |
114 | EOF |
115 | test_output' | |
116 | ||
117 | test_expect_success \ | |
66204988 | 118 | 'ls-tree filtered with path0/' \ |
5be60078 | 119 | 'git ls-tree $tree path0/ >current && |
704a3143 | 120 | make_expected <<\EOF && |
66204988 JH |
121 | EOF |
122 | test_output' | |
123 | ||
246cc52f JH |
124 | # It used to show path2 and its immediate children but |
125 | # with pathspec semantics it shows only path2 | |
66204988 JH |
126 | test_expect_success \ |
127 | 'ls-tree filtered with path2' \ | |
5be60078 | 128 | 'git ls-tree $tree path2 >current && |
704a3143 | 129 | make_expected <<\EOF && |
2eab945e | 130 | 040000 tree X path2 |
6d3a5077 JM |
131 | EOF |
132 | test_output' | |
133 | ||
246cc52f | 134 | # ... and path2/ shows the children. |
66204988 | 135 | test_expect_success \ |
246cc52f | 136 | 'ls-tree filtered with path2/' \ |
5be60078 | 137 | 'git ls-tree $tree path2/ >current && |
704a3143 | 138 | make_expected <<\EOF && |
66204988 JH |
139 | 040000 tree X path2/baz |
140 | 120000 blob X path2/bazbo | |
141 | 100644 blob X path2/foo | |
142 | EOF | |
143 | test_output' | |
144 | ||
246cc52f JH |
145 | # The same change -- exact match does not show children of |
146 | # path2/baz | |
66204988 | 147 | test_expect_success \ |
246cc52f | 148 | 'ls-tree filtered with path2/baz' \ |
5be60078 | 149 | 'git ls-tree $tree path2/baz >current && |
704a3143 | 150 | make_expected <<\EOF && |
66204988 | 151 | 040000 tree X path2/baz |
66204988 JH |
152 | EOF |
153 | test_output' | |
154 | ||
57ae0d09 JH |
155 | test_expect_success \ |
156 | 'ls-tree filtered with path2/bak' \ | |
5be60078 | 157 | 'git ls-tree $tree path2/bak >current && |
704a3143 | 158 | make_expected <<\EOF && |
57ae0d09 JH |
159 | EOF |
160 | test_output' | |
161 | ||
162 | test_expect_success \ | |
163 | 'ls-tree -t filtered with path2/bak' \ | |
5be60078 | 164 | 'git ls-tree -t $tree path2/bak >current && |
704a3143 | 165 | make_expected <<\EOF && |
57ae0d09 JH |
166 | 040000 tree X path2 |
167 | EOF | |
168 | test_output' | |
169 | ||
6d3a5077 | 170 | test_done |