3 test_description
='git clean -i basic tests'
5 TEST_PASSES_SANITIZE_LEAK
=true
7 .
"$TEST_DIRECTORY"/lib-terminal.sh
9 test_expect_success
'setup' '
12 touch src/part1.c Makefile &&
13 echo build >.gitignore &&
14 echo \*.o >>.gitignore &&
16 git commit -m setup &&
17 touch src/part2.c README &&
22 test_expect_success
'git clean -i (c: clean hotkey)' '
24 mkdir -p build docs &&
25 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
26 docs/manual.txt obj.o build/lib.so &&
27 echo c | git clean -i &&
30 test -f src/part1.c &&
31 test -f src/part2.c &&
33 test -f docs/manual.txt &&
34 test ! -f src/part3.c &&
35 test ! -f src/part3.h &&
36 test ! -f src/part4.c &&
37 test ! -f src/part4.h &&
43 test_expect_success
'git clean -i (cl: clean prefix)' '
45 mkdir -p build docs &&
46 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
47 docs/manual.txt obj.o build/lib.so &&
48 echo cl | git clean -i &&
51 test -f src/part1.c &&
52 test -f src/part2.c &&
54 test -f docs/manual.txt &&
55 test ! -f src/part3.c &&
56 test ! -f src/part3.h &&
57 test ! -f src/part4.c &&
58 test ! -f src/part4.h &&
64 test_expect_success
'git clean -i (quit)' '
66 mkdir -p build docs &&
67 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
68 docs/manual.txt obj.o build/lib.so &&
69 echo quit | git clean -i &&
72 test -f src/part1.c &&
73 test -f src/part2.c &&
75 test -f docs/manual.txt &&
76 test -f src/part3.c &&
77 test -f src/part3.h &&
78 test -f src/part4.c &&
79 test -f src/part4.h &&
85 test_expect_success
'git clean -i (Ctrl+D)' '
87 mkdir -p build docs &&
88 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
89 docs/manual.txt obj.o build/lib.so &&
90 echo "\04" | git clean -i &&
93 test -f src/part1.c &&
94 test -f src/part2.c &&
96 test -f docs/manual.txt &&
97 test -f src/part3.c &&
98 test -f src/part3.h &&
99 test -f src/part4.c &&
100 test -f src/part4.h &&
106 test_expect_success
'git clean -id (filter all)' '
108 mkdir -p build docs &&
109 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
110 docs/manual.txt obj.o build/lib.so &&
111 test_write_lines f "*" "" c |
115 test -f src/part1.c &&
116 test -f src/part2.c &&
118 test -f docs/manual.txt &&
119 test -f src/part3.c &&
120 test -f src/part3.h &&
121 test -f src/part4.c &&
122 test -f src/part4.h &&
128 test_expect_success
'git clean -id (filter patterns)' '
130 mkdir -p build docs &&
131 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
132 docs/manual.txt obj.o build/lib.so &&
133 test_write_lines f "part3.* *.out" "" c |
137 test -f src/part1.c &&
138 test -f src/part2.c &&
140 test ! -f docs/manual.txt &&
141 test -f src/part3.c &&
142 test -f src/part3.h &&
143 test ! -f src/part4.c &&
144 test ! -f src/part4.h &&
150 test_expect_success
'git clean -id (filter patterns 2)' '
152 mkdir -p build docs &&
153 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
154 docs/manual.txt obj.o build/lib.so &&
155 test_write_lines f "* !*.out" "" c |
159 test -f src/part1.c &&
160 test -f src/part2.c &&
162 test -f docs/manual.txt &&
163 test -f src/part3.c &&
164 test -f src/part3.h &&
165 test -f src/part4.c &&
166 test -f src/part4.h &&
172 test_expect_success
'git clean -id (select - all)' '
174 mkdir -p build docs &&
175 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
176 docs/manual.txt obj.o build/lib.so &&
177 test_write_lines s "*" "" c |
181 test -f src/part1.c &&
182 test -f src/part2.c &&
184 test ! -f docs/manual.txt &&
185 test ! -f src/part3.c &&
186 test ! -f src/part3.h &&
187 test ! -f src/part4.c &&
188 test ! -f src/part4.h &&
194 test_expect_success
'git clean -id (select - none)' '
196 mkdir -p build docs &&
197 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
198 docs/manual.txt obj.o build/lib.so &&
199 test_write_lines s "" c |
203 test -f src/part1.c &&
204 test -f src/part2.c &&
206 test -f docs/manual.txt &&
207 test -f src/part3.c &&
208 test -f src/part3.h &&
209 test -f src/part4.c &&
210 test -f src/part4.h &&
216 test_expect_success
'git clean -id (select - number)' '
218 mkdir -p build docs &&
219 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
220 docs/manual.txt obj.o build/lib.so &&
221 test_write_lines s 3 "" c |
225 test -f src/part1.c &&
226 test -f src/part2.c &&
228 test -f docs/manual.txt &&
229 test ! -f src/part3.c &&
230 test -f src/part3.h &&
231 test -f src/part4.c &&
232 test -f src/part4.h &&
238 test_expect_success
'git clean -id (select - number 2)' '
240 mkdir -p build docs &&
241 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
242 docs/manual.txt obj.o build/lib.so &&
243 test_write_lines s "2 3" 5 "" c |
247 test -f src/part1.c &&
248 test -f src/part2.c &&
250 test ! -f docs/manual.txt &&
251 test ! -f src/part3.c &&
252 test -f src/part3.h &&
253 test ! -f src/part4.c &&
254 test -f src/part4.h &&
260 test_expect_success
'git clean -id (select - number 3)' '
262 mkdir -p build docs &&
263 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
264 docs/manual.txt obj.o build/lib.so &&
265 test_write_lines s "3,4 5" "" c |
269 test -f src/part1.c &&
270 test -f src/part2.c &&
272 test -f docs/manual.txt &&
273 test ! -f src/part3.c &&
274 test ! -f src/part3.h &&
275 test ! -f src/part4.c &&
276 test -f src/part4.h &&
282 test_expect_success
'git clean -id (select - filenames)' '
284 mkdir -p build docs &&
285 touch a.out foo.txt bar.txt baz.txt &&
286 test_write_lines s "a.out fo ba bar" "" c |
297 test_expect_success
'git clean -id (select - range)' '
299 mkdir -p build docs &&
300 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
301 docs/manual.txt obj.o build/lib.so &&
302 test_write_lines s "1,3-4" 2 "" c |
306 test -f src/part1.c &&
307 test -f src/part2.c &&
309 test ! -f src/part3.c &&
310 test ! -f src/part3.h &&
311 test -f src/part4.c &&
312 test -f src/part4.h &&
313 test ! -f docs/manual.txt &&
319 test_expect_success
'git clean -id (select - range 2)' '
321 mkdir -p build docs &&
322 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
323 docs/manual.txt obj.o build/lib.so &&
324 test_write_lines s "4- 1" "" c |
328 test -f src/part1.c &&
329 test -f src/part2.c &&
331 test -f docs/manual.txt &&
332 test -f src/part3.c &&
333 test ! -f src/part3.h &&
334 test ! -f src/part4.c &&
335 test ! -f src/part4.h &&
341 test_expect_success
'git clean -id (inverse select)' '
343 mkdir -p build docs &&
344 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
345 docs/manual.txt obj.o build/lib.so &&
346 test_write_lines s "*" "-5- 1 -2" "" c |
350 test -f src/part1.c &&
351 test -f src/part2.c &&
353 test -f docs/manual.txt &&
354 test ! -f src/part3.c &&
355 test ! -f src/part3.h &&
356 test -f src/part4.c &&
357 test -f src/part4.h &&
363 test_expect_success
'git clean -id (ask)' '
365 mkdir -p build docs &&
366 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
367 docs/manual.txt obj.o build/lib.so &&
368 test_write_lines a Y y no yes bad "" |
372 test -f src/part1.c &&
373 test -f src/part2.c &&
375 test ! -f docs/manual.txt &&
376 test -f src/part3.c &&
377 test ! -f src/part3.h &&
378 test -f src/part4.c &&
379 test -f src/part4.h &&
385 test_expect_success
'git clean -id (ask - Ctrl+D)' '
387 mkdir -p build docs &&
388 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
389 docs/manual.txt obj.o build/lib.so &&
390 test_write_lines a Y no yes "\04" |
394 test -f src/part1.c &&
395 test -f src/part2.c &&
397 test -f docs/manual.txt &&
398 test ! -f src/part3.c &&
399 test -f src/part3.h &&
400 test -f src/part4.c &&
401 test -f src/part4.h &&
407 test_expect_success
'git clean -id with prefix and path (filter)' '
409 mkdir -p build docs &&
410 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
411 docs/manual.txt obj.o build/lib.so &&
413 test_write_lines f docs "*.h" "" c |
417 test -f src/part1.c &&
418 test -f src/part2.c &&
420 test -f docs/manual.txt &&
421 test ! -f src/part3.c &&
422 test -f src/part3.h &&
423 test ! -f src/part4.c &&
424 test -f src/part4.h &&
430 test_expect_success
'git clean -id with prefix and path (select by name)' '
432 mkdir -p build docs &&
433 touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
434 docs/manual.txt obj.o build/lib.so &&
436 test_write_lines s ../docs/ ../src/part3.c ../src/part4.c "" 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 test_write_lines a Y y no yes bad "" |
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