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