3 test_description='git clean -i basic tests'
6 . "$TEST_DIRECTORY"/lib-terminal.sh
8 test_expect_success 'setup' '
11 touch src/part1.c Makefile &&
12 echo build >.gitignore &&
13 echo \*.o >>.gitignore &&
15 git commit -m setup &&
16 touch src/part2.c README &&
21 test_expect_success 'git clean -i (c: clean hotkey)' '
23 mkdir -p build docs &&
24 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
25 docs/manual.txt obj.o build/lib.so &&
26 echo c | git clean -i &&
29 test -f src/part1.c &&
30 test -f src/part2.c &&
32 test -f docs/manual.txt &&
33 test ! -f src/part3.c &&
34 test ! -f src/part3.h &&
35 test ! -f src/part4.c &&
36 test ! -f src/part4.h &&
42 test_expect_success 'git clean -i (cl: clean prefix)' '
44 mkdir -p build docs &&
45 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
46 docs/manual.txt obj.o build/lib.so &&
47 echo cl | git clean -i &&
50 test -f src/part1.c &&
51 test -f src/part2.c &&
53 test -f docs/manual.txt &&
54 test ! -f src/part3.c &&
55 test ! -f src/part3.h &&
56 test ! -f src/part4.c &&
57 test ! -f src/part4.h &&
63 test_expect_success 'git clean -i (quit)' '
65 mkdir -p build docs &&
66 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
67 docs/manual.txt obj.o build/lib.so &&
68 echo quit | git clean -i &&
71 test -f src/part1.c &&
72 test -f src/part2.c &&
74 test -f docs/manual.txt &&
75 test -f src/part3.c &&
76 test -f src/part3.h &&
77 test -f src/part4.c &&
78 test -f src/part4.h &&
84 test_expect_success 'git clean -i (Ctrl+D)' '
86 mkdir -p build docs &&
87 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
88 docs/manual.txt obj.o build/lib.so &&
89 echo "\04" | git clean -i &&
92 test -f src/part1.c &&
93 test -f src/part2.c &&
95 test -f docs/manual.txt &&
96 test -f src/part3.c &&
97 test -f src/part3.h &&
98 test -f src/part4.c &&
99 test -f src/part4.h &&
105 test_expect_success 'git clean -id (filter all)' '
107 mkdir -p build docs &&
108 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
109 docs/manual.txt obj.o build/lib.so &&
110 (echo f; echo "*"; echo; echo c) | \
114 test -f src/part1.c &&
115 test -f src/part2.c &&
117 test -f docs/manual.txt &&
118 test -f src/part3.c &&
119 test -f src/part3.h &&
120 test -f src/part4.c &&
121 test -f src/part4.h &&
127 test_expect_success 'git clean -id (filter patterns)' '
129 mkdir -p build docs &&
130 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
131 docs/manual.txt obj.o build/lib.so &&
132 (echo f; echo "part3.* *.out"; echo; echo c) | \
136 test -f src/part1.c &&
137 test -f src/part2.c &&
139 test ! -f docs/manual.txt &&
140 test -f src/part3.c &&
141 test -f src/part3.h &&
142 test ! -f src/part4.c &&
143 test ! -f src/part4.h &&
149 test_expect_success 'git clean -id (filter patterns 2)' '
151 mkdir -p build docs &&
152 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
153 docs/manual.txt obj.o build/lib.so &&
154 (echo f; echo "* !*.out"; echo; echo c) | \
158 test -f src/part1.c &&
159 test -f src/part2.c &&
161 test -f docs/manual.txt &&
162 test -f src/part3.c &&
163 test -f src/part3.h &&
164 test -f src/part4.c &&
165 test -f src/part4.h &&
171 test_expect_success 'git clean -id (select - all)' '
173 mkdir -p build docs &&
174 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
175 docs/manual.txt obj.o build/lib.so &&
176 (echo s; echo "*"; echo; echo c) | \
180 test -f src/part1.c &&
181 test -f src/part2.c &&
183 test ! -f docs/manual.txt &&
184 test ! -f src/part3.c &&
185 test ! -f src/part3.h &&
186 test ! -f src/part4.c &&
187 test ! -f src/part4.h &&
193 test_expect_success 'git clean -id (select - none)' '
195 mkdir -p build docs &&
196 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
197 docs/manual.txt obj.o build/lib.so &&
198 (echo s; echo; echo c) | \
202 test -f src/part1.c &&
203 test -f src/part2.c &&
205 test -f docs/manual.txt &&
206 test -f src/part3.c &&
207 test -f src/part3.h &&
208 test -f src/part4.c &&
209 test -f src/part4.h &&
215 test_expect_success 'git clean -id (select - number)' '
217 mkdir -p build docs &&
218 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
219 docs/manual.txt obj.o build/lib.so &&
220 (echo s; echo 3; echo; echo c) | \
224 test -f src/part1.c &&
225 test -f src/part2.c &&
227 test -f docs/manual.txt &&
228 test ! -f src/part3.c &&
229 test -f src/part3.h &&
230 test -f src/part4.c &&
231 test -f src/part4.h &&
237 test_expect_success 'git clean -id (select - number 2)' '
239 mkdir -p build docs &&
240 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
241 docs/manual.txt obj.o build/lib.so &&
242 (echo s; echo 2 3; echo 5; echo; echo c) | \
246 test -f src/part1.c &&
247 test -f src/part2.c &&
249 test ! -f docs/manual.txt &&
250 test ! -f src/part3.c &&
251 test -f src/part3.h &&
252 test ! -f src/part4.c &&
253 test -f src/part4.h &&
259 test_expect_success 'git clean -id (select - number 3)' '
261 mkdir -p build docs &&
262 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
263 docs/manual.txt obj.o build/lib.so &&
264 (echo s; echo 3,4 5; echo; echo c) | \
268 test -f src/part1.c &&
269 test -f src/part2.c &&
271 test -f docs/manual.txt &&
272 test ! -f src/part3.c &&
273 test ! -f src/part3.h &&
274 test ! -f src/part4.c &&
275 test -f src/part4.h &&
281 test_expect_success 'git clean -id (select - filenames)' '
283 mkdir -p build docs &&
284 touch a.out foo.txt bar.txt baz.txt &&
285 (echo s; echo a.out fo ba bar; echo; echo c) | \
296 test_expect_success 'git clean -id (select - range)' '
298 mkdir -p build docs &&
299 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
300 docs/manual.txt obj.o build/lib.so &&
301 (echo s; echo 1,3-4; echo 2; echo; echo c) | \
305 test -f src/part1.c &&
306 test -f src/part2.c &&
308 test ! -f src/part3.c &&
309 test ! -f src/part3.h &&
310 test -f src/part4.c &&
311 test -f src/part4.h &&
312 test ! -f docs/manual.txt &&
318 test_expect_success 'git clean -id (select - range 2)' '
320 mkdir -p build docs &&
321 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
322 docs/manual.txt obj.o build/lib.so &&
323 (echo s; echo 4- 1; echo; echo c) | \
327 test -f src/part1.c &&
328 test -f src/part2.c &&
330 test -f docs/manual.txt &&
331 test -f src/part3.c &&
332 test ! -f src/part3.h &&
333 test ! -f src/part4.c &&
334 test ! -f src/part4.h &&
340 test_expect_success 'git clean -id (inverse select)' '
342 mkdir -p build docs &&
343 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
344 docs/manual.txt obj.o build/lib.so &&
345 (echo s; echo "*"; echo -5- 1 -2; echo; echo c) | \
349 test -f src/part1.c &&
350 test -f src/part2.c &&
352 test -f docs/manual.txt &&
353 test ! -f src/part3.c &&
354 test ! -f src/part3.h &&
355 test -f src/part4.c &&
356 test -f src/part4.h &&
362 test_expect_success 'git clean -id (ask)' '
364 mkdir -p build docs &&
365 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
366 docs/manual.txt obj.o build/lib.so &&
367 (echo a; echo Y; echo y; echo no; echo yes; echo bad; echo) | \
371 test -f src/part1.c &&
372 test -f src/part2.c &&
374 test ! -f docs/manual.txt &&
375 test -f src/part3.c &&
376 test ! -f src/part3.h &&
377 test -f src/part4.c &&
378 test -f src/part4.h &&
384 test_expect_success 'git clean -id (ask - Ctrl+D)' '
386 mkdir -p build docs &&
387 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
388 docs/manual.txt obj.o build/lib.so &&
389 (echo a; echo Y; echo no; echo yes; echo "\04") | \
393 test -f src/part1.c &&
394 test -f src/part2.c &&
396 test -f docs/manual.txt &&
397 test ! -f src/part3.c &&
398 test -f src/part3.h &&
399 test -f src/part4.c &&
400 test -f src/part4.h &&
406 test_expect_success 'git clean -id with prefix and path (filter)' '
408 mkdir -p build docs &&
409 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
410 docs/manual.txt obj.o build/lib.so &&
412 (echo f; echo "docs"; echo "*.h"; echo ; echo c) | \
416 test -f src/part1.c &&
417 test -f src/part2.c &&
419 test -f docs/manual.txt &&
420 test ! -f src/part3.c &&
421 test -f src/part3.h &&
422 test ! -f src/part4.c &&
423 test -f src/part4.h &&
429 test_expect_success 'git clean -id with prefix and path (select by name)' '
431 mkdir -p build docs &&
432 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
433 docs/manual.txt obj.o build/lib.so &&
435 (echo s; echo "../docs/"; echo "../src/part3.c"; \
436 echo "../src/part4.c"; echo; echo c) | \
440 test -f src/part1.c &&
441 test -f src/part2.c &&
443 test ! -f docs/manual.txt &&
444 test ! -f src/part3.c &&
445 test -f src/part3.h &&
446 test ! -f src/part4.c &&
447 test -f src/part4.h &&
453 test_expect_success 'git clean -id with prefix and path (ask)' '
455 mkdir -p build docs &&
456 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
457 docs/manual.txt obj.o build/lib.so &&
459 (echo a; echo Y; echo y; echo no; echo yes; echo bad; echo) | \
463 test -f src/part1.c &&
464 test -f src/part2.c &&
466 test ! -f docs/manual.txt &&
467 test -f src/part3.c &&
468 test ! -f src/part3.h &&
469 test -f src/part4.c &&
470 test -f src/part4.h &&
476 test_expect_success TTY 'git clean -i paints the header in HEADER color' '
479 test_terminal git clean -i |
483 grep "^<BOLD>" header