Implement the rmdir_or_warn function
[git/jnareb-git.git] / t / t7300-clean.sh
blob7d8ed68befed0e85ad85f9f933a2b887125e38e8
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 with skip-worktree .gitignore' '
26 git update-index --skip-worktree .gitignore &&
27 rm .gitignore &&
28 mkdir -p build docs &&
29 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
30 git clean &&
31 test -f Makefile &&
32 test -f README &&
33 test -f src/part1.c &&
34 test -f src/part2.c &&
35 test ! -f a.out &&
36 test ! -f src/part3.c &&
37 test -f docs/manual.txt &&
38 test -f obj.o &&
39 test -f build/lib.so &&
40 git update-index --no-skip-worktree .gitignore &&
41 git checkout .gitignore
44 test_expect_success 'git clean' '
46 mkdir -p build docs &&
47 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
48 git clean &&
49 test -f Makefile &&
50 test -f README &&
51 test -f src/part1.c &&
52 test -f src/part2.c &&
53 test ! -f a.out &&
54 test ! -f src/part3.c &&
55 test -f docs/manual.txt &&
56 test -f obj.o &&
57 test -f build/lib.so
61 test_expect_success 'git clean src/' '
63 mkdir -p build docs &&
64 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
65 git clean src/ &&
66 test -f Makefile &&
67 test -f README &&
68 test -f src/part1.c &&
69 test -f src/part2.c &&
70 test -f a.out &&
71 test ! -f src/part3.c &&
72 test -f docs/manual.txt &&
73 test -f obj.o &&
74 test -f build/lib.so
78 test_expect_success 'git clean src/ src/' '
80 mkdir -p build docs &&
81 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
82 git clean src/ src/ &&
83 test -f Makefile &&
84 test -f README &&
85 test -f src/part1.c &&
86 test -f src/part2.c &&
87 test -f a.out &&
88 test ! -f src/part3.c &&
89 test -f docs/manual.txt &&
90 test -f obj.o &&
91 test -f build/lib.so
95 test_expect_success 'git clean with prefix' '
97 mkdir -p build docs src/test &&
98 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c &&
99 (cd src/ && git clean) &&
100 test -f Makefile &&
101 test -f README &&
102 test -f src/part1.c &&
103 test -f src/part2.c &&
104 test -f a.out &&
105 test ! -f src/part3.c &&
106 test -f src/test/1.c &&
107 test -f docs/manual.txt &&
108 test -f obj.o &&
109 test -f build/lib.so
113 test_expect_success 'git clean with relative prefix' '
115 mkdir -p build docs &&
116 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
117 would_clean=$(
118 cd docs &&
119 git clean -n ../src |
120 sed -n -e "s|^Would remove ||p"
121 ) &&
122 test "$would_clean" = ../src/part3.c || {
123 echo "OOps <$would_clean>"
124 false
128 test_expect_success 'git clean with absolute path' '
130 mkdir -p build docs &&
131 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
132 would_clean=$(
133 cd docs &&
134 git clean -n "$(pwd)/../src" |
135 sed -n -e "s|^Would remove ||p"
136 ) &&
137 test "$would_clean" = ../src/part3.c || {
138 echo "OOps <$would_clean>"
139 false
143 test_expect_success 'git clean with out of work tree relative path' '
145 mkdir -p build docs &&
146 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
148 cd docs &&
149 test_must_fail git clean -n ../..
153 test_expect_success 'git clean with out of work tree absolute path' '
155 mkdir -p build docs &&
156 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
157 dd=$(cd .. && pwd) &&
159 cd docs &&
160 test_must_fail git clean -n $dd
164 test_expect_success 'git clean -d with prefix and path' '
166 mkdir -p build docs src/feature &&
167 touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
168 (cd src/ && git clean -d feature/) &&
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/feature/file.c &&
176 test -f docs/manual.txt &&
177 test -f obj.o &&
178 test -f build/lib.so
182 test_expect_success 'git clean symbolic link' '
184 mkdir -p build docs &&
185 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
186 ln -s docs/manual.txt src/part4.c
187 git clean &&
188 test -f Makefile &&
189 test -f README &&
190 test -f src/part1.c &&
191 test -f src/part2.c &&
192 test ! -f a.out &&
193 test ! -f src/part3.c &&
194 test ! -f src/part4.c &&
195 test -f docs/manual.txt &&
196 test -f obj.o &&
197 test -f build/lib.so
201 test_expect_success 'git clean with wildcard' '
203 touch a.clean b.clean other.c &&
204 git clean "*.clean" &&
205 test -f Makefile &&
206 test -f README &&
207 test -f src/part1.c &&
208 test -f src/part2.c &&
209 test ! -f a.clean &&
210 test ! -f b.clean &&
211 test -f other.c
215 test_expect_success 'git clean -n' '
217 mkdir -p build docs &&
218 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
219 git clean -n &&
220 test -f Makefile &&
221 test -f README &&
222 test -f src/part1.c &&
223 test -f src/part2.c &&
224 test -f a.out &&
225 test -f src/part3.c &&
226 test -f docs/manual.txt &&
227 test -f obj.o &&
228 test -f build/lib.so
232 test_expect_success 'git clean -d' '
234 mkdir -p build docs &&
235 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
236 git clean -d &&
237 test -f Makefile &&
238 test -f README &&
239 test -f src/part1.c &&
240 test -f src/part2.c &&
241 test ! -f a.out &&
242 test ! -f src/part3.c &&
243 test ! -d docs &&
244 test -f obj.o &&
245 test -f build/lib.so
249 test_expect_success 'git clean -d src/ examples/' '
251 mkdir -p build docs examples &&
252 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
253 git clean -d src/ examples/ &&
254 test -f Makefile &&
255 test -f README &&
256 test -f src/part1.c &&
257 test -f src/part2.c &&
258 test -f a.out &&
259 test ! -f src/part3.c &&
260 test ! -f examples/1.c &&
261 test -f docs/manual.txt &&
262 test -f obj.o &&
263 test -f build/lib.so
267 test_expect_success 'git clean -x' '
269 mkdir -p build docs &&
270 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
271 git clean -x &&
272 test -f Makefile &&
273 test -f README &&
274 test -f src/part1.c &&
275 test -f src/part2.c &&
276 test ! -f a.out &&
277 test ! -f src/part3.c &&
278 test -f docs/manual.txt &&
279 test ! -f obj.o &&
280 test -f build/lib.so
284 test_expect_success 'git clean -d -x' '
286 mkdir -p build docs &&
287 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
288 git clean -d -x &&
289 test -f Makefile &&
290 test -f README &&
291 test -f src/part1.c &&
292 test -f src/part2.c &&
293 test ! -f a.out &&
294 test ! -f src/part3.c &&
295 test ! -d docs &&
296 test ! -f obj.o &&
297 test ! -d build
301 test_expect_success 'git clean -X' '
303 mkdir -p build docs &&
304 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
305 git clean -X &&
306 test -f Makefile &&
307 test -f README &&
308 test -f src/part1.c &&
309 test -f src/part2.c &&
310 test -f a.out &&
311 test -f src/part3.c &&
312 test -f docs/manual.txt &&
313 test ! -f obj.o &&
314 test -f build/lib.so
318 test_expect_success 'git clean -d -X' '
320 mkdir -p build docs &&
321 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
322 git clean -d -X &&
323 test -f Makefile &&
324 test -f README &&
325 test -f src/part1.c &&
326 test -f src/part2.c &&
327 test -f a.out &&
328 test -f src/part3.c &&
329 test -f docs/manual.txt &&
330 test ! -f obj.o &&
331 test ! -d build
335 test_expect_success 'clean.requireForce defaults to true' '
337 git config --unset clean.requireForce &&
338 test_must_fail git clean
342 test_expect_success 'clean.requireForce' '
344 git config clean.requireForce true &&
345 test_must_fail git clean
349 test_expect_success 'clean.requireForce and -n' '
351 mkdir -p build docs &&
352 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
353 git clean -n &&
354 test -f Makefile &&
355 test -f README &&
356 test -f src/part1.c &&
357 test -f src/part2.c &&
358 test -f a.out &&
359 test -f src/part3.c &&
360 test -f docs/manual.txt &&
361 test -f obj.o &&
362 test -f build/lib.so
366 test_expect_success 'clean.requireForce and -f' '
368 git clean -f &&
369 test -f README &&
370 test -f src/part1.c &&
371 test -f src/part2.c &&
372 test ! -f a.out &&
373 test ! -f src/part3.c &&
374 test -f docs/manual.txt &&
375 test -f obj.o &&
376 test -f build/lib.so
380 test_expect_success 'core.excludesfile' '
382 echo excludes >excludes &&
383 echo included >included &&
384 git config core.excludesfile excludes &&
385 output=$(git clean -n excludes included 2>&1) &&
386 expr "$output" : ".*included" >/dev/null &&
387 ! expr "$output" : ".*excludes" >/dev/null
391 test_expect_success 'removal failure' '
393 mkdir foo &&
394 touch foo/bar &&
395 (exec <foo/bar &&
396 chmod 0 foo &&
397 test_must_fail git clean -f -d)
400 chmod 755 foo
402 test_expect_success 'nested git work tree' '
403 rm -fr foo bar &&
404 mkdir foo bar &&
406 cd foo &&
407 git init &&
408 >hello.world
409 git add . &&
410 git commit -a -m nested
411 ) &&
413 cd bar &&
414 >goodbye.people
415 ) &&
416 git clean -f -d &&
417 test -f foo/.git/index &&
418 test -f foo/hello.world &&
419 ! test -d bar
422 test_expect_success 'force removal of nested git work tree' '
423 rm -fr foo bar &&
424 mkdir foo bar &&
426 cd foo &&
427 git init &&
428 >hello.world
429 git add . &&
430 git commit -a -m nested
431 ) &&
433 cd bar &&
434 >goodbye.people
435 ) &&
436 git clean -f -f -d &&
437 ! test -d foo &&
438 ! test -d bar
441 test_done