t / t7300-clean.shon commit Merge branch 'js/valgrind' (8a61097)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Michael Spang
   4#
   5
   6test_description='git clean basic tests'
   7
   8. ./test-lib.sh
   9
  10git config clean.requireForce no
  11
  12test_expect_success 'setup' '
  13
  14        mkdir -p src &&
  15        touch src/part1.c Makefile &&
  16        echo build >.gitignore &&
  17        echo \*.o >>.gitignore &&
  18        git add . &&
  19        git commit -m setup &&
  20        touch src/part2.c README &&
  21        git add .
  22
  23'
  24
  25test_expect_success 'git clean' '
  26
  27        mkdir -p build docs &&
  28        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
  29        git clean &&
  30        test -f Makefile &&
  31        test -f README &&
  32        test -f src/part1.c &&
  33        test -f src/part2.c &&
  34        test ! -f a.out &&
  35        test ! -f src/part3.c &&
  36        test -f docs/manual.txt &&
  37        test -f obj.o &&
  38        test -f build/lib.so
  39
  40'
  41
  42test_expect_success 'git clean src/' '
  43
  44        mkdir -p build docs &&
  45        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
  46        git clean src/ &&
  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 src/part3.c &&
  53        test -f docs/manual.txt &&
  54        test -f obj.o &&
  55        test -f build/lib.so
  56
  57'
  58
  59test_expect_success 'git clean src/ src/' '
  60
  61        mkdir -p build docs &&
  62        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
  63        git clean src/ src/ &&
  64        test -f Makefile &&
  65        test -f README &&
  66        test -f src/part1.c &&
  67        test -f src/part2.c &&
  68        test -f a.out &&
  69        test ! -f src/part3.c &&
  70        test -f docs/manual.txt &&
  71        test -f obj.o &&
  72        test -f build/lib.so
  73
  74'
  75
  76test_expect_success 'git clean with prefix' '
  77
  78        mkdir -p build docs src/test &&
  79        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c &&
  80        (cd src/ && git clean) &&
  81        test -f Makefile &&
  82        test -f README &&
  83        test -f src/part1.c &&
  84        test -f src/part2.c &&
  85        test -f a.out &&
  86        test ! -f src/part3.c &&
  87        test -f src/test/1.c &&
  88        test -f docs/manual.txt &&
  89        test -f obj.o &&
  90        test -f build/lib.so
  91
  92'
  93
  94test_expect_success 'git clean with relative prefix' '
  95
  96        mkdir -p build docs &&
  97        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
  98        would_clean=$(
  99                cd docs &&
 100                git clean -n ../src |
 101                sed -n -e "s|^Would remove ||p"
 102        ) &&
 103        test "$would_clean" = ../src/part3.c || {
 104                echo "OOps <$would_clean>"
 105                false
 106        }
 107'
 108
 109test_expect_success 'git clean with absolute path' '
 110
 111        mkdir -p build docs &&
 112        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 113        would_clean=$(
 114                cd docs &&
 115                git clean -n "$(pwd)/../src" |
 116                sed -n -e "s|^Would remove ||p"
 117        ) &&
 118        test "$would_clean" = ../src/part3.c || {
 119                echo "OOps <$would_clean>"
 120                false
 121        }
 122'
 123
 124test_expect_success 'git clean with out of work tree relative path' '
 125
 126        mkdir -p build docs &&
 127        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 128        (
 129                cd docs &&
 130                test_must_fail git clean -n ../..
 131        )
 132'
 133
 134test_expect_success 'git clean with out of work tree absolute path' '
 135
 136        mkdir -p build docs &&
 137        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 138        dd=$(cd .. && pwd) &&
 139        (
 140                cd docs &&
 141                test_must_fail git clean -n $dd
 142        )
 143'
 144
 145test_expect_success 'git clean -d with prefix and path' '
 146
 147        mkdir -p build docs src/feature &&
 148        touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
 149        (cd src/ && git clean -d feature/) &&
 150        test -f Makefile &&
 151        test -f README &&
 152        test -f src/part1.c &&
 153        test -f src/part2.c &&
 154        test -f a.out &&
 155        test -f src/part3.c &&
 156        test ! -f src/feature/file.c &&
 157        test -f docs/manual.txt &&
 158        test -f obj.o &&
 159        test -f build/lib.so
 160
 161'
 162
 163test_expect_success 'git clean symbolic link' '
 164
 165        mkdir -p build docs &&
 166        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 167        ln -s docs/manual.txt src/part4.c
 168        git clean &&
 169        test -f Makefile &&
 170        test -f README &&
 171        test -f src/part1.c &&
 172        test -f src/part2.c &&
 173        test ! -f a.out &&
 174        test ! -f src/part3.c &&
 175        test ! -f src/part4.c &&
 176        test -f docs/manual.txt &&
 177        test -f obj.o &&
 178        test -f build/lib.so
 179
 180'
 181
 182test_expect_success 'git clean with wildcard' '
 183
 184        touch a.clean b.clean other.c &&
 185        git clean "*.clean" &&
 186        test -f Makefile &&
 187        test -f README &&
 188        test -f src/part1.c &&
 189        test -f src/part2.c &&
 190        test ! -f a.clean &&
 191        test ! -f b.clean &&
 192        test -f other.c
 193
 194'
 195
 196test_expect_success 'git clean -n' '
 197
 198        mkdir -p build docs &&
 199        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 200        git clean -n &&
 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 src/part3.c &&
 207        test -f docs/manual.txt &&
 208        test -f obj.o &&
 209        test -f build/lib.so
 210
 211'
 212
 213test_expect_success 'git clean -d' '
 214
 215        mkdir -p build docs &&
 216        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 217        git clean -d &&
 218        test -f Makefile &&
 219        test -f README &&
 220        test -f src/part1.c &&
 221        test -f src/part2.c &&
 222        test ! -f a.out &&
 223        test ! -f src/part3.c &&
 224        test ! -d docs &&
 225        test -f obj.o &&
 226        test -f build/lib.so
 227
 228'
 229
 230test_expect_success 'git clean -d src/ examples/' '
 231
 232        mkdir -p build docs examples &&
 233        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
 234        git clean -d src/ examples/ &&
 235        test -f Makefile &&
 236        test -f README &&
 237        test -f src/part1.c &&
 238        test -f src/part2.c &&
 239        test -f a.out &&
 240        test ! -f src/part3.c &&
 241        test ! -f examples/1.c &&
 242        test -f docs/manual.txt &&
 243        test -f obj.o &&
 244        test -f build/lib.so
 245
 246'
 247
 248test_expect_success 'git clean -x' '
 249
 250        mkdir -p build docs &&
 251        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 252        git clean -x &&
 253        test -f Makefile &&
 254        test -f README &&
 255        test -f src/part1.c &&
 256        test -f src/part2.c &&
 257        test ! -f a.out &&
 258        test ! -f src/part3.c &&
 259        test -f docs/manual.txt &&
 260        test ! -f obj.o &&
 261        test -f build/lib.so
 262
 263'
 264
 265test_expect_success 'git clean -d -x' '
 266
 267        mkdir -p build docs &&
 268        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 269        git clean -d -x &&
 270        test -f Makefile &&
 271        test -f README &&
 272        test -f src/part1.c &&
 273        test -f src/part2.c &&
 274        test ! -f a.out &&
 275        test ! -f src/part3.c &&
 276        test ! -d docs &&
 277        test ! -f obj.o &&
 278        test ! -d build
 279
 280'
 281
 282test_expect_success 'git clean -X' '
 283
 284        mkdir -p build docs &&
 285        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 286        git clean -X &&
 287        test -f Makefile &&
 288        test -f README &&
 289        test -f src/part1.c &&
 290        test -f src/part2.c &&
 291        test -f a.out &&
 292        test -f src/part3.c &&
 293        test -f docs/manual.txt &&
 294        test ! -f obj.o &&
 295        test -f build/lib.so
 296
 297'
 298
 299test_expect_success 'git clean -d -X' '
 300
 301        mkdir -p build docs &&
 302        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 303        git clean -d -X &&
 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 docs/manual.txt &&
 311        test ! -f obj.o &&
 312        test ! -d build
 313
 314'
 315
 316test_expect_success 'clean.requireForce defaults to true' '
 317
 318        git config --unset clean.requireForce &&
 319        test_must_fail git clean
 320
 321'
 322
 323test_expect_success 'clean.requireForce' '
 324
 325        git config clean.requireForce true &&
 326        test_must_fail git clean
 327
 328'
 329
 330test_expect_success 'clean.requireForce and -n' '
 331
 332        mkdir -p build docs &&
 333        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 334        git clean -n &&
 335        test -f Makefile &&
 336        test -f README &&
 337        test -f src/part1.c &&
 338        test -f src/part2.c &&
 339        test -f a.out &&
 340        test -f src/part3.c &&
 341        test -f docs/manual.txt &&
 342        test -f obj.o &&
 343        test -f build/lib.so
 344
 345'
 346
 347test_expect_success 'clean.requireForce and -f' '
 348
 349        git clean -f &&
 350        test -f README &&
 351        test -f src/part1.c &&
 352        test -f src/part2.c &&
 353        test ! -f a.out &&
 354        test ! -f src/part3.c &&
 355        test -f docs/manual.txt &&
 356        test -f obj.o &&
 357        test -f build/lib.so
 358
 359'
 360
 361test_expect_success 'core.excludesfile' '
 362
 363        echo excludes >excludes &&
 364        echo included >included &&
 365        git config core.excludesfile excludes &&
 366        output=$(git clean -n excludes included 2>&1) &&
 367        expr "$output" : ".*included" >/dev/null &&
 368        ! expr "$output" : ".*excludes" >/dev/null
 369
 370'
 371
 372test_expect_success 'removal failure' '
 373
 374        mkdir foo &&
 375        touch foo/bar &&
 376        exec <foo/bar &&
 377        chmod 0 foo &&
 378        test_must_fail git clean -f -d
 379
 380'
 381chmod 755 foo
 382
 383test_done