]>
Commit | Line | Data |
---|---|---|
368f99d5 JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
d8083e41 | 6 | test_description='basic tests for ls-files --others |
368f99d5 | 7 | |
5be60078 | 8 | This test runs git ls-files --others with the following on the |
368f99d5 JH |
9 | filesystem. |
10 | ||
11 | path0 - a file | |
12 | path1 - a symlink | |
13 | path2/file2 - a file in a directory | |
78c2cff6 JH |
14 | path3-junk - a file to confuse things |
15 | path3/file3 - a file in a directory | |
2fb6d6d6 | 16 | path4 - an empty directory |
368f99d5 JH |
17 | ' |
18 | . ./test-lib.sh | |
19 | ||
bcefed41 JN |
20 | test_expect_success 'setup ' ' |
21 | date >path0 && | |
22 | if test_have_prereq SYMLINKS | |
23 | then | |
24 | ln -s xyzzy path1 | |
25 | else | |
26 | date >path1 | |
27 | fi && | |
28 | mkdir path2 path3 path4 && | |
29 | date >path2/file2 && | |
30 | date >path2-junk && | |
31 | date >path3/file3 && | |
32 | date >path3-junk && | |
33 | git update-index --add path3-junk path3/file3 | |
34 | ' | |
78c2cff6 | 35 | |
bcefed41 JN |
36 | test_expect_success 'setup: expected output' ' |
37 | cat >expected1 <<-\EOF && | |
38 | expected1 | |
39 | expected2 | |
40 | expected3 | |
41 | output | |
42 | path0 | |
43 | path1 | |
44 | path2-junk | |
45 | path2/file2 | |
46 | EOF | |
78c2cff6 | 47 | |
bcefed41 JN |
48 | sed -e "s|path2/file2|path2/|" <expected1 >expected2 && |
49 | cp expected2 expected3 && | |
50 | echo path4/ >>expected2 | |
51 | ' | |
78c2cff6 | 52 | |
bcefed41 JN |
53 | test_expect_success 'ls-files --others' ' |
54 | git ls-files --others >output && | |
55 | test_cmp expected1 output | |
56 | ' | |
78c2cff6 | 57 | |
bcefed41 JN |
58 | test_expect_success 'ls-files --others --directory' ' |
59 | git ls-files --others --directory >output && | |
60 | test_cmp expected2 output | |
61 | ' | |
2fb6d6d6 | 62 | |
bcefed41 JN |
63 | test_expect_success '--no-empty-directory hides empty directory' ' |
64 | git ls-files --others --directory --no-empty-directory >output && | |
65 | test_cmp expected3 output | |
66 | ' | |
2fb6d6d6 | 67 | |
a2d5156c JK |
68 | test_expect_success 'ls-files --others handles non-submodule .git' ' |
69 | mkdir not-a-submodule && | |
70 | echo foo >not-a-submodule/.git && | |
71 | git ls-files -o >output && | |
72 | test_cmp expected1 output | |
73 | ' | |
74 | ||
e5fa45c1 JH |
75 | test_expect_success SYMLINKS 'ls-files --others with symlinked submodule' ' |
76 | git init super && | |
77 | git init sub && | |
78 | ( | |
79 | cd sub && | |
80 | >a && | |
81 | git add a && | |
82 | git commit -m sub && | |
83 | git pack-refs --all | |
84 | ) && | |
85 | ( | |
86 | cd super && | |
3ea67379 | 87 | "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub && |
e5fa45c1 JH |
88 | git ls-files --others --exclude-standard >../actual |
89 | ) && | |
90 | echo sub/ >expect && | |
91 | test_cmp expect actual | |
92 | ' | |
93 | ||
7260c7b6 EN |
94 | test_expect_success 'setup nested pathspec search' ' |
95 | test_create_repo nested && | |
96 | ( | |
97 | cd nested && | |
98 | ||
99 | mkdir -p partially_tracked/untracked_dir && | |
100 | > partially_tracked/content && | |
101 | > partially_tracked/untracked_dir/file && | |
102 | ||
103 | mkdir -p untracked/deep && | |
104 | > untracked/deep/path && | |
105 | > untracked/deep/foo.c && | |
106 | ||
107 | git add partially_tracked/content | |
108 | ) | |
109 | ' | |
110 | ||
111 | test_expect_success 'ls-files -o --directory with single deep dir pathspec' ' | |
112 | ( | |
113 | cd nested && | |
114 | ||
115 | git ls-files -o --directory untracked/deep/ >actual && | |
116 | ||
117 | cat <<-EOF >expect && | |
118 | untracked/deep/ | |
119 | EOF | |
120 | ||
121 | test_cmp expect actual | |
122 | ) | |
123 | ' | |
124 | ||
125 | test_expect_success 'ls-files -o --directory with multiple dir pathspecs' ' | |
126 | ( | |
127 | cd nested && | |
128 | ||
129 | git ls-files -o --directory partially_tracked/ untracked/ >actual && | |
130 | ||
131 | cat <<-EOF >expect && | |
132 | partially_tracked/untracked_dir/ | |
133 | untracked/ | |
134 | EOF | |
135 | ||
136 | test_cmp expect actual | |
137 | ) | |
138 | ' | |
139 | ||
140 | test_expect_success 'ls-files -o --directory with mix dir/file pathspecs' ' | |
141 | ( | |
142 | cd nested && | |
143 | ||
144 | git ls-files -o --directory partially_tracked/ untracked/deep/path >actual && | |
145 | ||
146 | cat <<-EOF >expect && | |
147 | partially_tracked/untracked_dir/ | |
148 | untracked/deep/path | |
149 | EOF | |
150 | ||
151 | test_cmp expect actual | |
152 | ) | |
153 | ' | |
154 | ||
ed8268da | 155 | test_expect_success 'ls-files -o --directory with glob filetype match' ' |
7260c7b6 EN |
156 | ( |
157 | cd nested && | |
158 | ||
159 | # globs kinda defeat --directory, but only for that pathspec | |
160 | git ls-files --others --directory partially_tracked "untracked/*.c" >actual && | |
161 | ||
162 | cat <<-EOF >expect && | |
163 | partially_tracked/untracked_dir/ | |
164 | untracked/deep/foo.c | |
165 | EOF | |
166 | ||
167 | test_cmp expect actual | |
168 | ) | |
169 | ' | |
170 | ||
ed8268da | 171 | test_expect_success 'ls-files -o --directory with mix of tracked states' ' |
7260c7b6 EN |
172 | ( |
173 | cd nested && | |
174 | ||
175 | # globs kinda defeat --directory, but only for that pathspec | |
176 | git ls-files --others --directory partially_tracked/ "untracked/?*" >actual && | |
177 | ||
178 | cat <<-EOF >expect && | |
179 | partially_tracked/untracked_dir/ | |
180 | untracked/deep/ | |
181 | EOF | |
182 | ||
183 | test_cmp expect actual | |
184 | ) | |
185 | ' | |
186 | ||
ed8268da | 187 | test_expect_success 'ls-files -o --directory with glob filetype match only' ' |
7260c7b6 EN |
188 | ( |
189 | cd nested && | |
190 | ||
191 | git ls-files --others --directory "untracked/*.c" >actual && | |
192 | ||
193 | cat <<-EOF >expect && | |
194 | untracked/deep/foo.c | |
195 | EOF | |
196 | ||
197 | test_cmp expect actual | |
198 | ) | |
199 | ' | |
200 | ||
ed8268da | 201 | test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' ' |
7260c7b6 EN |
202 | ( |
203 | cd nested && | |
204 | ||
205 | git ls-files --others --directory "untracked/?*" >actual && | |
206 | ||
207 | cat <<-EOF >expect && | |
208 | untracked/deep/ | |
209 | EOF | |
210 | ||
211 | test_cmp expect actual | |
212 | ) | |
213 | ' | |
214 | ||
ab282aa5 EN |
215 | test_expect_success 'ls-files -o avoids listing untracked non-matching gitdir' ' |
216 | test_when_finished "rm -rf nested/untracked/deep/empty" && | |
217 | ( | |
218 | cd nested && | |
219 | ||
220 | git init untracked/deep/empty && | |
221 | git ls-files --others "untracked/*.c" >actual && | |
222 | ||
223 | cat <<-EOF >expect && | |
224 | untracked/deep/foo.c | |
225 | EOF | |
226 | ||
227 | test_cmp expect actual | |
228 | ) | |
229 | ' | |
230 | ||
368f99d5 | 231 | test_done |