Merge branch 'ds/reprepare-alternates-when-repreparing-packfiles'
[alt-git.git] / t / t7301-clean-interactive.sh
blobd82a3210a1db48288c54ce3c06d430546da70f48
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 -f Makefile &&
29 test -f README &&
30 test -f src/part1.c &&
31 test -f src/part2.c &&
32 test ! -f a.out &&
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 &&
38 test -f obj.o &&
39 test -f 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 -f Makefile &&
50 test -f README &&
51 test -f src/part1.c &&
52 test -f src/part2.c &&
53 test ! -f a.out &&
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 &&
59 test -f obj.o &&
60 test -f 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 -f Makefile &&
71 test -f README &&
72 test -f src/part1.c &&
73 test -f src/part2.c &&
74 test -f a.out &&
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 &&
80 test -f obj.o &&
81 test -f 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 -f Makefile &&
92 test -f README &&
93 test -f src/part1.c &&
94 test -f src/part2.c &&
95 test -f a.out &&
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 &&
101 test -f obj.o &&
102 test -f 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 -f Makefile &&
114 test -f README &&
115 test -f src/part1.c &&
116 test -f src/part2.c &&
117 test -f a.out &&
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 &&
123 test -f obj.o &&
124 test -f 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 -f Makefile &&
136 test -f README &&
137 test -f src/part1.c &&
138 test -f src/part2.c &&
139 test -f a.out &&
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 &&
145 test -f obj.o &&
146 test -f 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 -f Makefile &&
158 test -f README &&
159 test -f src/part1.c &&
160 test -f src/part2.c &&
161 test ! -f a.out &&
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 &&
167 test -f obj.o &&
168 test -f 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 -f Makefile &&
180 test -f README &&
181 test -f src/part1.c &&
182 test -f src/part2.c &&
183 test ! -f a.out &&
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 &&
189 test -f obj.o &&
190 test -f 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 -f Makefile &&
202 test -f README &&
203 test -f src/part1.c &&
204 test -f src/part2.c &&
205 test -f a.out &&
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 &&
211 test -f obj.o &&
212 test -f 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 -f Makefile &&
224 test -f README &&
225 test -f src/part1.c &&
226 test -f src/part2.c &&
227 test -f a.out &&
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 &&
233 test -f obj.o &&
234 test -f 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 -f Makefile &&
246 test -f README &&
247 test -f src/part1.c &&
248 test -f src/part2.c &&
249 test -f a.out &&
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 &&
255 test -f obj.o &&
256 test -f 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 -f Makefile &&
268 test -f README &&
269 test -f src/part1.c &&
270 test -f src/part2.c &&
271 test -f a.out &&
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 &&
277 test -f obj.o &&
278 test -f 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 -f Makefile &&
289 test ! -f a.out &&
290 test ! -f foo.txt &&
291 test ! -f bar.txt &&
292 test -f 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 -f Makefile &&
305 test -f README &&
306 test -f src/part1.c &&
307 test -f src/part2.c &&
308 test ! -f a.out &&
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 &&
314 test -f obj.o &&
315 test -f 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 -f Makefile &&
327 test -f README &&
328 test -f src/part1.c &&
329 test -f src/part2.c &&
330 test ! -f a.out &&
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 &&
336 test -f obj.o &&
337 test -f 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 -f Makefile &&
349 test -f README &&
350 test -f src/part1.c &&
351 test -f src/part2.c &&
352 test ! -f a.out &&
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 &&
358 test -f obj.o &&
359 test -f 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 -f Makefile &&
371 test -f README &&
372 test -f src/part1.c &&
373 test -f src/part2.c &&
374 test ! -f a.out &&
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 &&
380 test -f obj.o &&
381 test -f 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 -f Makefile &&
393 test -f README &&
394 test -f src/part1.c &&
395 test -f src/part2.c &&
396 test ! -f a.out &&
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 &&
402 test -f obj.o &&
403 test -f 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 -f Makefile &&
416 test -f README &&
417 test -f src/part1.c &&
418 test -f src/part2.c &&
419 test ! -f a.out &&
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 &&
425 test -f obj.o &&
426 test -f 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 -f Makefile &&
439 test -f README &&
440 test -f src/part1.c &&
441 test -f src/part2.c &&
442 test -f a.out &&
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 &&
448 test -f obj.o &&
449 test -f 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 -f Makefile &&
462 test -f README &&
463 test -f src/part1.c &&
464 test -f src/part2.c &&
465 test ! -f a.out &&
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 &&
471 test -f obj.o &&
472 test -f 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