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' '
27 mkdir -p build docs &&
28 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
32 test -f src/part1.c &&
33 test -f src/part2.c &&
35 test ! -f src/part3.c &&
36 test -f docs/manual.txt &&
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 &&
49 test -f src/part1.c &&
50 test -f src/part2.c &&
52 test ! -f src/part3.c &&
53 test -f docs/manual.txt &&
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/ &&
66 test -f src/part1.c &&
67 test -f src/part2.c &&
69 test ! -f src/part3.c &&
70 test -f docs/manual.txt &&
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) &&
83 test -f src/part1.c &&
84 test -f src/part2.c &&
86 test ! -f src/part3.c &&
87 test -f src/test/1.c &&
88 test -f docs/manual.txt &&
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 &&
100 git clean -n ../src |
101 sed -n -e "s|^Would remove ||p"
103 test "$would_clean" = ../src/part3.c || {
104 echo "OOps <$would_clean>"
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 &&
115 git clean -n "$(pwd)/../src" |
116 sed -n -e "s|^Would remove ||p"
118 test "$would_clean" = ../src/part3.c || {
119 echo "OOps <$would_clean>"
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 &&
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) &&
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/) &&
152 test -f src/part1.c &&
153 test -f src/part2.c &&
155 test -f src/part3.c &&
156 test ! -f src/feature/file.c &&
157 test -f docs/manual.txt &&
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
171 test -f src/part1.c &&
172 test -f src/part2.c &&
174 test ! -f src/part3.c &&
175 test ! -f src/part4.c &&
176 test -f docs/manual.txt &&
182 test_expect_success
'git clean with wildcard' '
184 touch a.clean b.clean other.c &&
185 git clean "*.clean" &&
188 test -f src/part1.c &&
189 test -f src/part2.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 &&
203 test -f src/part1.c &&
204 test -f src/part2.c &&
206 test -f src/part3.c &&
207 test -f docs/manual.txt &&
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 &&
220 test -f src/part1.c &&
221 test -f src/part2.c &&
223 test ! -f src/part3.c &&
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/ &&
237 test -f src/part1.c &&
238 test -f src/part2.c &&
240 test ! -f src/part3.c &&
241 test ! -f examples/1.c &&
242 test -f docs/manual.txt &&
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 &&
255 test -f src/part1.c &&
256 test -f src/part2.c &&
258 test ! -f src/part3.c &&
259 test -f docs/manual.txt &&
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 &&
272 test -f src/part1.c &&
273 test -f src/part2.c &&
275 test ! -f src/part3.c &&
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 &&
289 test -f src/part1.c &&
290 test -f src/part2.c &&
292 test -f src/part3.c &&
293 test -f docs/manual.txt &&
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 &&
306 test -f src/part1.c &&
307 test -f src/part2.c &&
309 test -f src/part3.c &&
310 test -f docs/manual.txt &&
316 test_expect_success
'clean.requireForce defaults to true' '
318 git config --unset clean.requireForce &&
319 test_must_fail git clean
323 test_expect_success
'clean.requireForce' '
325 git config clean.requireForce true &&
326 test_must_fail 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 &&
337 test -f src/part1.c &&
338 test -f src/part2.c &&
340 test -f src/part3.c &&
341 test -f docs/manual.txt &&
347 test_expect_success
'clean.requireForce and -f' '
351 test -f src/part1.c &&
352 test -f src/part2.c &&
354 test ! -f src/part3.c &&
355 test -f docs/manual.txt &&
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' '
378 test_must_fail git clean -f -d)