t / t7300-clean.shon commit fmt-merge-msg: add '--(no-)log' options and 'merge.log' config variable (6cd9cfe)
   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 &&
  79        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
  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 docs/manual.txt &&
  88        test -f obj.o &&
  89        test -f build/lib.so
  90
  91'
  92
  93test_expect_success 'git-clean with relative prefix' '
  94
  95        mkdir -p build docs &&
  96        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
  97        would_clean=$(
  98                cd docs &&
  99                git clean -n ../src |
 100                sed -n -e "s|^Would remove ||p"
 101        ) &&
 102        test "$would_clean" = ../src/part3.c || {
 103                echo "OOps <$would_clean>"
 104                false
 105        }
 106'
 107
 108test_expect_success 'git-clean with absolute path' '
 109
 110        mkdir -p build docs &&
 111        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 112        would_clean=$(
 113                cd docs &&
 114                git clean -n $(pwd)/../src |
 115                sed -n -e "s|^Would remove ||p"
 116        ) &&
 117        test "$would_clean" = ../src/part3.c || {
 118                echo "OOps <$would_clean>"
 119                false
 120        }
 121'
 122
 123test_expect_success 'git-clean with out of work tree relative path' '
 124
 125        mkdir -p build docs &&
 126        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 127        (
 128                cd docs &&
 129                test_must_fail git clean -n ../..
 130        )
 131'
 132
 133test_expect_success 'git-clean with out of work tree absolute path' '
 134
 135        mkdir -p build docs &&
 136        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 137        dd=$(cd .. && pwd) &&
 138        (
 139                cd docs &&
 140                test_must_fail git clean -n $dd
 141        )
 142'
 143
 144test_expect_success 'git-clean -d with prefix and path' '
 145
 146        mkdir -p build docs src/feature &&
 147        touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
 148        (cd src/ && git-clean -d feature/) &&
 149        test -f Makefile &&
 150        test -f README &&
 151        test -f src/part1.c &&
 152        test -f src/part2.c &&
 153        test -f a.out &&
 154        test -f src/part3.c &&
 155        test ! -f src/feature/file.c &&
 156        test -f docs/manual.txt &&
 157        test -f obj.o &&
 158        test -f build/lib.so
 159
 160'
 161
 162test_expect_success 'git-clean symbolic link' '
 163
 164        mkdir -p build docs &&
 165        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 166        ln -s docs/manual.txt src/part4.c
 167        git-clean &&
 168        test -f Makefile &&
 169        test -f README &&
 170        test -f src/part1.c &&
 171        test -f src/part2.c &&
 172        test ! -f a.out &&
 173        test ! -f src/part3.c &&
 174        test ! -f src/part4.c &&
 175        test -f docs/manual.txt &&
 176        test -f obj.o &&
 177        test -f build/lib.so
 178
 179'
 180
 181test_expect_success 'git-clean with wildcard' '
 182
 183        touch a.clean b.clean other.c &&
 184        git-clean "*.clean" &&
 185        test -f Makefile &&
 186        test -f README &&
 187        test -f src/part1.c &&
 188        test -f src/part2.c &&
 189        test ! -f a.clean &&
 190        test ! -f b.clean &&
 191        test -f other.c
 192
 193'
 194
 195test_expect_success 'git-clean -n' '
 196
 197        mkdir -p build docs &&
 198        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 199        git-clean -n &&
 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 src/part3.c &&
 206        test -f docs/manual.txt &&
 207        test -f obj.o &&
 208        test -f build/lib.so
 209
 210'
 211
 212test_expect_success 'git-clean -d' '
 213
 214        mkdir -p build docs &&
 215        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 216        git-clean -d &&
 217        test -f Makefile &&
 218        test -f README &&
 219        test -f src/part1.c &&
 220        test -f src/part2.c &&
 221        test ! -f a.out &&
 222        test ! -f src/part3.c &&
 223        test ! -d docs &&
 224        test -f obj.o &&
 225        test -f build/lib.so
 226
 227'
 228
 229test_expect_success 'git-clean -d src/ examples/' '
 230
 231        mkdir -p build docs examples &&
 232        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
 233        git-clean -d src/ examples/ &&
 234        test -f Makefile &&
 235        test -f README &&
 236        test -f src/part1.c &&
 237        test -f src/part2.c &&
 238        test -f a.out &&
 239        test ! -f src/part3.c &&
 240        test ! -f examples/1.c &&
 241        test -f docs/manual.txt &&
 242        test -f obj.o &&
 243        test -f build/lib.so
 244
 245'
 246
 247test_expect_success 'git-clean -x' '
 248
 249        mkdir -p build docs &&
 250        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 251        git-clean -x &&
 252        test -f Makefile &&
 253        test -f README &&
 254        test -f src/part1.c &&
 255        test -f src/part2.c &&
 256        test ! -f a.out &&
 257        test ! -f src/part3.c &&
 258        test -f docs/manual.txt &&
 259        test ! -f obj.o &&
 260        test -f build/lib.so
 261
 262'
 263
 264test_expect_success 'git-clean -d -x' '
 265
 266        mkdir -p build docs &&
 267        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 268        git-clean -d -x &&
 269        test -f Makefile &&
 270        test -f README &&
 271        test -f src/part1.c &&
 272        test -f src/part2.c &&
 273        test ! -f a.out &&
 274        test ! -f src/part3.c &&
 275        test ! -d docs &&
 276        test ! -f obj.o &&
 277        test ! -d build
 278
 279'
 280
 281test_expect_success 'git-clean -X' '
 282
 283        mkdir -p build docs &&
 284        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 285        git-clean -X &&
 286        test -f Makefile &&
 287        test -f README &&
 288        test -f src/part1.c &&
 289        test -f src/part2.c &&
 290        test -f a.out &&
 291        test -f src/part3.c &&
 292        test -f docs/manual.txt &&
 293        test ! -f obj.o &&
 294        test -f build/lib.so
 295
 296'
 297
 298test_expect_success 'git-clean -d -X' '
 299
 300        mkdir -p build docs &&
 301        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 302        git-clean -d -X &&
 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 docs/manual.txt &&
 310        test ! -f obj.o &&
 311        test ! -d build
 312
 313'
 314
 315test_expect_success 'clean.requireForce defaults to true' '
 316
 317        git config --unset clean.requireForce &&
 318        ! git-clean
 319
 320'
 321
 322test_expect_success 'clean.requireForce' '
 323
 324        git config clean.requireForce true &&
 325        ! git-clean
 326
 327'
 328
 329test_expect_success 'clean.requireForce and -n' '
 330
 331        mkdir -p build docs &&
 332        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 333        git-clean -n &&
 334        test -f Makefile &&
 335        test -f README &&
 336        test -f src/part1.c &&
 337        test -f src/part2.c &&
 338        test -f a.out &&
 339        test -f src/part3.c &&
 340        test -f docs/manual.txt &&
 341        test -f obj.o &&
 342        test -f build/lib.so
 343
 344'
 345
 346test_expect_success 'clean.requireForce and -f' '
 347
 348        git-clean -f &&
 349        test -f README &&
 350        test -f src/part1.c &&
 351        test -f src/part2.c &&
 352        test ! -f a.out &&
 353        test ! -f src/part3.c &&
 354        test -f docs/manual.txt &&
 355        test -f obj.o &&
 356        test -f build/lib.so
 357
 358'
 359
 360test_expect_success 'core.excludesfile' '
 361
 362        echo excludes >excludes &&
 363        echo included >included &&
 364        git config core.excludesfile excludes &&
 365        output=$(git clean -n excludes included 2>&1) &&
 366        expr "$output" : ".*included" >/dev/null &&
 367        ! expr "$output" : ".*excludes" >/dev/null
 368
 369'
 370
 371test_expect_success 'removal failure' '
 372
 373        mkdir foo &&
 374        touch foo/bar &&
 375        exec <foo/bar &&
 376        chmod 0 foo &&
 377        test_must_fail git clean -f -d
 378
 379'
 380chmod 755 foo
 381
 382test_done