The twelfth batch
[git/gitster.git] / t / t7301-clean-interactive.sh
blob4afe53c66ae57acdadc7177b98fd0aacefdd576c
1 #!/bin/sh
3 test_description='git clean -i basic tests'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7 . "$TEST_DIRECTORY"/lib-terminal.sh
9 test_expect_success 'setup' '
11 mkdir -p src &&
12 touch src/part1.c Makefile &&
13 echo build >.gitignore &&
14 echo \*.o >>.gitignore &&
15 git add . &&
16 git commit -m setup &&
17 touch src/part2.c README &&
18 git add .
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 &&
28 test_path_is_file Makefile &&
29 test_path_is_file README &&
30 test_path_is_file src/part1.c &&
31 test_path_is_file src/part2.c &&
32 test_path_is_missing a.out &&
33 test_path_is_file docs/manual.txt &&
34 test_path_is_missing src/part3.c &&
35 test_path_is_missing src/part3.h &&
36 test_path_is_missing src/part4.c &&
37 test_path_is_missing src/part4.h &&
38 test_path_is_file obj.o &&
39 test_path_is_file build/lib.so
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 &&
49 test_path_is_file Makefile &&
50 test_path_is_file README &&
51 test_path_is_file src/part1.c &&
52 test_path_is_file src/part2.c &&
53 test_path_is_missing a.out &&
54 test_path_is_file docs/manual.txt &&
55 test_path_is_missing src/part3.c &&
56 test_path_is_missing src/part3.h &&
57 test_path_is_missing src/part4.c &&
58 test_path_is_missing src/part4.h &&
59 test_path_is_file obj.o &&
60 test_path_is_file build/lib.so
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 &&
70 test_path_is_file Makefile &&
71 test_path_is_file README &&
72 test_path_is_file src/part1.c &&
73 test_path_is_file src/part2.c &&
74 test_path_is_file a.out &&
75 test_path_is_file docs/manual.txt &&
76 test_path_is_file src/part3.c &&
77 test_path_is_file src/part3.h &&
78 test_path_is_file src/part4.c &&
79 test_path_is_file src/part4.h &&
80 test_path_is_file obj.o &&
81 test_path_is_file build/lib.so
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 &&
91 test_path_is_file Makefile &&
92 test_path_is_file README &&
93 test_path_is_file src/part1.c &&
94 test_path_is_file src/part2.c &&
95 test_path_is_file a.out &&
96 test_path_is_file docs/manual.txt &&
97 test_path_is_file src/part3.c &&
98 test_path_is_file src/part3.h &&
99 test_path_is_file src/part4.c &&
100 test_path_is_file src/part4.h &&
101 test_path_is_file obj.o &&
102 test_path_is_file build/lib.so
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 |
112 git clean -id &&
113 test_path_is_file Makefile &&
114 test_path_is_file README &&
115 test_path_is_file src/part1.c &&
116 test_path_is_file src/part2.c &&
117 test_path_is_file a.out &&
118 test_path_is_file docs/manual.txt &&
119 test_path_is_file src/part3.c &&
120 test_path_is_file src/part3.h &&
121 test_path_is_file src/part4.c &&
122 test_path_is_file src/part4.h &&
123 test_path_is_file obj.o &&
124 test_path_is_file build/lib.so
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 |
134 git clean -id &&
135 test_path_is_file Makefile &&
136 test_path_is_file README &&
137 test_path_is_file src/part1.c &&
138 test_path_is_file src/part2.c &&
139 test_path_is_file a.out &&
140 test_path_is_missing docs/manual.txt &&
141 test_path_is_file src/part3.c &&
142 test_path_is_file src/part3.h &&
143 test_path_is_missing src/part4.c &&
144 test_path_is_missing src/part4.h &&
145 test_path_is_file obj.o &&
146 test_path_is_file build/lib.so
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 |
156 git clean -id &&
157 test_path_is_file Makefile &&
158 test_path_is_file README &&
159 test_path_is_file src/part1.c &&
160 test_path_is_file src/part2.c &&
161 test_path_is_missing a.out &&
162 test_path_is_file docs/manual.txt &&
163 test_path_is_file src/part3.c &&
164 test_path_is_file src/part3.h &&
165 test_path_is_file src/part4.c &&
166 test_path_is_file src/part4.h &&
167 test_path_is_file obj.o &&
168 test_path_is_file build/lib.so
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 |
178 git clean -id &&
179 test_path_is_file Makefile &&
180 test_path_is_file README &&
181 test_path_is_file src/part1.c &&
182 test_path_is_file src/part2.c &&
183 test_path_is_missing a.out &&
184 test_path_is_missing docs/manual.txt &&
185 test_path_is_missing src/part3.c &&
186 test_path_is_missing src/part3.h &&
187 test_path_is_missing src/part4.c &&
188 test_path_is_missing src/part4.h &&
189 test_path_is_file obj.o &&
190 test_path_is_file build/lib.so
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 |
200 git clean -id &&
201 test_path_is_file Makefile &&
202 test_path_is_file README &&
203 test_path_is_file src/part1.c &&
204 test_path_is_file src/part2.c &&
205 test_path_is_file a.out &&
206 test_path_is_file docs/manual.txt &&
207 test_path_is_file src/part3.c &&
208 test_path_is_file src/part3.h &&
209 test_path_is_file src/part4.c &&
210 test_path_is_file src/part4.h &&
211 test_path_is_file obj.o &&
212 test_path_is_file build/lib.so
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 |
222 git clean -id &&
223 test_path_is_file Makefile &&
224 test_path_is_file README &&
225 test_path_is_file src/part1.c &&
226 test_path_is_file src/part2.c &&
227 test_path_is_file a.out &&
228 test_path_is_file docs/manual.txt &&
229 test_path_is_missing src/part3.c &&
230 test_path_is_file src/part3.h &&
231 test_path_is_file src/part4.c &&
232 test_path_is_file src/part4.h &&
233 test_path_is_file obj.o &&
234 test_path_is_file build/lib.so
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 |
244 git clean -id &&
245 test_path_is_file Makefile &&
246 test_path_is_file README &&
247 test_path_is_file src/part1.c &&
248 test_path_is_file src/part2.c &&
249 test_path_is_file a.out &&
250 test_path_is_missing docs/manual.txt &&
251 test_path_is_missing src/part3.c &&
252 test_path_is_file src/part3.h &&
253 test_path_is_missing src/part4.c &&
254 test_path_is_file src/part4.h &&
255 test_path_is_file obj.o &&
256 test_path_is_file build/lib.so
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 |
266 git clean -id &&
267 test_path_is_file Makefile &&
268 test_path_is_file README &&
269 test_path_is_file src/part1.c &&
270 test_path_is_file src/part2.c &&
271 test_path_is_file a.out &&
272 test_path_is_file docs/manual.txt &&
273 test_path_is_missing src/part3.c &&
274 test_path_is_missing src/part3.h &&
275 test_path_is_missing src/part4.c &&
276 test_path_is_file src/part4.h &&
277 test_path_is_file obj.o &&
278 test_path_is_file build/lib.so
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 |
287 git clean -id &&
288 test_path_is_file Makefile &&
289 test_path_is_missing a.out &&
290 test_path_is_missing foo.txt &&
291 test_path_is_missing bar.txt &&
292 test_path_is_file baz.txt &&
293 rm baz.txt
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 |
303 git clean -id &&
304 test_path_is_file Makefile &&
305 test_path_is_file README &&
306 test_path_is_file src/part1.c &&
307 test_path_is_file src/part2.c &&
308 test_path_is_missing a.out &&
309 test_path_is_missing src/part3.c &&
310 test_path_is_missing src/part3.h &&
311 test_path_is_file src/part4.c &&
312 test_path_is_file src/part4.h &&
313 test_path_is_missing docs/manual.txt &&
314 test_path_is_file obj.o &&
315 test_path_is_file build/lib.so
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 |
325 git clean -id &&
326 test_path_is_file Makefile &&
327 test_path_is_file README &&
328 test_path_is_file src/part1.c &&
329 test_path_is_file src/part2.c &&
330 test_path_is_missing a.out &&
331 test_path_is_file docs/manual.txt &&
332 test_path_is_file src/part3.c &&
333 test_path_is_missing src/part3.h &&
334 test_path_is_missing src/part4.c &&
335 test_path_is_missing src/part4.h &&
336 test_path_is_file obj.o &&
337 test_path_is_file build/lib.so
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 |
347 git clean -id &&
348 test_path_is_file Makefile &&
349 test_path_is_file README &&
350 test_path_is_file src/part1.c &&
351 test_path_is_file src/part2.c &&
352 test_path_is_missing a.out &&
353 test_path_is_file docs/manual.txt &&
354 test_path_is_missing src/part3.c &&
355 test_path_is_missing src/part3.h &&
356 test_path_is_file src/part4.c &&
357 test_path_is_file src/part4.h &&
358 test_path_is_file obj.o &&
359 test_path_is_file build/lib.so
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 "" |
369 git clean -id &&
370 test_path_is_file Makefile &&
371 test_path_is_file README &&
372 test_path_is_file src/part1.c &&
373 test_path_is_file src/part2.c &&
374 test_path_is_missing a.out &&
375 test_path_is_missing docs/manual.txt &&
376 test_path_is_file src/part3.c &&
377 test_path_is_missing src/part3.h &&
378 test_path_is_file src/part4.c &&
379 test_path_is_file src/part4.h &&
380 test_path_is_file obj.o &&
381 test_path_is_file build/lib.so
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" |
391 git clean -id &&
392 test_path_is_file Makefile &&
393 test_path_is_file README &&
394 test_path_is_file src/part1.c &&
395 test_path_is_file src/part2.c &&
396 test_path_is_missing a.out &&
397 test_path_is_file docs/manual.txt &&
398 test_path_is_missing src/part3.c &&
399 test_path_is_file src/part3.h &&
400 test_path_is_file src/part4.c &&
401 test_path_is_file src/part4.h &&
402 test_path_is_file obj.o &&
403 test_path_is_file build/lib.so
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 &&
412 (cd build/ &&
413 test_write_lines f docs "*.h" "" c |
414 git clean -id ..) &&
415 test_path_is_file Makefile &&
416 test_path_is_file README &&
417 test_path_is_file src/part1.c &&
418 test_path_is_file src/part2.c &&
419 test_path_is_missing a.out &&
420 test_path_is_file docs/manual.txt &&
421 test_path_is_missing src/part3.c &&
422 test_path_is_file src/part3.h &&
423 test_path_is_missing src/part4.c &&
424 test_path_is_file src/part4.h &&
425 test_path_is_file obj.o &&
426 test_path_is_file build/lib.so
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 &&
435 (cd build/ &&
436 test_write_lines s ../docs/ ../src/part3.c ../src/part4.c "" c |
437 git clean -id ..) &&
438 test_path_is_file Makefile &&
439 test_path_is_file README &&
440 test_path_is_file src/part1.c &&
441 test_path_is_file src/part2.c &&
442 test_path_is_file a.out &&
443 test_path_is_missing docs/manual.txt &&
444 test_path_is_missing src/part3.c &&
445 test_path_is_file src/part3.h &&
446 test_path_is_missing src/part4.c &&
447 test_path_is_file src/part4.h &&
448 test_path_is_file obj.o &&
449 test_path_is_file build/lib.so
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 &&
458 (cd build/ &&
459 test_write_lines a Y y no yes bad "" |
460 git clean -id ..) &&
461 test_path_is_file Makefile &&
462 test_path_is_file README &&
463 test_path_is_file src/part1.c &&
464 test_path_is_file src/part2.c &&
465 test_path_is_missing a.out &&
466 test_path_is_missing docs/manual.txt &&
467 test_path_is_file src/part3.c &&
468 test_path_is_missing src/part3.h &&
469 test_path_is_file src/part4.c &&
470 test_path_is_file src/part4.h &&
471 test_path_is_file obj.o &&
472 test_path_is_file build/lib.so
476 test_expect_success TTY 'git clean -i paints the header in HEADER color' '
477 >a.out &&
478 echo q |
479 test_terminal git clean -i |
480 test_decode_color |
481 head -n 1 >header &&
482 # not i18ngrep
483 grep "^<BOLD>" header
486 test_done