]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3000-ls-files-others.sh
The twentieth batch
[thirdparty/git.git] / t / t3000-ls-files-others.sh
CommitLineData
368f99d5
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
d8083e41 6test_description='basic tests for ls-files --others
368f99d5 7
5be60078 8This test runs git ls-files --others with the following on the
368f99d5
JH
9filesystem.
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 17'
0b3481c9
ÆAB
18
19TEST_PASSES_SANITIZE_LEAK=true
368f99d5
JH
20. ./test-lib.sh
21
bcefed41
JN
22test_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'
78c2cff6 37
bcefed41
JN
38test_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
78c2cff6 49
bcefed41
JN
50 sed -e "s|path2/file2|path2/|" <expected1 >expected2 &&
51 cp expected2 expected3 &&
52 echo path4/ >>expected2
53'
78c2cff6 54
bcefed41
JN
55test_expect_success 'ls-files --others' '
56 git ls-files --others >output &&
57 test_cmp expected1 output
58'
78c2cff6 59
bcefed41
JN
60test_expect_success 'ls-files --others --directory' '
61 git ls-files --others --directory >output &&
62 test_cmp expected2 output
63'
2fb6d6d6 64
bcefed41
JN
65test_expect_success '--no-empty-directory hides empty directory' '
66 git ls-files --others --directory --no-empty-directory >output &&
67 test_cmp expected3 output
68'
2fb6d6d6 69
a2d5156c
JK
70test_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
e5fa45c1
JH
77test_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 &&
3ea67379 89 "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub &&
e5fa45c1
JH
90 git ls-files --others --exclude-standard >../actual
91 ) &&
92 echo sub/ >expect &&
93 test_cmp expect actual
94'
95
7260c7b6
EN
96test_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
113test_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
127test_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
142test_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
ed8268da 157test_expect_success 'ls-files -o --directory with glob filetype match' '
7260c7b6
EN
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
ed8268da 173test_expect_success 'ls-files -o --directory with mix of tracked states' '
7260c7b6
EN
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
ed8268da 189test_expect_success 'ls-files -o --directory with glob filetype match only' '
7260c7b6
EN
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
ed8268da 203test_expect_success 'ls-files -o --directory to get immediate paths under one dir only' '
7260c7b6
EN
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
ab282aa5
EN
217test_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
368f99d5 233test_done