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 &&
79 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
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 docs/manual.txt &&
93 test_expect_success
'git-clean with relative prefix' '
95 mkdir -p build docs &&
96 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
100 sed -n -e "s|^Would remove ||p"
102 test "$would_clean" = ../src/part3.c || {
103 echo "OOps <$would_clean>"
108 test_expect_success
'git-clean with absolute path' '
110 mkdir -p build docs &&
111 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
114 git clean -n $(pwd)/../src |
115 sed -n -e "s|^Would remove ||p"
117 test "$would_clean" = ../src/part3.c || {
118 echo "OOps <$would_clean>"
123 test_expect_success
'git-clean with out of work tree relative path' '
125 mkdir -p build docs &&
126 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
129 test_must_fail git clean -n ../..
133 test_expect_success
'git-clean with out of work tree absolute path' '
135 mkdir -p build docs &&
136 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
137 dd=$(cd .. && pwd) &&
140 test_must_fail git clean -n $dd
144 test_expect_success
'git-clean -d with prefix and path' '
146 mkdir -p build docs src/feature &&
147 touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
148 (cd src/ && git-clean -d feature/) &&
151 test -f src/part1.c &&
152 test -f src/part2.c &&
154 test -f src/part3.c &&
155 test ! -f src/feature/file.c &&
156 test -f docs/manual.txt &&
162 test_expect_success
'git-clean symbolic link' '
164 mkdir -p build docs &&
165 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
166 ln -s docs/manual.txt src/part4.c
170 test -f src/part1.c &&
171 test -f src/part2.c &&
173 test ! -f src/part3.c &&
174 test ! -f src/part4.c &&
175 test -f docs/manual.txt &&
181 test_expect_success
'git-clean with wildcard' '
183 touch a.clean b.clean other.c &&
184 git-clean "*.clean" &&
187 test -f src/part1.c &&
188 test -f src/part2.c &&
195 test_expect_success
'git-clean -n' '
197 mkdir -p build docs &&
198 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
202 test -f src/part1.c &&
203 test -f src/part2.c &&
205 test -f src/part3.c &&
206 test -f docs/manual.txt &&
212 test_expect_success
'git-clean -d' '
214 mkdir -p build docs &&
215 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
219 test -f src/part1.c &&
220 test -f src/part2.c &&
222 test ! -f src/part3.c &&
229 test_expect_success
'git-clean -d src/ examples/' '
231 mkdir -p build docs examples &&
232 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
233 git-clean -d src/ examples/ &&
236 test -f src/part1.c &&
237 test -f src/part2.c &&
239 test ! -f src/part3.c &&
240 test ! -f examples/1.c &&
241 test -f docs/manual.txt &&
247 test_expect_success
'git-clean -x' '
249 mkdir -p build docs &&
250 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
254 test -f src/part1.c &&
255 test -f src/part2.c &&
257 test ! -f src/part3.c &&
258 test -f docs/manual.txt &&
264 test_expect_success
'git-clean -d -x' '
266 mkdir -p build docs &&
267 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
271 test -f src/part1.c &&
272 test -f src/part2.c &&
274 test ! -f src/part3.c &&
281 test_expect_success
'git-clean -X' '
283 mkdir -p build docs &&
284 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
288 test -f src/part1.c &&
289 test -f src/part2.c &&
291 test -f src/part3.c &&
292 test -f docs/manual.txt &&
298 test_expect_success
'git-clean -d -X' '
300 mkdir -p build docs &&
301 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
305 test -f src/part1.c &&
306 test -f src/part2.c &&
308 test -f src/part3.c &&
309 test -f docs/manual.txt &&
315 test_expect_success
'clean.requireForce defaults to true' '
317 git config --unset clean.requireForce &&
322 test_expect_success
'clean.requireForce' '
324 git config clean.requireForce true &&
329 test_expect_success
'clean.requireForce and -n' '
331 mkdir -p build docs &&
332 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
336 test -f src/part1.c &&
337 test -f src/part2.c &&
339 test -f src/part3.c &&
340 test -f docs/manual.txt &&
346 test_expect_success
'clean.requireForce and -f' '
350 test -f src/part1.c &&
351 test -f src/part2.c &&
353 test ! -f src/part3.c &&
354 test -f docs/manual.txt &&
360 test_expect_success
'core.excludesfile' '
362 echo excludes >excludes &&
363 echo included >included &&
364 git config core.excludesfile excludes &&
365 output=$(git clean -n excludes included 2>&1) &&
366 expr "$output" : ".*included" >/dev/null &&
367 ! expr "$output" : ".*excludes" >/dev/null
371 test_expect_success
'removal failure' '
377 test_must_fail git clean -f -d