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 test_write_lines f "*" "" 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 test_write_lines f "part3.* *.out" "" 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 test_write_lines f "* !*.out" "" 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 test_write_lines s "*" "" 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 test_write_lines s "" 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 test_write_lines s 3 "" 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 test_write_lines s "2 3" 5 "" 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 test_write_lines s "3,4 5" "" 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 test_write_lines s "a.out fo ba bar" "" 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 test_write_lines s "1,3-4" 2 "" 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 test_write_lines s "4- 1" "" 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 test_write_lines s "*" "-5- 1 -2" "" 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 test_write_lines a Y y no yes bad "" |
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 test_write_lines a Y no yes "\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 test_write_lines f docs "*.h" "" 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 test_write_lines s ../docs/ ../src/part3.c ../src/part4.c "" 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 test_write_lines a Y y no yes bad "" |
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 TTY 'git clean -i paints the header in HEADER color' '
478 test_terminal git clean -i |
482 grep "^<BOLD>" header