3 test_description='git clean -i basic tests'
7 test_expect_success 'setup' '
10 touch src/part1.c Makefile &&
11 echo build >.gitignore &&
12 echo \*.o >>.gitignore &&
14 git commit -m setup &&
15 touch src/part2.c README &&
20 test_expect_success 'git clean -i (c: clean hotkey)' '
22 mkdir -p build docs &&
23 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
24 docs/manual.txt obj.o build/lib.so &&
25 echo c | git clean -i &&
28 test -f src/part1.c &&
29 test -f src/part2.c &&
31 test -f docs/manual.txt &&
32 test ! -f src/part3.c &&
33 test ! -f src/part3.h &&
34 test ! -f src/part4.c &&
35 test ! -f src/part4.h &&
41 test_expect_success 'git clean -i (cl: clean prefix)' '
43 mkdir -p build docs &&
44 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
45 docs/manual.txt obj.o build/lib.so &&
46 echo cl | git clean -i &&
49 test -f src/part1.c &&
50 test -f src/part2.c &&
52 test -f docs/manual.txt &&
53 test ! -f src/part3.c &&
54 test ! -f src/part3.h &&
55 test ! -f src/part4.c &&
56 test ! -f src/part4.h &&
62 test_expect_success 'git clean -i (quit)' '
64 mkdir -p build docs &&
65 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
66 docs/manual.txt obj.o build/lib.so &&
67 echo quit | git clean -i &&
70 test -f src/part1.c &&
71 test -f src/part2.c &&
73 test -f docs/manual.txt &&
74 test -f src/part3.c &&
75 test -f src/part3.h &&
76 test -f src/part4.c &&
77 test -f src/part4.h &&
83 test_expect_success 'git clean -i (Ctrl+D)' '
85 mkdir -p build docs &&
86 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
87 docs/manual.txt obj.o build/lib.so &&
88 echo "\04" | git clean -i &&
91 test -f src/part1.c &&
92 test -f src/part2.c &&
94 test -f docs/manual.txt &&
95 test -f src/part3.c &&
96 test -f src/part3.h &&
97 test -f src/part4.c &&
98 test -f src/part4.h &&
104 test_expect_success 'git clean -id (filter all)' '
106 mkdir -p build docs &&
107 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
108 docs/manual.txt obj.o build/lib.so &&
109 (echo f; echo "*"; echo; echo c) | \
113 test -f src/part1.c &&
114 test -f src/part2.c &&
116 test -f docs/manual.txt &&
117 test -f src/part3.c &&
118 test -f src/part3.h &&
119 test -f src/part4.c &&
120 test -f src/part4.h &&
126 test_expect_success 'git clean -id (filter patterns)' '
128 mkdir -p build docs &&
129 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
130 docs/manual.txt obj.o build/lib.so &&
131 (echo f; echo "part3.* *.out"; echo; echo c) | \
135 test -f src/part1.c &&
136 test -f src/part2.c &&
138 test ! -f docs/manual.txt &&
139 test -f src/part3.c &&
140 test -f src/part3.h &&
141 test ! -f src/part4.c &&
142 test ! -f src/part4.h &&
148 test_expect_success 'git clean -id (filter patterns 2)' '
150 mkdir -p build docs &&
151 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
152 docs/manual.txt obj.o build/lib.so &&
153 (echo f; echo "* !*.out"; echo; echo c) | \
157 test -f src/part1.c &&
158 test -f src/part2.c &&
160 test -f docs/manual.txt &&
161 test -f src/part3.c &&
162 test -f src/part3.h &&
163 test -f src/part4.c &&
164 test -f src/part4.h &&
170 test_expect_success 'git clean -id (select - all)' '
172 mkdir -p build docs &&
173 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
174 docs/manual.txt obj.o build/lib.so &&
175 (echo s; echo "*"; echo; echo c) | \
179 test -f src/part1.c &&
180 test -f src/part2.c &&
182 test ! -f docs/manual.txt &&
183 test ! -f src/part3.c &&
184 test ! -f src/part3.h &&
185 test ! -f src/part4.c &&
186 test ! -f src/part4.h &&
192 test_expect_success 'git clean -id (select - none)' '
194 mkdir -p build docs &&
195 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
196 docs/manual.txt obj.o build/lib.so &&
197 (echo s; echo; echo c) | \
201 test -f src/part1.c &&
202 test -f src/part2.c &&
204 test -f docs/manual.txt &&
205 test -f src/part3.c &&
206 test -f src/part3.h &&
207 test -f src/part4.c &&
208 test -f src/part4.h &&
214 test_expect_success 'git clean -id (select - number)' '
216 mkdir -p build docs &&
217 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
218 docs/manual.txt obj.o build/lib.so &&
219 (echo s; echo 3; echo; echo c) | \
223 test -f src/part1.c &&
224 test -f src/part2.c &&
226 test -f docs/manual.txt &&
227 test ! -f src/part3.c &&
228 test -f src/part3.h &&
229 test -f src/part4.c &&
230 test -f src/part4.h &&
236 test_expect_success 'git clean -id (select - number 2)' '
238 mkdir -p build docs &&
239 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
240 docs/manual.txt obj.o build/lib.so &&
241 (echo s; echo 2 3; echo 5; echo; echo c) | \
245 test -f src/part1.c &&
246 test -f src/part2.c &&
248 test ! -f docs/manual.txt &&
249 test ! -f src/part3.c &&
250 test -f src/part3.h &&
251 test ! -f src/part4.c &&
252 test -f src/part4.h &&
258 test_expect_success 'git clean -id (select - number 3)' '
260 mkdir -p build docs &&
261 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
262 docs/manual.txt obj.o build/lib.so &&
263 (echo s; echo 3,4 5; echo; echo c) | \
267 test -f src/part1.c &&
268 test -f src/part2.c &&
270 test -f docs/manual.txt &&
271 test ! -f src/part3.c &&
272 test ! -f src/part3.h &&
273 test ! -f src/part4.c &&
274 test -f src/part4.h &&
280 test_expect_success 'git clean -id (select - filenames)' '
282 mkdir -p build docs &&
283 touch a.out foo.txt bar.txt baz.txt &&
284 (echo s; echo a.out fo ba bar; echo; echo c) | \
295 test_expect_success 'git clean -id (select - range)' '
297 mkdir -p build docs &&
298 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
299 docs/manual.txt obj.o build/lib.so &&
300 (echo s; echo 1,3-4; echo 2; echo; echo c) | \
304 test -f src/part1.c &&
305 test -f src/part2.c &&
307 test ! -f src/part3.c &&
308 test ! -f src/part3.h &&
309 test -f src/part4.c &&
310 test -f src/part4.h &&
311 test ! -f docs/manual.txt &&
317 test_expect_success 'git clean -id (select - range 2)' '
319 mkdir -p build docs &&
320 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
321 docs/manual.txt obj.o build/lib.so &&
322 (echo s; echo 4- 1; echo; echo c) | \
326 test -f src/part1.c &&
327 test -f src/part2.c &&
329 test -f docs/manual.txt &&
330 test -f src/part3.c &&
331 test ! -f src/part3.h &&
332 test ! -f src/part4.c &&
333 test ! -f src/part4.h &&
339 test_expect_success 'git clean -id (inverse select)' '
341 mkdir -p build docs &&
342 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
343 docs/manual.txt obj.o build/lib.so &&
344 (echo s; echo "*"; echo -5- 1 -2; echo; echo c) | \
348 test -f src/part1.c &&
349 test -f src/part2.c &&
351 test -f docs/manual.txt &&
352 test ! -f src/part3.c &&
353 test ! -f src/part3.h &&
354 test -f src/part4.c &&
355 test -f src/part4.h &&
361 test_expect_success 'git clean -id (ask)' '
363 mkdir -p build docs &&
364 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
365 docs/manual.txt obj.o build/lib.so &&
366 (echo a; echo Y; echo y; echo no; echo yes; echo bad; echo) | \
370 test -f src/part1.c &&
371 test -f src/part2.c &&
373 test ! -f docs/manual.txt &&
374 test -f src/part3.c &&
375 test ! -f src/part3.h &&
376 test -f src/part4.c &&
377 test -f src/part4.h &&
383 test_expect_success 'git clean -id (ask - Ctrl+D)' '
385 mkdir -p build docs &&
386 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
387 docs/manual.txt obj.o build/lib.so &&
388 (echo a; echo Y; echo no; echo yes; echo "\04") | \
392 test -f src/part1.c &&
393 test -f src/part2.c &&
395 test -f docs/manual.txt &&
396 test ! -f src/part3.c &&
397 test -f src/part3.h &&
398 test -f src/part4.c &&
399 test -f src/part4.h &&
405 test_expect_success 'git clean -id with prefix and path (filter)' '
407 mkdir -p build docs &&
408 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
409 docs/manual.txt obj.o build/lib.so &&
411 (echo f; echo "docs"; echo "*.h"; echo ; echo c) | \
415 test -f src/part1.c &&
416 test -f src/part2.c &&
418 test -f docs/manual.txt &&
419 test ! -f src/part3.c &&
420 test -f src/part3.h &&
421 test ! -f src/part4.c &&
422 test -f src/part4.h &&
428 test_expect_success 'git clean -id with prefix and path (select by name)' '
430 mkdir -p build docs &&
431 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
432 docs/manual.txt obj.o build/lib.so &&
434 (echo s; echo "../docs/"; echo "../src/part3.c"; \
435 echo "../src/part4.c"; echo; echo c) | \
439 test -f src/part1.c &&
440 test -f src/part2.c &&
442 test ! -f docs/manual.txt &&
443 test ! -f src/part3.c &&
444 test -f src/part3.h &&
445 test ! -f src/part4.c &&
446 test -f src/part4.h &&
452 test_expect_success 'git clean -id with prefix and path (ask)' '
454 mkdir -p build docs &&
455 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
456 docs/manual.txt obj.o build/lib.so &&
458 (echo a; echo Y; echo y; echo no; echo yes; echo bad; echo) | \
462 test -f src/part1.c &&
463 test -f src/part2.c &&
465 test ! -f docs/manual.txt &&
466 test -f src/part3.c &&
467 test ! -f src/part3.h &&
468 test -f src/part4.c &&
469 test -f src/part4.h &&
475 test_expect_success 'git clean -i paints the header in HEADER color' '
478 git -c color.ui=always clean -i |
482 grep "^<BOLD>" header