t / t7301-clean-interactive.shon commit Merge branch 'pt/t0302-needs-sanity' (b3689ce)
   1#!/bin/sh
   2
   3test_description='git clean -i basic tests'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8
   9        mkdir -p src &&
  10        touch src/part1.c Makefile &&
  11        echo build >.gitignore &&
  12        echo \*.o >>.gitignore &&
  13        git add . &&
  14        git commit -m setup &&
  15        touch src/part2.c README &&
  16        git add .
  17
  18'
  19
  20test_expect_success 'git clean -i (c: clean hotkey)' '
  21
  22        mkdir -p build docs &&
  23        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
  24        docs/manual.txt obj.o build/lib.so &&
  25        echo c | git clean -i &&
  26        test -f Makefile &&
  27        test -f README &&
  28        test -f src/part1.c &&
  29        test -f src/part2.c &&
  30        test ! -f a.out &&
  31        test -f docs/manual.txt &&
  32        test ! -f src/part3.c &&
  33        test ! -f src/part3.h &&
  34        test ! -f src/part4.c &&
  35        test ! -f src/part4.h &&
  36        test -f obj.o &&
  37        test -f build/lib.so
  38
  39'
  40
  41test_expect_success 'git clean -i (cl: clean prefix)' '
  42
  43        mkdir -p build docs &&
  44        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
  45        docs/manual.txt obj.o build/lib.so &&
  46        echo cl | git clean -i &&
  47        test -f Makefile &&
  48        test -f README &&
  49        test -f src/part1.c &&
  50        test -f src/part2.c &&
  51        test ! -f a.out &&
  52        test -f docs/manual.txt &&
  53        test ! -f src/part3.c &&
  54        test ! -f src/part3.h &&
  55        test ! -f src/part4.c &&
  56        test ! -f src/part4.h &&
  57        test -f obj.o &&
  58        test -f build/lib.so
  59
  60'
  61
  62test_expect_success 'git clean -i (quit)' '
  63
  64        mkdir -p build docs &&
  65        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
  66        docs/manual.txt obj.o build/lib.so &&
  67        echo quit | git clean -i &&
  68        test -f Makefile &&
  69        test -f README &&
  70        test -f src/part1.c &&
  71        test -f src/part2.c &&
  72        test -f a.out &&
  73        test -f docs/manual.txt &&
  74        test -f src/part3.c &&
  75        test -f src/part3.h &&
  76        test -f src/part4.c &&
  77        test -f src/part4.h &&
  78        test -f obj.o &&
  79        test -f build/lib.so
  80
  81'
  82
  83test_expect_success 'git clean -i (Ctrl+D)' '
  84
  85        mkdir -p build docs &&
  86        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
  87        docs/manual.txt obj.o build/lib.so &&
  88        echo "\04" | git clean -i &&
  89        test -f Makefile &&
  90        test -f README &&
  91        test -f src/part1.c &&
  92        test -f src/part2.c &&
  93        test -f a.out &&
  94        test -f docs/manual.txt &&
  95        test -f src/part3.c &&
  96        test -f src/part3.h &&
  97        test -f src/part4.c &&
  98        test -f src/part4.h &&
  99        test -f obj.o &&
 100        test -f build/lib.so
 101
 102'
 103
 104test_expect_success 'git clean -id (filter all)' '
 105
 106        mkdir -p build docs &&
 107        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 108        docs/manual.txt obj.o build/lib.so &&
 109        (echo f; echo "*"; echo; echo c) | \
 110        git clean -id &&
 111        test -f Makefile &&
 112        test -f README &&
 113        test -f src/part1.c &&
 114        test -f src/part2.c &&
 115        test -f a.out &&
 116        test -f docs/manual.txt &&
 117        test -f src/part3.c &&
 118        test -f src/part3.h &&
 119        test -f src/part4.c &&
 120        test -f src/part4.h &&
 121        test -f obj.o &&
 122        test -f build/lib.so
 123
 124'
 125
 126test_expect_success 'git clean -id (filter patterns)' '
 127
 128        mkdir -p build docs &&
 129        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 130        docs/manual.txt obj.o build/lib.so &&
 131        (echo f; echo "part3.* *.out"; echo; echo c) | \
 132        git clean -id &&
 133        test -f Makefile &&
 134        test -f README &&
 135        test -f src/part1.c &&
 136        test -f src/part2.c &&
 137        test -f a.out &&
 138        test ! -f docs/manual.txt &&
 139        test -f src/part3.c &&
 140        test -f src/part3.h &&
 141        test ! -f src/part4.c &&
 142        test ! -f src/part4.h &&
 143        test -f obj.o &&
 144        test -f build/lib.so
 145
 146'
 147
 148test_expect_success 'git clean -id (filter patterns 2)' '
 149
 150        mkdir -p build docs &&
 151        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 152        docs/manual.txt obj.o build/lib.so &&
 153        (echo f; echo "* !*.out"; echo; echo c) | \
 154        git clean -id &&
 155        test -f Makefile &&
 156        test -f README &&
 157        test -f src/part1.c &&
 158        test -f src/part2.c &&
 159        test ! -f a.out &&
 160        test -f docs/manual.txt &&
 161        test -f src/part3.c &&
 162        test -f src/part3.h &&
 163        test -f src/part4.c &&
 164        test -f src/part4.h &&
 165        test -f obj.o &&
 166        test -f build/lib.so
 167
 168'
 169
 170test_expect_success 'git clean -id (select - all)' '
 171
 172        mkdir -p build docs &&
 173        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 174        docs/manual.txt obj.o build/lib.so &&
 175        (echo s; echo "*"; echo; echo c) | \
 176        git clean -id &&
 177        test -f Makefile &&
 178        test -f README &&
 179        test -f src/part1.c &&
 180        test -f src/part2.c &&
 181        test ! -f a.out &&
 182        test ! -f docs/manual.txt &&
 183        test ! -f src/part3.c &&
 184        test ! -f src/part3.h &&
 185        test ! -f src/part4.c &&
 186        test ! -f src/part4.h &&
 187        test -f obj.o &&
 188        test -f build/lib.so
 189
 190'
 191
 192test_expect_success 'git clean -id (select - none)' '
 193
 194        mkdir -p build docs &&
 195        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 196        docs/manual.txt obj.o build/lib.so &&
 197        (echo s; echo; echo c) | \
 198        git clean -id &&
 199        test -f Makefile &&
 200        test -f README &&
 201        test -f src/part1.c &&
 202        test -f src/part2.c &&
 203        test -f a.out &&
 204        test -f docs/manual.txt &&
 205        test -f src/part3.c &&
 206        test -f src/part3.h &&
 207        test -f src/part4.c &&
 208        test -f src/part4.h &&
 209        test -f obj.o &&
 210        test -f build/lib.so
 211
 212'
 213
 214test_expect_success 'git clean -id (select - number)' '
 215
 216        mkdir -p build docs &&
 217        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 218        docs/manual.txt obj.o build/lib.so &&
 219        (echo s; echo 3; echo; echo c) | \
 220        git clean -id &&
 221        test -f Makefile &&
 222        test -f README &&
 223        test -f src/part1.c &&
 224        test -f src/part2.c &&
 225        test -f a.out &&
 226        test -f docs/manual.txt &&
 227        test ! -f src/part3.c &&
 228        test -f src/part3.h &&
 229        test -f src/part4.c &&
 230        test -f src/part4.h &&
 231        test -f obj.o &&
 232        test -f build/lib.so
 233
 234'
 235
 236test_expect_success 'git clean -id (select - number 2)' '
 237
 238        mkdir -p build docs &&
 239        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 240        docs/manual.txt obj.o build/lib.so &&
 241        (echo s; echo 2 3; echo 5; echo; echo c) | \
 242        git clean -id &&
 243        test -f Makefile &&
 244        test -f README &&
 245        test -f src/part1.c &&
 246        test -f src/part2.c &&
 247        test -f a.out &&
 248        test ! -f docs/manual.txt &&
 249        test ! -f src/part3.c &&
 250        test -f src/part3.h &&
 251        test ! -f src/part4.c &&
 252        test -f src/part4.h &&
 253        test -f obj.o &&
 254        test -f build/lib.so
 255
 256'
 257
 258test_expect_success 'git clean -id (select - number 3)' '
 259
 260        mkdir -p build docs &&
 261        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 262        docs/manual.txt obj.o build/lib.so &&
 263        (echo s; echo 3,4 5; echo; echo c) | \
 264        git clean -id &&
 265        test -f Makefile &&
 266        test -f README &&
 267        test -f src/part1.c &&
 268        test -f src/part2.c &&
 269        test -f a.out &&
 270        test -f docs/manual.txt &&
 271        test ! -f src/part3.c &&
 272        test ! -f src/part3.h &&
 273        test ! -f src/part4.c &&
 274        test -f src/part4.h &&
 275        test -f obj.o &&
 276        test -f build/lib.so
 277
 278'
 279
 280test_expect_success 'git clean -id (select - filenames)' '
 281
 282        mkdir -p build docs &&
 283        touch a.out foo.txt bar.txt baz.txt &&
 284        (echo s; echo a.out fo ba bar; echo; echo c) | \
 285        git clean -id &&
 286        test -f Makefile &&
 287        test ! -f a.out &&
 288        test ! -f foo.txt &&
 289        test ! -f bar.txt &&
 290        test -f baz.txt &&
 291        rm baz.txt
 292
 293'
 294
 295test_expect_success 'git clean -id (select - range)' '
 296
 297        mkdir -p build docs &&
 298        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 299        docs/manual.txt obj.o build/lib.so &&
 300        (echo s; echo 1,3-4; echo 2; echo; echo c) | \
 301        git clean -id &&
 302        test -f Makefile &&
 303        test -f README &&
 304        test -f src/part1.c &&
 305        test -f src/part2.c &&
 306        test ! -f a.out &&
 307        test ! -f src/part3.c &&
 308        test ! -f src/part3.h &&
 309        test -f src/part4.c &&
 310        test -f src/part4.h &&
 311        test ! -f docs/manual.txt &&
 312        test -f obj.o &&
 313        test -f build/lib.so
 314
 315'
 316
 317test_expect_success 'git clean -id (select - range 2)' '
 318
 319        mkdir -p build docs &&
 320        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 321        docs/manual.txt obj.o build/lib.so &&
 322        (echo s; echo 4- 1; echo; echo c) | \
 323        git clean -id &&
 324        test -f Makefile &&
 325        test -f README &&
 326        test -f src/part1.c &&
 327        test -f src/part2.c &&
 328        test ! -f a.out &&
 329        test -f docs/manual.txt &&
 330        test -f src/part3.c &&
 331        test ! -f src/part3.h &&
 332        test ! -f src/part4.c &&
 333        test ! -f src/part4.h &&
 334        test -f obj.o &&
 335        test -f build/lib.so
 336
 337'
 338
 339test_expect_success 'git clean -id (inverse select)' '
 340
 341        mkdir -p build docs &&
 342        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 343        docs/manual.txt obj.o build/lib.so &&
 344        (echo s; echo "*"; echo -5- 1 -2; echo; echo c) | \
 345        git clean -id &&
 346        test -f Makefile &&
 347        test -f README &&
 348        test -f src/part1.c &&
 349        test -f src/part2.c &&
 350        test ! -f a.out &&
 351        test -f docs/manual.txt &&
 352        test ! -f src/part3.c &&
 353        test ! -f src/part3.h &&
 354        test -f src/part4.c &&
 355        test -f src/part4.h &&
 356        test -f obj.o &&
 357        test -f build/lib.so
 358
 359'
 360
 361test_expect_success 'git clean -id (ask)' '
 362
 363        mkdir -p build docs &&
 364        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 365        docs/manual.txt obj.o build/lib.so &&
 366        (echo a; echo Y; echo y; echo no; echo yes; echo bad; echo) | \
 367        git clean -id &&
 368        test -f Makefile &&
 369        test -f README &&
 370        test -f src/part1.c &&
 371        test -f src/part2.c &&
 372        test ! -f a.out &&
 373        test ! -f docs/manual.txt &&
 374        test -f src/part3.c &&
 375        test ! -f src/part3.h &&
 376        test -f src/part4.c &&
 377        test -f src/part4.h &&
 378        test -f obj.o &&
 379        test -f build/lib.so
 380
 381'
 382
 383test_expect_success 'git clean -id (ask - Ctrl+D)' '
 384
 385        mkdir -p build docs &&
 386        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 387        docs/manual.txt obj.o build/lib.so &&
 388        (echo a; echo Y; echo no; echo yes; echo "\04") | \
 389        git clean -id &&
 390        test -f Makefile &&
 391        test -f README &&
 392        test -f src/part1.c &&
 393        test -f src/part2.c &&
 394        test ! -f a.out &&
 395        test -f docs/manual.txt &&
 396        test ! -f src/part3.c &&
 397        test -f src/part3.h &&
 398        test -f src/part4.c &&
 399        test -f src/part4.h &&
 400        test -f obj.o &&
 401        test -f build/lib.so
 402
 403'
 404
 405test_expect_success 'git clean -id with prefix and path (filter)' '
 406
 407        mkdir -p build docs &&
 408        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 409        docs/manual.txt obj.o build/lib.so &&
 410        (cd build/ && \
 411         (echo f; echo "docs"; echo "*.h"; echo ; echo c) | \
 412         git clean -id ..) &&
 413        test -f Makefile &&
 414        test -f README &&
 415        test -f src/part1.c &&
 416        test -f src/part2.c &&
 417        test ! -f a.out &&
 418        test -f docs/manual.txt &&
 419        test ! -f src/part3.c &&
 420        test -f src/part3.h &&
 421        test ! -f src/part4.c &&
 422        test -f src/part4.h &&
 423        test -f obj.o &&
 424        test -f build/lib.so
 425
 426'
 427
 428test_expect_success 'git clean -id with prefix and path (select by name)' '
 429
 430        mkdir -p build docs &&
 431        touch a.out src/part3.c src/part3.h src/part4.c src/part4.h \
 432        docs/manual.txt obj.o build/lib.so &&
 433        (cd build/ && \
 434         (echo s; echo "../docs/"; echo "../src/part3.c"; \
 435          echo "../src/part4.c";  echo; echo 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         (echo a; echo Y; echo y; echo no; echo yes; echo bad; echo) | \
 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_done