t / t7300-clean.shon commit Merge branch 'maint' (ada59fc)
   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'
  92test_expect_success 'git-clean -d with prefix and path' '
  93
  94        mkdir -p build docs src/feature &&
  95        touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
  96        (cd src/ && git-clean -d feature/) &&
  97        test -f Makefile &&
  98        test -f README &&
  99        test -f src/part1.c &&
 100        test -f src/part2.c &&
 101        test -f a.out &&
 102        test -f src/part3.c &&
 103        test ! -f src/feature/file.c &&
 104        test -f docs/manual.txt &&
 105        test -f obj.o &&
 106        test -f build/lib.so
 107
 108'
 109
 110test_expect_success 'git-clean symbolic link' '
 111
 112        mkdir -p build docs &&
 113        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 114        ln -s docs/manual.txt src/part4.c
 115        git-clean &&
 116        test -f Makefile &&
 117        test -f README &&
 118        test -f src/part1.c &&
 119        test -f src/part2.c &&
 120        test ! -f a.out &&
 121        test ! -f src/part3.c &&
 122        test ! -f src/part4.c &&
 123        test -f docs/manual.txt &&
 124        test -f obj.o &&
 125        test -f build/lib.so
 126
 127'
 128
 129test_expect_success 'git-clean -n' '
 130
 131        mkdir -p build docs &&
 132        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 133        git-clean -n &&
 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 src/part3.c &&
 140        test -f docs/manual.txt &&
 141        test -f obj.o &&
 142        test -f build/lib.so
 143
 144'
 145
 146test_expect_success 'git-clean -d' '
 147
 148        mkdir -p build docs &&
 149        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 150        git-clean -d &&
 151        test -f Makefile &&
 152        test -f README &&
 153        test -f src/part1.c &&
 154        test -f src/part2.c &&
 155        test ! -f a.out &&
 156        test ! -f src/part3.c &&
 157        test ! -d docs &&
 158        test -f obj.o &&
 159        test -f build/lib.so
 160
 161'
 162
 163test_expect_success 'git-clean -d src/ examples/' '
 164
 165        mkdir -p build docs examples &&
 166        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
 167        git-clean -d src/ examples/ &&
 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 examples/1.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 -x' '
 182
 183        mkdir -p build docs &&
 184        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 185        git-clean -x &&
 186        test -f Makefile &&
 187        test -f README &&
 188        test -f src/part1.c &&
 189        test -f src/part2.c &&
 190        test ! -f a.out &&
 191        test ! -f src/part3.c &&
 192        test -f docs/manual.txt &&
 193        test ! -f obj.o &&
 194        test -f build/lib.so
 195
 196'
 197
 198test_expect_success 'git-clean -d -x' '
 199
 200        mkdir -p build docs &&
 201        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 202        git-clean -d -x &&
 203        test -f Makefile &&
 204        test -f README &&
 205        test -f src/part1.c &&
 206        test -f src/part2.c &&
 207        test ! -f a.out &&
 208        test ! -f src/part3.c &&
 209        test ! -d docs &&
 210        test ! -f obj.o &&
 211        test ! -d build
 212
 213'
 214
 215test_expect_success 'git-clean -X' '
 216
 217        mkdir -p build docs &&
 218        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 219        git-clean -X &&
 220        test -f Makefile &&
 221        test -f README &&
 222        test -f src/part1.c &&
 223        test -f src/part2.c &&
 224        test -f a.out &&
 225        test -f src/part3.c &&
 226        test -f docs/manual.txt &&
 227        test ! -f obj.o &&
 228        test -f build/lib.so
 229
 230'
 231
 232test_expect_success 'git-clean -d -X' '
 233
 234        mkdir -p build docs &&
 235        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 236        git-clean -d -X &&
 237        test -f Makefile &&
 238        test -f README &&
 239        test -f src/part1.c &&
 240        test -f src/part2.c &&
 241        test -f a.out &&
 242        test -f src/part3.c &&
 243        test -f docs/manual.txt &&
 244        test ! -f obj.o &&
 245        test ! -d build
 246
 247'
 248
 249test_expect_success 'clean.requireForce defaults to true' '
 250
 251        git config --unset clean.requireForce &&
 252        ! git-clean
 253
 254'
 255
 256test_expect_success 'clean.requireForce' '
 257
 258        git config clean.requireForce true &&
 259        ! git-clean
 260
 261'
 262
 263test_expect_success 'clean.requireForce and -n' '
 264
 265        mkdir -p build docs &&
 266        touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
 267        git-clean -n &&
 268        test -f Makefile &&
 269        test -f README &&
 270        test -f src/part1.c &&
 271        test -f src/part2.c &&
 272        test -f a.out &&
 273        test -f src/part3.c &&
 274        test -f docs/manual.txt &&
 275        test -f obj.o &&
 276        test -f build/lib.so
 277
 278'
 279
 280test_expect_success 'clean.requireForce and -f' '
 281
 282        git-clean -f &&
 283        test -f README &&
 284        test -f src/part1.c &&
 285        test -f src/part2.c &&
 286        test ! -f a.out &&
 287        test ! -f src/part3.c &&
 288        test -f docs/manual.txt &&
 289        test -f obj.o &&
 290        test -f build/lib.so
 291
 292'
 293
 294test_expect_success 'core.excludesfile' '
 295
 296        echo excludes >excludes &&
 297        echo included >included &&
 298        git config core.excludesfile excludes &&
 299        output=$(git clean -n excludes included 2>&1) &&
 300        expr "$output" : ".*included" >/dev/null &&
 301        ! expr "$output" : ".*excludes" >/dev/null
 302
 303'
 304
 305test_done