t / t7301-clean-interactive.shon commit Merge branch 'master' of https://github.com/vnwildman/git (26a567e)
   1#!/bin/sh
   2
   3test_description='git clean -i basic tests'
   4
   5. ./test-lib.sh
   6. "$TEST_DIRECTORY"/lib-terminal.sh
   7
   8test_expect_success 'setup' '
   9
  10        mkdir -p src &&
  11        touch src/part1.c Makefile &&
  12        echo build >.gitignore &&
  13        echo \*.o >>.gitignore &&
  14        git add . &&
  15        git commit -m setup &&
  16        touch src/part2.c README &&
  17        git add .
  18
  19'
  20
  21test_expect_success 'git clean -i (c: clean hotkey)' '
  22
  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 &&
  27        test -f Makefile &&
  28        test -f README &&
  29        test -f src/part1.c &&
  30        test -f src/part2.c &&
  31        test ! -f a.out &&
  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 &&
  37        test -f obj.o &&
  38        test -f build/lib.so
  39
  40'
  41
  42test_expect_success 'git clean -i (cl: clean prefix)' '
  43
  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 &&
  48        test -f Makefile &&
  49        test -f README &&
  50        test -f src/part1.c &&
  51        test -f src/part2.c &&
  52        test ! -f a.out &&
  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 &&
  58        test -f obj.o &&
  59        test -f build/lib.so
  60
  61'
  62
  63test_expect_success 'git clean -i (quit)' '
  64
  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 &&
  69        test -f Makefile &&
  70        test -f README &&
  71        test -f src/part1.c &&
  72        test -f src/part2.c &&
  73        test -f a.out &&
  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 &&
  79        test -f obj.o &&
  80        test -f build/lib.so
  81
  82'
  83
  84test_expect_success 'git clean -i (Ctrl+D)' '
  85
  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 &&
  90        test -f Makefile &&
  91        test -f README &&
  92        test -f src/part1.c &&
  93        test -f src/part2.c &&
  94        test -f a.out &&
  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 &&
 100        test -f obj.o &&
 101        test -f build/lib.so
 102
 103'
 104
 105test_expect_success 'git clean -id (filter all)' '
 106
 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 |
 111        git clean -id &&
 112        test -f Makefile &&
 113        test -f README &&
 114        test -f src/part1.c &&
 115        test -f src/part2.c &&
 116        test -f a.out &&
 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 &&
 122        test -f obj.o &&
 123        test -f build/lib.so
 124
 125'
 126
 127test_expect_success 'git clean -id (filter patterns)' '
 128
 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 |
 133        git clean -id &&
 134        test -f Makefile &&
 135        test -f README &&
 136        test -f src/part1.c &&
 137        test -f src/part2.c &&
 138        test -f a.out &&
 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 &&
 144        test -f obj.o &&
 145        test -f build/lib.so
 146
 147'
 148
 149test_expect_success 'git clean -id (filter patterns 2)' '
 150
 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 |
 155        git clean -id &&
 156        test -f Makefile &&
 157        test -f README &&
 158        test -f src/part1.c &&
 159        test -f src/part2.c &&
 160        test ! -f a.out &&
 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 &&
 166        test -f obj.o &&
 167        test -f build/lib.so
 168
 169'
 170
 171test_expect_success 'git clean -id (select - all)' '
 172
 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 |
 177        git clean -id &&
 178        test -f Makefile &&
 179        test -f README &&
 180        test -f src/part1.c &&
 181        test -f src/part2.c &&
 182        test ! -f a.out &&
 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 &&
 188        test -f obj.o &&
 189        test -f build/lib.so
 190
 191'
 192
 193test_expect_success 'git clean -id (select - none)' '
 194
 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 |
 199        git clean -id &&
 200        test -f Makefile &&
 201        test -f README &&
 202        test -f src/part1.c &&
 203        test -f src/part2.c &&
 204        test -f a.out &&
 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 &&
 210        test -f obj.o &&
 211        test -f build/lib.so
 212
 213'
 214
 215test_expect_success 'git clean -id (select - number)' '
 216
 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 |
 221        git clean -id &&
 222        test -f Makefile &&
 223        test -f README &&
 224        test -f src/part1.c &&
 225        test -f src/part2.c &&
 226        test -f a.out &&
 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 &&
 232        test -f obj.o &&
 233        test -f build/lib.so
 234
 235'
 236
 237test_expect_success 'git clean -id (select - number 2)' '
 238
 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 |
 243        git clean -id &&
 244        test -f Makefile &&
 245        test -f README &&
 246        test -f src/part1.c &&
 247        test -f src/part2.c &&
 248        test -f a.out &&
 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 &&
 254        test -f obj.o &&
 255        test -f build/lib.so
 256
 257'
 258
 259test_expect_success 'git clean -id (select - number 3)' '
 260
 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 |
 265        git clean -id &&
 266        test -f Makefile &&
 267        test -f README &&
 268        test -f src/part1.c &&
 269        test -f src/part2.c &&
 270        test -f a.out &&
 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 &&
 276        test -f obj.o &&
 277        test -f build/lib.so
 278
 279'
 280
 281test_expect_success 'git clean -id (select - filenames)' '
 282
 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 |
 286        git clean -id &&
 287        test -f Makefile &&
 288        test ! -f a.out &&
 289        test ! -f foo.txt &&
 290        test ! -f bar.txt &&
 291        test -f baz.txt &&
 292        rm baz.txt
 293
 294'
 295
 296test_expect_success 'git clean -id (select - range)' '
 297
 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 |
 302        git clean -id &&
 303        test -f Makefile &&
 304        test -f README &&
 305        test -f src/part1.c &&
 306        test -f src/part2.c &&
 307        test ! -f a.out &&
 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 &&
 313        test -f obj.o &&
 314        test -f build/lib.so
 315
 316'
 317
 318test_expect_success 'git clean -id (select - range 2)' '
 319
 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 |
 324        git clean -id &&
 325        test -f Makefile &&
 326        test -f README &&
 327        test -f src/part1.c &&
 328        test -f src/part2.c &&
 329        test ! -f a.out &&
 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 &&
 335        test -f obj.o &&
 336        test -f build/lib.so
 337
 338'
 339
 340test_expect_success 'git clean -id (inverse select)' '
 341
 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 |
 346        git clean -id &&
 347        test -f Makefile &&
 348        test -f README &&
 349        test -f src/part1.c &&
 350        test -f src/part2.c &&
 351        test ! -f a.out &&
 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 &&
 357        test -f obj.o &&
 358        test -f build/lib.so
 359
 360'
 361
 362test_expect_success 'git clean -id (ask)' '
 363
 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 "" |
 368        git clean -id &&
 369        test -f Makefile &&
 370        test -f README &&
 371        test -f src/part1.c &&
 372        test -f src/part2.c &&
 373        test ! -f a.out &&
 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 &&
 379        test -f obj.o &&
 380        test -f build/lib.so
 381
 382'
 383
 384test_expect_success 'git clean -id (ask - Ctrl+D)' '
 385
 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" |
 390        git clean -id &&
 391        test -f Makefile &&
 392        test -f README &&
 393        test -f src/part1.c &&
 394        test -f src/part2.c &&
 395        test ! -f a.out &&
 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 &&
 401        test -f obj.o &&
 402        test -f build/lib.so
 403
 404'
 405
 406test_expect_success 'git clean -id with prefix and path (filter)' '
 407
 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 &&
 411        (cd build/ &&
 412         test_write_lines f docs "*.h" "" c |
 413         git clean -id ..) &&
 414        test -f Makefile &&
 415        test -f README &&
 416        test -f src/part1.c &&
 417        test -f src/part2.c &&
 418        test ! -f a.out &&
 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 &&
 424        test -f obj.o &&
 425        test -f build/lib.so
 426
 427'
 428
 429test_expect_success 'git clean -id with prefix and path (select by name)' '
 430
 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 &&
 434        (cd build/ &&
 435         test_write_lines s ../docs/ ../src/part3.c ../src/part4.c "" c |
 436         git clean -id ..) &&
 437        test -f Makefile &&
 438        test -f README &&
 439        test -f src/part1.c &&
 440        test -f src/part2.c &&
 441        test -f a.out &&
 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 &&
 447        test -f obj.o &&
 448        test -f build/lib.so
 449
 450'
 451
 452test_expect_success 'git clean -id with prefix and path (ask)' '
 453
 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 &&
 457        (cd build/ &&
 458         test_write_lines a Y y no yes bad "" |
 459         git clean -id ..) &&
 460        test -f Makefile &&
 461        test -f README &&
 462        test -f src/part1.c &&
 463        test -f src/part2.c &&
 464        test ! -f a.out &&
 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 &&
 470        test -f obj.o &&
 471        test -f build/lib.so
 472
 473'
 474
 475test_expect_success TTY 'git clean -i paints the header in HEADER color' '
 476        >a.out &&
 477        echo q |
 478        test_terminal git clean -i |
 479        test_decode_color |
 480        head -n 1 >header &&
 481        # not i18ngrep
 482        grep "^<BOLD>" header
 483'
 484
 485test_done