Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Michael Spang |
| 4 | # |
| 5 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 6 | test_description='git clean basic tests' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
Junio C Hamano | 562ca19 | 2007-11-01 17:32:04 -0700 | [diff] [blame] | 10 | git config clean.requireForce no |
| 11 | |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 12 | test_expect_success 'setup' ' |
| 13 | |
| 14 | mkdir -p src && |
| 15 | touch src/part1.c Makefile && |
| 16 | echo build >.gitignore && |
| 17 | echo \*.o >>.gitignore && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 18 | git add . && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 19 | git commit -m setup && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 20 | touch src/part2.c README && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 21 | git add . |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 22 | |
| 23 | ' |
| 24 | |
Nguyễn Thái Ngọc Duy | c28b3d6 | 2009-08-20 20:47:01 +0700 | [diff] [blame] | 25 | test_expect_success 'git clean with skip-worktree .gitignore' ' |
| 26 | git update-index --skip-worktree .gitignore && |
| 27 | rm .gitignore && |
| 28 | mkdir -p build docs && |
| 29 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 30 | git clean && |
| 31 | test -f Makefile && |
| 32 | test -f README && |
| 33 | test -f src/part1.c && |
| 34 | test -f src/part2.c && |
| 35 | test ! -f a.out && |
| 36 | test ! -f src/part3.c && |
| 37 | test -f docs/manual.txt && |
| 38 | test -f obj.o && |
| 39 | test -f build/lib.so && |
| 40 | git update-index --no-skip-worktree .gitignore && |
| 41 | git checkout .gitignore |
| 42 | ' |
| 43 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 44 | test_expect_success 'git clean' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 45 | |
| 46 | mkdir -p build docs && |
| 47 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 48 | git clean && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 49 | test -f Makefile && |
| 50 | test -f README && |
| 51 | test -f src/part1.c && |
| 52 | test -f src/part2.c && |
| 53 | test ! -f a.out && |
| 54 | test ! -f src/part3.c && |
| 55 | test -f docs/manual.txt && |
| 56 | test -f obj.o && |
| 57 | test -f build/lib.so |
| 58 | |
| 59 | ' |
| 60 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 61 | test_expect_success 'git clean src/' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 62 | |
| 63 | mkdir -p build docs && |
| 64 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 65 | git clean src/ && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 66 | test -f Makefile && |
| 67 | test -f README && |
| 68 | test -f src/part1.c && |
| 69 | test -f src/part2.c && |
| 70 | test -f a.out && |
| 71 | test ! -f src/part3.c && |
| 72 | test -f docs/manual.txt && |
| 73 | test -f obj.o && |
| 74 | test -f build/lib.so |
| 75 | |
| 76 | ' |
| 77 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 78 | test_expect_success 'git clean src/ src/' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 79 | |
| 80 | mkdir -p build docs && |
| 81 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 82 | git clean src/ src/ && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 83 | test -f Makefile && |
| 84 | test -f README && |
| 85 | test -f src/part1.c && |
| 86 | test -f src/part2.c && |
| 87 | test -f a.out && |
| 88 | test ! -f src/part3.c && |
| 89 | test -f docs/manual.txt && |
| 90 | test -f obj.o && |
| 91 | test -f build/lib.so |
| 92 | |
| 93 | ' |
| 94 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 95 | test_expect_success 'git clean with prefix' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 96 | |
Shawn Bohrer | 2b6f0b0 | 2008-04-13 18:49:38 -0500 | [diff] [blame] | 97 | mkdir -p build docs src/test && |
| 98 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 99 | (cd src/ && git clean) && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 100 | test -f Makefile && |
| 101 | test -f README && |
| 102 | test -f src/part1.c && |
| 103 | test -f src/part2.c && |
| 104 | test -f a.out && |
| 105 | test ! -f src/part3.c && |
Shawn Bohrer | 2b6f0b0 | 2008-04-13 18:49:38 -0500 | [diff] [blame] | 106 | test -f src/test/1.c && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 107 | test -f docs/manual.txt && |
| 108 | test -f obj.o && |
| 109 | test -f build/lib.so |
| 110 | |
| 111 | ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 112 | |
Ævar Arnfjörð Bjarmason | 2da57ad | 2011-02-22 23:42:21 +0000 | [diff] [blame] | 113 | test_expect_success C_LOCALE_OUTPUT 'git clean with relative prefix' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 114 | |
| 115 | mkdir -p build docs && |
| 116 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 117 | would_clean=$( |
| 118 | cd docs && |
| 119 | git clean -n ../src | |
| 120 | sed -n -e "s|^Would remove ||p" |
| 121 | ) && |
| 122 | test "$would_clean" = ../src/part3.c || { |
| 123 | echo "OOps <$would_clean>" |
| 124 | false |
| 125 | } |
| 126 | ' |
| 127 | |
Ævar Arnfjörð Bjarmason | 2da57ad | 2011-02-22 23:42:21 +0000 | [diff] [blame] | 128 | test_expect_success C_LOCALE_OUTPUT 'git clean with absolute path' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 129 | |
| 130 | mkdir -p build docs && |
| 131 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 132 | would_clean=$( |
| 133 | cd docs && |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 134 | git clean -n "$(pwd)/../src" | |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 135 | sed -n -e "s|^Would remove ||p" |
| 136 | ) && |
| 137 | test "$would_clean" = ../src/part3.c || { |
| 138 | echo "OOps <$would_clean>" |
| 139 | false |
| 140 | } |
| 141 | ' |
| 142 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 143 | test_expect_success 'git clean with out of work tree relative path' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 144 | |
| 145 | mkdir -p build docs && |
| 146 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 147 | ( |
| 148 | cd docs && |
| 149 | test_must_fail git clean -n ../.. |
| 150 | ) |
| 151 | ' |
| 152 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 153 | test_expect_success 'git clean with out of work tree absolute path' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 154 | |
| 155 | mkdir -p build docs && |
| 156 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 157 | dd=$(cd .. && pwd) && |
| 158 | ( |
| 159 | cd docs && |
| 160 | test_must_fail git clean -n $dd |
| 161 | ) |
| 162 | ' |
| 163 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 164 | test_expect_success 'git clean -d with prefix and path' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 165 | |
| 166 | mkdir -p build docs src/feature && |
| 167 | touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 168 | (cd src/ && git clean -d feature/) && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 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/feature/file.c && |
| 176 | test -f docs/manual.txt && |
| 177 | test -f obj.o && |
| 178 | test -f build/lib.so |
| 179 | |
| 180 | ' |
| 181 | |
Johannes Sixt | 7569c1f | 2010-11-25 09:03:39 +0100 | [diff] [blame] | 182 | test_expect_success SYMLINKS 'git clean symbolic link' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 183 | |
| 184 | mkdir -p build docs && |
| 185 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Jonathan Nieder | 2dec68c | 2010-10-31 02:30:58 -0500 | [diff] [blame] | 186 | ln -s docs/manual.txt src/part4.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 187 | git clean && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 188 | test -f Makefile && |
| 189 | test -f README && |
| 190 | test -f src/part1.c && |
| 191 | test -f src/part2.c && |
| 192 | test ! -f a.out && |
| 193 | test ! -f src/part3.c && |
| 194 | test ! -f src/part4.c && |
| 195 | test -f docs/manual.txt && |
| 196 | test -f obj.o && |
| 197 | test -f build/lib.so |
| 198 | |
| 199 | ' |
| 200 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 201 | test_expect_success 'git clean with wildcard' ' |
Jeff King | d3357ab | 2007-12-05 22:28:06 -0500 | [diff] [blame] | 202 | |
| 203 | touch a.clean b.clean other.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 204 | git clean "*.clean" && |
Jeff King | d3357ab | 2007-12-05 22:28:06 -0500 | [diff] [blame] | 205 | test -f Makefile && |
| 206 | test -f README && |
| 207 | test -f src/part1.c && |
| 208 | test -f src/part2.c && |
| 209 | test ! -f a.clean && |
| 210 | test ! -f b.clean && |
| 211 | test -f other.c |
| 212 | |
| 213 | ' |
| 214 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 215 | test_expect_success 'git clean -n' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 216 | |
| 217 | mkdir -p build docs && |
| 218 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 219 | git clean -n && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 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 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 232 | test_expect_success 'git clean -d' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 233 | |
| 234 | mkdir -p build docs && |
| 235 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 236 | git clean -d && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 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 ! -d docs && |
| 244 | test -f obj.o && |
| 245 | test -f build/lib.so |
| 246 | |
| 247 | ' |
| 248 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 249 | test_expect_success 'git clean -d src/ examples/' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 250 | |
| 251 | mkdir -p build docs examples && |
| 252 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 253 | git clean -d src/ examples/ && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 254 | test -f Makefile && |
| 255 | test -f README && |
| 256 | test -f src/part1.c && |
| 257 | test -f src/part2.c && |
| 258 | test -f a.out && |
| 259 | test ! -f src/part3.c && |
| 260 | test ! -f examples/1.c && |
| 261 | test -f docs/manual.txt && |
| 262 | test -f obj.o && |
| 263 | test -f build/lib.so |
| 264 | |
| 265 | ' |
| 266 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 267 | test_expect_success 'git clean -x' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 268 | |
| 269 | mkdir -p build docs && |
| 270 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 271 | git clean -x && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 272 | test -f Makefile && |
| 273 | test -f README && |
| 274 | test -f src/part1.c && |
| 275 | test -f src/part2.c && |
| 276 | test ! -f a.out && |
| 277 | test ! -f src/part3.c && |
| 278 | test -f docs/manual.txt && |
| 279 | test ! -f obj.o && |
| 280 | test -f build/lib.so |
| 281 | |
| 282 | ' |
| 283 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 284 | test_expect_success 'git clean -d -x' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 285 | |
| 286 | mkdir -p build docs && |
| 287 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 288 | git clean -d -x && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 289 | test -f Makefile && |
| 290 | test -f README && |
| 291 | test -f src/part1.c && |
| 292 | test -f src/part2.c && |
| 293 | test ! -f a.out && |
| 294 | test ! -f src/part3.c && |
| 295 | test ! -d docs && |
| 296 | test ! -f obj.o && |
| 297 | test ! -d build |
| 298 | |
| 299 | ' |
| 300 | |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 301 | test_expect_success 'git clean -d -x with ignored tracked directory' ' |
| 302 | |
| 303 | mkdir -p build docs && |
| 304 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 305 | git clean -d -x -e src && |
| 306 | test -f Makefile && |
| 307 | test -f README && |
| 308 | test -f src/part1.c && |
| 309 | test -f src/part2.c && |
| 310 | test ! -f a.out && |
| 311 | test -f src/part3.c && |
| 312 | test ! -d docs && |
| 313 | test ! -f obj.o && |
| 314 | test ! -d build |
| 315 | |
| 316 | ' |
| 317 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 318 | test_expect_success 'git clean -X' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 319 | |
| 320 | mkdir -p build docs && |
| 321 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 322 | git clean -X && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 323 | test -f Makefile && |
| 324 | test -f README && |
| 325 | test -f src/part1.c && |
| 326 | test -f src/part2.c && |
| 327 | test -f a.out && |
| 328 | test -f src/part3.c && |
| 329 | test -f docs/manual.txt && |
| 330 | test ! -f obj.o && |
| 331 | test -f build/lib.so |
| 332 | |
| 333 | ' |
| 334 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 335 | test_expect_success 'git clean -d -X' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 336 | |
| 337 | mkdir -p build docs && |
| 338 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 339 | git clean -d -X && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 340 | test -f Makefile && |
| 341 | test -f README && |
| 342 | test -f src/part1.c && |
| 343 | test -f src/part2.c && |
| 344 | test -f a.out && |
| 345 | test -f src/part3.c && |
| 346 | test -f docs/manual.txt && |
| 347 | test ! -f obj.o && |
| 348 | test ! -d build |
| 349 | |
| 350 | ' |
| 351 | |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 352 | test_expect_success 'git clean -d -X with ignored tracked directory' ' |
| 353 | |
| 354 | mkdir -p build docs && |
| 355 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 356 | git clean -d -X -e src && |
| 357 | test -f Makefile && |
| 358 | test -f README && |
| 359 | test -f src/part1.c && |
| 360 | test -f src/part2.c && |
| 361 | test -f a.out && |
| 362 | test ! -f src/part3.c && |
| 363 | test -f docs/manual.txt && |
| 364 | test ! -f obj.o && |
| 365 | test ! -d build |
| 366 | |
| 367 | ' |
| 368 | |
Junio C Hamano | 562ca19 | 2007-11-01 17:32:04 -0700 | [diff] [blame] | 369 | test_expect_success 'clean.requireForce defaults to true' ' |
| 370 | |
| 371 | git config --unset clean.requireForce && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 372 | test_must_fail git clean |
Junio C Hamano | 562ca19 | 2007-11-01 17:32:04 -0700 | [diff] [blame] | 373 | |
| 374 | ' |
| 375 | |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 376 | test_expect_success 'clean.requireForce' ' |
| 377 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 378 | git config clean.requireForce true && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 379 | test_must_fail git clean |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 380 | |
| 381 | ' |
| 382 | |
| 383 | test_expect_success 'clean.requireForce and -n' ' |
| 384 | |
| 385 | mkdir -p build docs && |
| 386 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 387 | git clean -n && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 388 | test -f Makefile && |
| 389 | test -f README && |
| 390 | test -f src/part1.c && |
| 391 | test -f src/part2.c && |
| 392 | test -f a.out && |
| 393 | test -f src/part3.c && |
| 394 | test -f docs/manual.txt && |
| 395 | test -f obj.o && |
| 396 | test -f build/lib.so |
| 397 | |
| 398 | ' |
| 399 | |
| 400 | test_expect_success 'clean.requireForce and -f' ' |
| 401 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 402 | git clean -f && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 403 | test -f README && |
| 404 | test -f src/part1.c && |
| 405 | test -f src/part2.c && |
| 406 | test ! -f a.out && |
| 407 | test ! -f src/part3.c && |
| 408 | test -f docs/manual.txt && |
| 409 | test -f obj.o && |
| 410 | test -f build/lib.so |
| 411 | |
| 412 | ' |
| 413 | |
Ævar Arnfjörð Bjarmason | 2da57ad | 2011-02-22 23:42:21 +0000 | [diff] [blame] | 414 | test_expect_success C_LOCALE_OUTPUT 'core.excludesfile' ' |
Junio C Hamano | b57321f | 2007-11-14 01:54:43 -0800 | [diff] [blame] | 415 | |
| 416 | echo excludes >excludes && |
| 417 | echo included >included && |
| 418 | git config core.excludesfile excludes && |
| 419 | output=$(git clean -n excludes included 2>&1) && |
| 420 | expr "$output" : ".*included" >/dev/null && |
| 421 | ! expr "$output" : ".*excludes" >/dev/null |
| 422 | |
| 423 | ' |
| 424 | |
Ævar Arnfjörð Bjarmason | c91cfd1 | 2010-08-06 22:09:09 +0000 | [diff] [blame] | 425 | test_expect_success SANITY 'removal failure' ' |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 426 | |
| 427 | mkdir foo && |
| 428 | touch foo/bar && |
Jeff King | 45067fc | 2014-07-02 14:44:30 -0400 | [diff] [blame] | 429 | test_when_finished "chmod 755 foo" && |
Johannes Schindelin | e2c2407 | 2009-03-11 17:58:32 +0100 | [diff] [blame] | 430 | (exec <foo/bar && |
| 431 | chmod 0 foo && |
Jeff King | 45067fc | 2014-07-02 14:44:30 -0400 | [diff] [blame] | 432 | test_must_fail git clean -f -d) |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 433 | ' |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 434 | |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 435 | test_expect_success 'nested git work tree' ' |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 436 | rm -fr foo bar baz && |
| 437 | mkdir -p foo bar baz/boo && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 438 | ( |
| 439 | cd foo && |
| 440 | git init && |
| 441 | >hello.world |
| 442 | git add . && |
| 443 | git commit -a -m nested |
| 444 | ) && |
| 445 | ( |
| 446 | cd bar && |
| 447 | >goodbye.people |
| 448 | ) && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 449 | ( |
| 450 | cd baz/boo && |
| 451 | git init && |
| 452 | >deeper.world |
| 453 | git add . && |
| 454 | git commit -a -m deeply.nested |
| 455 | ) && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 456 | git clean -f -d && |
| 457 | test -f foo/.git/index && |
| 458 | test -f foo/hello.world && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 459 | test -f baz/boo/.git/index && |
| 460 | test -f baz/boo/deeper.world && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 461 | ! test -d bar |
| 462 | ' |
| 463 | |
| 464 | test_expect_success 'force removal of nested git work tree' ' |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 465 | rm -fr foo bar baz && |
| 466 | mkdir -p foo bar baz/boo && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 467 | ( |
| 468 | cd foo && |
| 469 | git init && |
| 470 | >hello.world |
| 471 | git add . && |
| 472 | git commit -a -m nested |
| 473 | ) && |
| 474 | ( |
| 475 | cd bar && |
| 476 | >goodbye.people |
| 477 | ) && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 478 | ( |
| 479 | cd baz/boo && |
| 480 | git init && |
| 481 | >deeper.world |
| 482 | git add . && |
| 483 | git commit -a -m deeply.nested |
| 484 | ) && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 485 | git clean -f -f -d && |
| 486 | ! test -d foo && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 487 | ! test -d bar && |
| 488 | ! test -d baz |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 489 | ' |
| 490 | |
Jared Hance | 2c76c3f | 2010-07-20 15:36:21 -0400 | [diff] [blame] | 491 | test_expect_success 'git clean -e' ' |
| 492 | rm -fr repo && |
| 493 | mkdir repo && |
| 494 | ( |
| 495 | cd repo && |
| 496 | git init && |
Brandon Casey | 84d6940 | 2010-09-15 15:58:22 -0500 | [diff] [blame] | 497 | touch known 1 2 3 && |
Jared Hance | 2c76c3f | 2010-07-20 15:36:21 -0400 | [diff] [blame] | 498 | git add known && |
| 499 | git clean -f -e 1 -e 2 && |
| 500 | test -e 1 && |
| 501 | test -e 2 && |
| 502 | ! (test -e 3) && |
| 503 | test -e known |
| 504 | ) |
| 505 | ' |
| 506 | |
Alex Riesen | 0235017 | 2011-04-01 10:29:16 +0200 | [diff] [blame] | 507 | test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' |
| 508 | mkdir foo && |
| 509 | chmod a= foo && |
| 510 | git clean -dfx foo && |
| 511 | ! test -d foo |
| 512 | ' |
| 513 | |
Jeff King | cf424f5 | 2014-03-10 16:37:30 -0400 | [diff] [blame] | 514 | test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' ' |
| 515 | mkdir -p foo && |
| 516 | mkdir -p foobar && |
| 517 | git clean -df foobar && |
| 518 | test_path_is_dir foo && |
| 519 | test_path_is_missing foobar |
| 520 | ' |
| 521 | |
| 522 | test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)' ' |
| 523 | mkdir -p foo && |
| 524 | mkdir -p foobar && |
| 525 | git clean -df foo && |
| 526 | test_path_is_missing foo && |
| 527 | test_path_is_dir foobar |
| 528 | ' |
| 529 | |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 530 | test_done |