]>
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 | 18 | ' |
809aeedb ÆAB |
19 | |
20 | TEST_PASSES_SANITIZE_LEAK=true | |
6d3a5077 JM |
21 | . ./test-lib.sh |
22 | ||
23 | test_expect_success \ | |
24 | 'setup' \ | |
25 | 'mkdir path2 path2/baz && | |
26 | echo Hi >path0 && | |
e40db07f JS |
27 | test_ln_s_add path0 path1 && |
28 | test_ln_s_add ../path1 path2/bazbo && | |
6d3a5077 | 29 | echo Lo >path2/foo && |
6d3a5077 JM |
30 | echo Mi >path2/baz/b && |
31 | find path? \( -type f -o -type l \) -print | | |
5be60078 | 32 | xargs git update-index --add && |
10c1e855 | 33 | tree=$(git write-tree) && |
6d3a5077 JM |
34 | echo $tree' |
35 | ||
6d3a5077 | 36 | test_output () { |
2ece6ad2 | 37 | sed -e "s/ $OID_REGEX / X /" <current >check |
3af82863 | 38 | test_cmp expected check |
6d3a5077 JM |
39 | } |
40 | ||
41 | test_expect_success \ | |
42 | 'ls-tree plain' \ | |
5be60078 | 43 | 'git ls-tree $tree >current && |
e40db07f | 44 | cat >expected <<\EOF && |
2eab945e JH |
45 | 100644 blob X path0 |
46 | 120000 blob X path1 | |
47 | 040000 tree X path2 | |
6d3a5077 JM |
48 | EOF |
49 | test_output' | |
50 | ||
51 | test_expect_success \ | |
52 | 'ls-tree recursive' \ | |
5be60078 | 53 | 'git ls-tree -r $tree >current && |
e40db07f | 54 | cat >expected <<\EOF && |
2eab945e JH |
55 | 100644 blob X path0 |
56 | 120000 blob X path1 | |
2eab945e JH |
57 | 100644 blob X path2/baz/b |
58 | 120000 blob X path2/bazbo | |
59 | 100644 blob X path2/foo | |
6d3a5077 JM |
60 | EOF |
61 | test_output' | |
62 | ||
57ae0d09 JH |
63 | test_expect_success \ |
64 | 'ls-tree recursive with -t' \ | |
5be60078 | 65 | 'git ls-tree -r -t $tree >current && |
e40db07f | 66 | cat >expected <<\EOF && |
57ae0d09 JH |
67 | 100644 blob X path0 |
68 | 120000 blob X path1 | |
69 | 040000 tree X path2 | |
70 | 040000 tree X path2/baz | |
71 | 100644 blob X path2/baz/b | |
72 | 120000 blob X path2/bazbo | |
73 | 100644 blob X path2/foo | |
74 | EOF | |
75 | test_output' | |
76 | ||
77 | test_expect_success \ | |
78 | 'ls-tree recursive with -d' \ | |
5be60078 | 79 | 'git ls-tree -r -d $tree >current && |
e40db07f | 80 | cat >expected <<\EOF && |
57ae0d09 JH |
81 | 040000 tree X path2 |
82 | 040000 tree X path2/baz | |
83 | EOF | |
84 | test_output' | |
85 | ||
6d3a5077 | 86 | test_expect_success \ |
66204988 | 87 | 'ls-tree filtered with path' \ |
5be60078 | 88 | 'git ls-tree $tree path >current && |
e40db07f | 89 | cat >expected <<\EOF && |
6d3a5077 JM |
90 | EOF |
91 | test_output' | |
92 | ||
93 | ||
246cc52f JH |
94 | # it used to be path1 and then path0, but with pathspec semantics |
95 | # they are shown in canonical order. | |
6d3a5077 | 96 | test_expect_success \ |
66204988 | 97 | 'ls-tree filtered with path1 path0' \ |
5be60078 | 98 | 'git ls-tree $tree path1 path0 >current && |
e40db07f | 99 | cat >expected <<\EOF && |
6af1f019 | 100 | 100644 blob X path0 |
246cc52f | 101 | 120000 blob X path1 |
6d3a5077 JM |
102 | EOF |
103 | test_output' | |
104 | ||
105 | test_expect_success \ | |
66204988 | 106 | 'ls-tree filtered with path0/' \ |
5be60078 | 107 | 'git ls-tree $tree path0/ >current && |
e40db07f | 108 | cat >expected <<\EOF && |
66204988 JH |
109 | EOF |
110 | test_output' | |
111 | ||
246cc52f JH |
112 | # It used to show path2 and its immediate children but |
113 | # with pathspec semantics it shows only path2 | |
66204988 JH |
114 | test_expect_success \ |
115 | 'ls-tree filtered with path2' \ | |
5be60078 | 116 | 'git ls-tree $tree path2 >current && |
e40db07f | 117 | cat >expected <<\EOF && |
2eab945e | 118 | 040000 tree X path2 |
6d3a5077 JM |
119 | EOF |
120 | test_output' | |
121 | ||
246cc52f | 122 | # ... and path2/ shows the children. |
66204988 | 123 | test_expect_success \ |
246cc52f | 124 | 'ls-tree filtered with path2/' \ |
5be60078 | 125 | 'git ls-tree $tree path2/ >current && |
e40db07f | 126 | cat >expected <<\EOF && |
66204988 JH |
127 | 040000 tree X path2/baz |
128 | 120000 blob X path2/bazbo | |
129 | 100644 blob X path2/foo | |
130 | EOF | |
131 | test_output' | |
132 | ||
246cc52f JH |
133 | # The same change -- exact match does not show children of |
134 | # path2/baz | |
66204988 | 135 | test_expect_success \ |
246cc52f | 136 | 'ls-tree filtered with path2/baz' \ |
5be60078 | 137 | 'git ls-tree $tree path2/baz >current && |
e40db07f | 138 | cat >expected <<\EOF && |
66204988 | 139 | 040000 tree X path2/baz |
66204988 JH |
140 | EOF |
141 | test_output' | |
142 | ||
57ae0d09 JH |
143 | test_expect_success \ |
144 | 'ls-tree filtered with path2/bak' \ | |
5be60078 | 145 | 'git ls-tree $tree path2/bak >current && |
e40db07f | 146 | cat >expected <<\EOF && |
57ae0d09 JH |
147 | EOF |
148 | test_output' | |
149 | ||
150 | test_expect_success \ | |
151 | 'ls-tree -t filtered with path2/bak' \ | |
5be60078 | 152 | 'git ls-tree -t $tree path2/bak >current && |
e40db07f | 153 | cat >expected <<\EOF && |
57ae0d09 JH |
154 | 040000 tree X path2 |
155 | EOF | |
156 | test_output' | |
157 | ||
b294ed63 JH |
158 | test_expect_success \ |
159 | 'ls-tree with one path a prefix of the other' \ | |
160 | 'git ls-tree $tree path2/baz path2/bazbo >current && | |
e40db07f | 161 | cat >expected <<\EOF && |
b294ed63 JH |
162 | 040000 tree X path2/baz |
163 | 120000 blob X path2/bazbo | |
164 | EOF | |
165 | test_output' | |
166 | ||
6d3a5077 | 167 | test_done |