3 # Copyright (c) 2007 Michael Spang
6 test_description
='git clean basic tests'
10 git config clean.requireForce no
12 test_expect_success
'setup' '
15 touch src/part1.c Makefile &&
16 echo build >.gitignore &&
17 echo \*.o >>.gitignore &&
19 git commit -m setup &&
20 touch src/part2.c README &&
25 test_expect_success
'git clean with skip-worktree .gitignore' '
26 git update-index --skip-worktree .gitignore &&
28 mkdir -p build docs &&
29 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
33 test -f src/part1.c &&
34 test -f src/part2.c &&
36 test ! -f src/part3.c &&
37 test -f docs/manual.txt &&
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 &&
51 test -f src/part1.c &&
52 test -f src/part2.c &&
54 test ! -f src/part3.c &&
55 test -f docs/manual.txt &&
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 &&
68 test -f src/part1.c &&
69 test -f src/part2.c &&
71 test ! -f src/part3.c &&
72 test -f docs/manual.txt &&
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/ &&
85 test -f src/part1.c &&
86 test -f src/part2.c &&
88 test ! -f src/part3.c &&
89 test -f docs/manual.txt &&
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) &&
102 test -f src/part1.c &&
103 test -f src/part2.c &&
105 test ! -f src/part3.c &&
106 test -f src/test/1.c &&
107 test -f docs/manual.txt &&
113 test_expect_success C_LOCALE_OUTPUT
'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 &&
119 git clean -n ../src |
120 sed -n -e "s|^Would remove ||p"
122 test "$would_clean" = ../src/part3.c || {
123 echo "OOps <$would_clean>"
128 test_expect_success C_LOCALE_OUTPUT
'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 &&
134 git clean -n "$(pwd)/../src" |
135 sed -n -e "s|^Would remove ||p"
137 test "$would_clean" = ../src/part3.c || {
138 echo "OOps <$would_clean>"
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 &&
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) &&
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/) &&
171 test -f src/part1.c &&
172 test -f src/part2.c &&
174 test -f src/part3.c &&
175 test ! -f src/feature/file.c &&
176 test -f docs/manual.txt &&
182 test_expect_success SYMLINKS
'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 &&
190 test -f src/part1.c &&
191 test -f src/part2.c &&
193 test ! -f src/part3.c &&
194 test ! -f src/part4.c &&
195 test -f docs/manual.txt &&
201 test_expect_success
'git clean with wildcard' '
203 touch a.clean b.clean other.c &&
204 git clean "*.clean" &&
207 test -f src/part1.c &&
208 test -f src/part2.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 &&
222 test -f src/part1.c &&
223 test -f src/part2.c &&
225 test -f src/part3.c &&
226 test -f docs/manual.txt &&
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 &&
239 test -f src/part1.c &&
240 test -f src/part2.c &&
242 test ! -f src/part3.c &&
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/ &&
256 test -f src/part1.c &&
257 test -f src/part2.c &&
259 test ! -f src/part3.c &&
260 test ! -f examples/1.c &&
261 test -f docs/manual.txt &&
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 &&
274 test -f src/part1.c &&
275 test -f src/part2.c &&
277 test ! -f src/part3.c &&
278 test -f docs/manual.txt &&
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 &&
291 test -f src/part1.c &&
292 test -f src/part2.c &&
294 test ! -f src/part3.c &&
301 test_expect_success
'git clean -d -x with ignored tracked directory' '
303 mkdir -p build docs &&
304 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
305 git clean -d -x -e src &&
308 test -f src/part1.c &&
309 test -f src/part2.c &&
311 test -f src/part3.c &&
318 test_expect_success
'git clean -X' '
320 mkdir -p build docs &&
321 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
325 test -f src/part1.c &&
326 test -f src/part2.c &&
328 test -f src/part3.c &&
329 test -f docs/manual.txt &&
335 test_expect_success
'git clean -d -X' '
337 mkdir -p build docs &&
338 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
342 test -f src/part1.c &&
343 test -f src/part2.c &&
345 test -f src/part3.c &&
346 test -f docs/manual.txt &&
352 test_expect_success
'git clean -d -X with ignored tracked directory' '
354 mkdir -p build docs &&
355 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
356 git clean -d -X -e src &&
359 test -f src/part1.c &&
360 test -f src/part2.c &&
362 test ! -f src/part3.c &&
363 test -f docs/manual.txt &&
369 test_expect_success
'clean.requireForce defaults to true' '
371 git config --unset clean.requireForce &&
372 test_must_fail git clean
376 test_expect_success
'clean.requireForce' '
378 git config clean.requireForce true &&
379 test_must_fail git clean
383 test_expect_success
'clean.requireForce and -n' '
385 mkdir -p build docs &&
386 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
390 test -f src/part1.c &&
391 test -f src/part2.c &&
393 test -f src/part3.c &&
394 test -f docs/manual.txt &&
400 test_expect_success
'clean.requireForce and -f' '
404 test -f src/part1.c &&
405 test -f src/part2.c &&
407 test ! -f src/part3.c &&
408 test -f docs/manual.txt &&
414 test_expect_success C_LOCALE_OUTPUT
'core.excludesfile' '
416 echo excludes >excludes &&
417 echo included >included &&
418 git config core.excludesfile excludes &&
419 output=$(git clean -n excludes included 2>&1) &&
420 expr "$output" : ".*included" >/dev/null &&
421 ! expr "$output" : ".*excludes" >/dev/null
425 test_expect_success SANITY
'removal failure' '
431 test_must_fail git clean -f -d &&
435 test_expect_success
'nested git work tree' '
436 rm -fr foo bar baz &&
437 mkdir -p foo bar baz/boo &&
443 git commit -a -m nested
454 git commit -a -m deeply.nested
457 test -f foo/.git/index &&
458 test -f foo/hello.world &&
459 test -f baz/boo/.git/index &&
460 test -f baz/boo/deeper.world &&
464 test_expect_success
'force removal of nested git work tree' '
465 rm -fr foo bar baz &&
466 mkdir -p foo bar baz/boo &&
472 git commit -a -m nested
483 git commit -a -m deeply.nested
485 git clean -f -f -d &&
491 test_expect_success
'git clean -e' '
499 git clean -f -e 1 -e 2 &&
507 test_expect_success SANITY
'git clean -d with an unreadable empty directory' '
510 git clean -dfx foo &&
514 test_expect_success
'git clean -d respects pathspecs (dir is prefix of pathspec)' '
517 git clean -df foobar &&
518 test_path_is_dir foo &&
519 test_path_is_missing foobar
522 test_expect_success
'git clean -d respects pathspecs (pathspec is prefix of dir)' '
526 test_path_is_missing foo &&
527 test_path_is_dir foobar