test-lib.sh: Fix some missing path quoting
[git/mjg.git] / t / t7300-clean.sh
bloba50492f7c065d034cb344eac965d51a82cb5a599
1 #!/bin/sh
3 # Copyright (c) 2007 Michael Spang
6 test_description='git-clean basic tests'
8 . ./test-lib.sh
10 git config clean.requireForce no
12 test_expect_success 'setup' '
14 mkdir -p src &&
15 touch src/part1.c Makefile &&
16 echo build >.gitignore &&
17 echo \*.o >>.gitignore &&
18 git add . &&
19 git-commit -m setup &&
20 touch src/part2.c README &&
21 git add .
25 test_expect_success 'git-clean' '
27 mkdir -p build docs &&
28 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
29 git-clean &&
30 test -f Makefile &&
31 test -f README &&
32 test -f src/part1.c &&
33 test -f src/part2.c &&
34 test ! -f a.out &&
35 test ! -f src/part3.c &&
36 test -f docs/manual.txt &&
37 test -f obj.o &&
38 test -f build/lib.so
42 test_expect_success 'git-clean src/' '
44 mkdir -p build docs &&
45 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
46 git-clean src/ &&
47 test -f Makefile &&
48 test -f README &&
49 test -f src/part1.c &&
50 test -f src/part2.c &&
51 test -f a.out &&
52 test ! -f src/part3.c &&
53 test -f docs/manual.txt &&
54 test -f obj.o &&
55 test -f build/lib.so
59 test_expect_success 'git-clean src/ src/' '
61 mkdir -p build docs &&
62 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
63 git-clean src/ src/ &&
64 test -f Makefile &&
65 test -f README &&
66 test -f src/part1.c &&
67 test -f src/part2.c &&
68 test -f a.out &&
69 test ! -f src/part3.c &&
70 test -f docs/manual.txt &&
71 test -f obj.o &&
72 test -f build/lib.so
76 test_expect_success 'git-clean with prefix' '
78 mkdir -p build docs src/test &&
79 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c &&
80 (cd src/ && git-clean) &&
81 test -f Makefile &&
82 test -f README &&
83 test -f src/part1.c &&
84 test -f src/part2.c &&
85 test -f a.out &&
86 test ! -f src/part3.c &&
87 test -f src/test/1.c &&
88 test -f docs/manual.txt &&
89 test -f obj.o &&
90 test -f build/lib.so
94 test_expect_success 'git-clean with relative prefix' '
96 mkdir -p build docs &&
97 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
98 would_clean=$(
99 cd docs &&
100 git clean -n ../src |
101 sed -n -e "s|^Would remove ||p"
102 ) &&
103 test "$would_clean" = ../src/part3.c || {
104 echo "OOps <$would_clean>"
105 false
109 test_expect_success 'git-clean with absolute path' '
111 mkdir -p build docs &&
112 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
113 would_clean=$(
114 cd docs &&
115 git clean -n $(pwd)/../src |
116 sed -n -e "s|^Would remove ||p"
117 ) &&
118 test "$would_clean" = ../src/part3.c || {
119 echo "OOps <$would_clean>"
120 false
124 test_expect_success 'git-clean with out of work tree relative path' '
126 mkdir -p build docs &&
127 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
129 cd docs &&
130 test_must_fail git clean -n ../..
134 test_expect_success 'git-clean with out of work tree absolute path' '
136 mkdir -p build docs &&
137 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
138 dd=$(cd .. && pwd) &&
140 cd docs &&
141 test_must_fail git clean -n $dd
145 test_expect_success 'git-clean -d with prefix and path' '
147 mkdir -p build docs src/feature &&
148 touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
149 (cd src/ && git-clean -d feature/) &&
150 test -f Makefile &&
151 test -f README &&
152 test -f src/part1.c &&
153 test -f src/part2.c &&
154 test -f a.out &&
155 test -f src/part3.c &&
156 test ! -f src/feature/file.c &&
157 test -f docs/manual.txt &&
158 test -f obj.o &&
159 test -f build/lib.so
163 test_expect_success 'git-clean symbolic link' '
165 mkdir -p build docs &&
166 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
167 ln -s docs/manual.txt src/part4.c
168 git-clean &&
169 test -f Makefile &&
170 test -f README &&
171 test -f src/part1.c &&
172 test -f src/part2.c &&
173 test ! -f a.out &&
174 test ! -f src/part3.c &&
175 test ! -f src/part4.c &&
176 test -f docs/manual.txt &&
177 test -f obj.o &&
178 test -f build/lib.so
182 test_expect_success 'git-clean with wildcard' '
184 touch a.clean b.clean other.c &&
185 git-clean "*.clean" &&
186 test -f Makefile &&
187 test -f README &&
188 test -f src/part1.c &&
189 test -f src/part2.c &&
190 test ! -f a.clean &&
191 test ! -f b.clean &&
192 test -f other.c
196 test_expect_success 'git-clean -n' '
198 mkdir -p build docs &&
199 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
200 git-clean -n &&
201 test -f Makefile &&
202 test -f README &&
203 test -f src/part1.c &&
204 test -f src/part2.c &&
205 test -f a.out &&
206 test -f src/part3.c &&
207 test -f docs/manual.txt &&
208 test -f obj.o &&
209 test -f build/lib.so
213 test_expect_success 'git-clean -d' '
215 mkdir -p build docs &&
216 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
217 git-clean -d &&
218 test -f Makefile &&
219 test -f README &&
220 test -f src/part1.c &&
221 test -f src/part2.c &&
222 test ! -f a.out &&
223 test ! -f src/part3.c &&
224 test ! -d docs &&
225 test -f obj.o &&
226 test -f build/lib.so
230 test_expect_success 'git-clean -d src/ examples/' '
232 mkdir -p build docs examples &&
233 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
234 git-clean -d src/ examples/ &&
235 test -f Makefile &&
236 test -f README &&
237 test -f src/part1.c &&
238 test -f src/part2.c &&
239 test -f a.out &&
240 test ! -f src/part3.c &&
241 test ! -f examples/1.c &&
242 test -f docs/manual.txt &&
243 test -f obj.o &&
244 test -f build/lib.so
248 test_expect_success 'git-clean -x' '
250 mkdir -p build docs &&
251 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
252 git-clean -x &&
253 test -f Makefile &&
254 test -f README &&
255 test -f src/part1.c &&
256 test -f src/part2.c &&
257 test ! -f a.out &&
258 test ! -f src/part3.c &&
259 test -f docs/manual.txt &&
260 test ! -f obj.o &&
261 test -f build/lib.so
265 test_expect_success 'git-clean -d -x' '
267 mkdir -p build docs &&
268 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
269 git-clean -d -x &&
270 test -f Makefile &&
271 test -f README &&
272 test -f src/part1.c &&
273 test -f src/part2.c &&
274 test ! -f a.out &&
275 test ! -f src/part3.c &&
276 test ! -d docs &&
277 test ! -f obj.o &&
278 test ! -d build
282 test_expect_success 'git-clean -X' '
284 mkdir -p build docs &&
285 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
286 git-clean -X &&
287 test -f Makefile &&
288 test -f README &&
289 test -f src/part1.c &&
290 test -f src/part2.c &&
291 test -f a.out &&
292 test -f src/part3.c &&
293 test -f docs/manual.txt &&
294 test ! -f obj.o &&
295 test -f build/lib.so
299 test_expect_success 'git-clean -d -X' '
301 mkdir -p build docs &&
302 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
303 git-clean -d -X &&
304 test -f Makefile &&
305 test -f README &&
306 test -f src/part1.c &&
307 test -f src/part2.c &&
308 test -f a.out &&
309 test -f src/part3.c &&
310 test -f docs/manual.txt &&
311 test ! -f obj.o &&
312 test ! -d build
316 test_expect_success 'clean.requireForce defaults to true' '
318 git config --unset clean.requireForce &&
319 ! git-clean
323 test_expect_success 'clean.requireForce' '
325 git config clean.requireForce true &&
326 ! git-clean
330 test_expect_success 'clean.requireForce and -n' '
332 mkdir -p build docs &&
333 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
334 git-clean -n &&
335 test -f Makefile &&
336 test -f README &&
337 test -f src/part1.c &&
338 test -f src/part2.c &&
339 test -f a.out &&
340 test -f src/part3.c &&
341 test -f docs/manual.txt &&
342 test -f obj.o &&
343 test -f build/lib.so
347 test_expect_success 'clean.requireForce and -f' '
349 git-clean -f &&
350 test -f README &&
351 test -f src/part1.c &&
352 test -f src/part2.c &&
353 test ! -f a.out &&
354 test ! -f src/part3.c &&
355 test -f docs/manual.txt &&
356 test -f obj.o &&
357 test -f build/lib.so
361 test_expect_success 'core.excludesfile' '
363 echo excludes >excludes &&
364 echo included >included &&
365 git config core.excludesfile excludes &&
366 output=$(git clean -n excludes included 2>&1) &&
367 expr "$output" : ".*included" >/dev/null &&
368 ! expr "$output" : ".*excludes" >/dev/null
372 test_expect_success 'removal failure' '
374 mkdir foo &&
375 touch foo/bar &&
376 exec <foo/bar &&
377 chmod 0 foo &&
378 test_must_fail git clean -f -d
381 chmod 755 foo
383 test_done