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 | ) && |
Jeff King | a167ece | 2015-03-20 06:09:00 -0400 | [diff] [blame] | 122 | verbose test "$would_clean" = ../src/part3.c |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 123 | ' |
| 124 | |
Ævar Arnfjörð Bjarmason | 2da57ad | 2011-02-22 23:42:21 +0000 | [diff] [blame] | 125 | test_expect_success C_LOCALE_OUTPUT 'git clean with absolute path' ' |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 126 | |
| 127 | mkdir -p build docs && |
| 128 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 129 | would_clean=$( |
| 130 | cd docs && |
Bryan Donlan | f69e836 | 2008-05-04 01:37:59 -0400 | [diff] [blame] | 131 | git clean -n "$(pwd)/../src" | |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 132 | sed -n -e "s|^Would remove ||p" |
| 133 | ) && |
Jeff King | a167ece | 2015-03-20 06:09:00 -0400 | [diff] [blame] | 134 | verbose test "$would_clean" = ../src/part3.c |
Junio C Hamano | 5b7570c | 2008-03-07 21:56:56 -0800 | [diff] [blame] | 135 | ' |
| 136 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 137 | 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] | 138 | |
| 139 | mkdir -p build docs && |
| 140 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 141 | ( |
| 142 | cd docs && |
| 143 | test_must_fail git clean -n ../.. |
| 144 | ) |
| 145 | ' |
| 146 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 147 | 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] | 148 | |
| 149 | mkdir -p build docs && |
| 150 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 151 | dd=$(cd .. && pwd) && |
| 152 | ( |
| 153 | cd docs && |
| 154 | test_must_fail git clean -n $dd |
| 155 | ) |
| 156 | ' |
| 157 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 158 | test_expect_success 'git clean -d with prefix and path' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 159 | |
| 160 | mkdir -p build docs src/feature && |
| 161 | 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] | 162 | (cd src/ && git clean -d feature/) && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 163 | test -f Makefile && |
| 164 | test -f README && |
| 165 | test -f src/part1.c && |
| 166 | test -f src/part2.c && |
| 167 | test -f a.out && |
| 168 | test -f src/part3.c && |
| 169 | test ! -f src/feature/file.c && |
| 170 | test -f docs/manual.txt && |
| 171 | test -f obj.o && |
| 172 | test -f build/lib.so |
| 173 | |
| 174 | ' |
| 175 | |
Johannes Sixt | 7569c1f | 2010-11-25 09:03:39 +0100 | [diff] [blame] | 176 | test_expect_success SYMLINKS 'git clean symbolic link' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 177 | |
| 178 | mkdir -p build docs && |
| 179 | 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] | 180 | ln -s docs/manual.txt src/part4.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 181 | git clean && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 182 | test -f Makefile && |
| 183 | test -f README && |
| 184 | test -f src/part1.c && |
| 185 | test -f src/part2.c && |
| 186 | test ! -f a.out && |
| 187 | test ! -f src/part3.c && |
| 188 | test ! -f src/part4.c && |
| 189 | test -f docs/manual.txt && |
| 190 | test -f obj.o && |
| 191 | test -f build/lib.so |
| 192 | |
| 193 | ' |
| 194 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 195 | test_expect_success 'git clean with wildcard' ' |
Jeff King | d3357ab | 2007-12-05 22:28:06 -0500 | [diff] [blame] | 196 | |
| 197 | touch a.clean b.clean other.c && |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 198 | git clean "*.clean" && |
Jeff King | d3357ab | 2007-12-05 22:28:06 -0500 | [diff] [blame] | 199 | test -f Makefile && |
| 200 | test -f README && |
| 201 | test -f src/part1.c && |
| 202 | test -f src/part2.c && |
| 203 | test ! -f a.clean && |
| 204 | test ! -f b.clean && |
| 205 | test -f other.c |
| 206 | |
| 207 | ' |
| 208 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 209 | test_expect_success 'git clean -n' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 210 | |
| 211 | mkdir -p build docs && |
| 212 | 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] | 213 | git clean -n && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 214 | test -f Makefile && |
| 215 | test -f README && |
| 216 | test -f src/part1.c && |
| 217 | test -f src/part2.c && |
| 218 | test -f a.out && |
| 219 | test -f src/part3.c && |
| 220 | test -f docs/manual.txt && |
| 221 | test -f obj.o && |
| 222 | test -f build/lib.so |
| 223 | |
| 224 | ' |
| 225 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 226 | test_expect_success 'git clean -d' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 227 | |
| 228 | mkdir -p build docs && |
| 229 | 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] | 230 | git clean -d && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 231 | test -f Makefile && |
| 232 | test -f README && |
| 233 | test -f src/part1.c && |
| 234 | test -f src/part2.c && |
| 235 | test ! -f a.out && |
| 236 | test ! -f src/part3.c && |
| 237 | test ! -d docs && |
| 238 | test -f obj.o && |
| 239 | test -f build/lib.so |
| 240 | |
| 241 | ' |
| 242 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 243 | test_expect_success 'git clean -d src/ examples/' ' |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 244 | |
| 245 | mkdir -p build docs examples && |
| 246 | 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] | 247 | git clean -d src/ examples/ && |
Shawn Bohrer | ae3e76c | 2007-11-04 22:28:12 -0600 | [diff] [blame] | 248 | test -f Makefile && |
| 249 | test -f README && |
| 250 | test -f src/part1.c && |
| 251 | test -f src/part2.c && |
| 252 | test -f a.out && |
| 253 | test ! -f src/part3.c && |
| 254 | test ! -f examples/1.c && |
| 255 | test -f docs/manual.txt && |
| 256 | test -f obj.o && |
| 257 | test -f build/lib.so |
| 258 | |
| 259 | ' |
| 260 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 261 | test_expect_success 'git clean -x' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 262 | |
| 263 | mkdir -p build docs && |
| 264 | 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] | 265 | git clean -x && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 266 | test -f Makefile && |
| 267 | test -f README && |
| 268 | test -f src/part1.c && |
| 269 | test -f src/part2.c && |
| 270 | test ! -f a.out && |
| 271 | test ! -f src/part3.c && |
| 272 | test -f docs/manual.txt && |
| 273 | test ! -f obj.o && |
| 274 | test -f build/lib.so |
| 275 | |
| 276 | ' |
| 277 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 278 | test_expect_success 'git clean -d -x' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 279 | |
| 280 | mkdir -p build docs && |
| 281 | 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] | 282 | git clean -d -x && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 283 | test -f Makefile && |
| 284 | test -f README && |
| 285 | test -f src/part1.c && |
| 286 | test -f src/part2.c && |
| 287 | test ! -f a.out && |
| 288 | test ! -f src/part3.c && |
| 289 | test ! -d docs && |
| 290 | test ! -f obj.o && |
| 291 | test ! -d build |
| 292 | |
| 293 | ' |
| 294 | |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 295 | test_expect_success 'git clean -d -x with ignored tracked directory' ' |
| 296 | |
| 297 | mkdir -p build docs && |
| 298 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 299 | git clean -d -x -e src && |
| 300 | test -f Makefile && |
| 301 | test -f README && |
| 302 | test -f src/part1.c && |
| 303 | test -f src/part2.c && |
| 304 | test ! -f a.out && |
| 305 | test -f src/part3.c && |
| 306 | test ! -d docs && |
| 307 | test ! -f obj.o && |
| 308 | test ! -d build |
| 309 | |
| 310 | ' |
| 311 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 312 | test_expect_success 'git clean -X' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 313 | |
| 314 | mkdir -p build docs && |
| 315 | 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] | 316 | git clean -X && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 317 | test -f Makefile && |
| 318 | test -f README && |
| 319 | test -f src/part1.c && |
| 320 | test -f src/part2.c && |
| 321 | test -f a.out && |
| 322 | test -f src/part3.c && |
| 323 | test -f docs/manual.txt && |
| 324 | test ! -f obj.o && |
| 325 | test -f build/lib.so |
| 326 | |
| 327 | ' |
| 328 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 329 | test_expect_success 'git clean -d -X' ' |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 330 | |
| 331 | mkdir -p build docs && |
| 332 | 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] | 333 | git clean -d -X && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 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 ! -d build |
| 343 | |
| 344 | ' |
| 345 | |
Karsten Blees | 5bd8e2d | 2013-04-15 21:10:05 +0200 | [diff] [blame] | 346 | test_expect_success 'git clean -d -X with ignored tracked directory' ' |
| 347 | |
| 348 | mkdir -p build docs && |
| 349 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && |
| 350 | git clean -d -X -e src && |
| 351 | test -f Makefile && |
| 352 | test -f README && |
| 353 | test -f src/part1.c && |
| 354 | test -f src/part2.c && |
| 355 | test -f a.out && |
| 356 | test ! -f src/part3.c && |
| 357 | test -f docs/manual.txt && |
| 358 | test ! -f obj.o && |
| 359 | test ! -d build |
| 360 | |
| 361 | ' |
| 362 | |
Junio C Hamano | 562ca19 | 2007-11-01 17:32:04 -0700 | [diff] [blame] | 363 | test_expect_success 'clean.requireForce defaults to true' ' |
| 364 | |
| 365 | git config --unset clean.requireForce && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 366 | test_must_fail git clean |
Junio C Hamano | 562ca19 | 2007-11-01 17:32:04 -0700 | [diff] [blame] | 367 | |
| 368 | ' |
| 369 | |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 370 | test_expect_success 'clean.requireForce' ' |
| 371 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 372 | git config clean.requireForce true && |
Stephan Beyer | d492b31 | 2008-07-12 17:47:52 +0200 | [diff] [blame] | 373 | test_must_fail git clean |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 374 | |
| 375 | ' |
| 376 | |
| 377 | test_expect_success 'clean.requireForce and -n' ' |
| 378 | |
| 379 | mkdir -p build docs && |
| 380 | 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] | 381 | git clean -n && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 382 | test -f Makefile && |
| 383 | test -f README && |
| 384 | test -f src/part1.c && |
| 385 | test -f src/part2.c && |
| 386 | test -f a.out && |
| 387 | test -f src/part3.c && |
| 388 | test -f docs/manual.txt && |
| 389 | test -f obj.o && |
| 390 | test -f build/lib.so |
| 391 | |
| 392 | ' |
| 393 | |
| 394 | test_expect_success 'clean.requireForce and -f' ' |
| 395 | |
Nanako Shiraishi | 47a528a | 2008-09-03 17:59:33 +0900 | [diff] [blame] | 396 | git clean -f && |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 397 | test -f README && |
| 398 | test -f src/part1.c && |
| 399 | test -f src/part2.c && |
| 400 | test ! -f a.out && |
| 401 | test ! -f src/part3.c && |
| 402 | test -f docs/manual.txt && |
| 403 | test -f obj.o && |
| 404 | test -f build/lib.so |
| 405 | |
| 406 | ' |
| 407 | |
Ævar Arnfjörð Bjarmason | 2da57ad | 2011-02-22 23:42:21 +0000 | [diff] [blame] | 408 | test_expect_success C_LOCALE_OUTPUT 'core.excludesfile' ' |
Junio C Hamano | b57321f | 2007-11-14 01:54:43 -0800 | [diff] [blame] | 409 | |
| 410 | echo excludes >excludes && |
| 411 | echo included >included && |
| 412 | git config core.excludesfile excludes && |
| 413 | output=$(git clean -n excludes included 2>&1) && |
| 414 | expr "$output" : ".*included" >/dev/null && |
| 415 | ! expr "$output" : ".*excludes" >/dev/null |
| 416 | |
| 417 | ' |
| 418 | |
Ævar Arnfjörð Bjarmason | c91cfd1 | 2010-08-06 22:09:09 +0000 | [diff] [blame] | 419 | test_expect_success SANITY 'removal failure' ' |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 420 | |
| 421 | mkdir foo && |
| 422 | touch foo/bar && |
Jeff King | 45067fc | 2014-07-02 14:44:30 -0400 | [diff] [blame] | 423 | test_when_finished "chmod 755 foo" && |
Johannes Schindelin | e2c2407 | 2009-03-11 17:58:32 +0100 | [diff] [blame] | 424 | (exec <foo/bar && |
| 425 | chmod 0 foo && |
Jeff King | 45067fc | 2014-07-02 14:44:30 -0400 | [diff] [blame] | 426 | test_must_fail git clean -f -d) |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 427 | ' |
Miklos Vajna | aa9c83c | 2008-02-21 02:44:46 +0100 | [diff] [blame] | 428 | |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 429 | test_expect_success 'nested git work tree' ' |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 430 | rm -fr foo bar baz && |
| 431 | mkdir -p foo bar baz/boo && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 432 | ( |
| 433 | cd foo && |
| 434 | git init && |
Erik Elfström | 1733ed3 | 2015-08-30 11:18:09 +0200 | [diff] [blame] | 435 | test_commit nested hello.world |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 436 | ) && |
| 437 | ( |
| 438 | cd bar && |
| 439 | >goodbye.people |
| 440 | ) && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 441 | ( |
| 442 | cd baz/boo && |
| 443 | git init && |
Erik Elfström | 1733ed3 | 2015-08-30 11:18:09 +0200 | [diff] [blame] | 444 | test_commit deeply.nested deeper.world |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 445 | ) && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 446 | git clean -f -d && |
| 447 | test -f foo/.git/index && |
| 448 | test -f foo/hello.world && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 449 | test -f baz/boo/.git/index && |
| 450 | test -f baz/boo/deeper.world && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 451 | ! test -d bar |
| 452 | ' |
| 453 | |
Erik Elfström | 0179ca7 | 2015-06-15 21:39:55 +0200 | [diff] [blame] | 454 | test_expect_success 'should clean things that almost look like git but are not' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 455 | rm -fr almost_git almost_bare_git almost_submodule && |
| 456 | mkdir -p almost_git/.git/objects && |
| 457 | mkdir -p almost_git/.git/refs && |
| 458 | cat >almost_git/.git/HEAD <<-\EOF && |
| 459 | garbage |
| 460 | EOF |
| 461 | cp -r almost_git/.git/ almost_bare_git && |
| 462 | mkdir almost_submodule/ && |
| 463 | cat >almost_submodule/.git <<-\EOF && |
| 464 | garbage |
| 465 | EOF |
| 466 | test_when_finished "rm -rf almost_*" && |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 467 | git clean -f -d && |
| 468 | test_path_is_missing almost_git && |
| 469 | test_path_is_missing almost_bare_git && |
| 470 | test_path_is_missing almost_submodule |
| 471 | ' |
| 472 | |
| 473 | test_expect_success 'should not clean submodules' ' |
| 474 | rm -fr repo to_clean sub1 sub2 && |
| 475 | mkdir repo to_clean && |
| 476 | ( |
| 477 | cd repo && |
| 478 | git init && |
| 479 | test_commit msg hello.world |
| 480 | ) && |
| 481 | git submodule add ./repo/.git sub1 && |
| 482 | git commit -m "sub1" && |
| 483 | git branch before_sub2 && |
| 484 | git submodule add ./repo/.git sub2 && |
| 485 | git commit -m "sub2" && |
| 486 | git checkout before_sub2 && |
| 487 | >to_clean/should_clean.this && |
| 488 | git clean -f -d && |
| 489 | test_path_is_file repo/.git/index && |
| 490 | test_path_is_file repo/hello.world && |
| 491 | test_path_is_file sub1/.git && |
| 492 | test_path_is_file sub1/hello.world && |
| 493 | test_path_is_file sub2/.git && |
| 494 | test_path_is_file sub2/hello.world && |
| 495 | test_path_is_missing to_clean |
| 496 | ' |
| 497 | |
Stefan Beller | cadfbef | 2016-05-03 11:54:32 -0700 | [diff] [blame] | 498 | test_expect_success POSIXPERM,SANITY 'should avoid cleaning possible submodules' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 499 | rm -fr to_clean possible_sub1 && |
| 500 | mkdir to_clean possible_sub1 && |
| 501 | test_when_finished "rm -rf possible_sub*" && |
| 502 | echo "gitdir: foo" >possible_sub1/.git && |
| 503 | >possible_sub1/hello.world && |
| 504 | chmod 0 possible_sub1/.git && |
| 505 | >to_clean/should_clean.this && |
| 506 | git clean -f -d && |
| 507 | test_path_is_file possible_sub1/.git && |
| 508 | test_path_is_file possible_sub1/hello.world && |
| 509 | test_path_is_missing to_clean |
| 510 | ' |
| 511 | |
Erik Elfström | 0179ca7 | 2015-06-15 21:39:55 +0200 | [diff] [blame] | 512 | test_expect_success 'nested (empty) git should be kept' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 513 | rm -fr empty_repo to_clean && |
| 514 | git init empty_repo && |
| 515 | mkdir to_clean && |
| 516 | >to_clean/should_clean.this && |
| 517 | git clean -f -d && |
| 518 | test_path_is_file empty_repo/.git/HEAD && |
| 519 | test_path_is_missing to_clean |
| 520 | ' |
| 521 | |
| 522 | test_expect_success 'nested bare repositories should be cleaned' ' |
| 523 | rm -fr bare1 bare2 subdir && |
| 524 | git init --bare bare1 && |
| 525 | git clone --local --bare . bare2 && |
| 526 | mkdir subdir && |
| 527 | cp -r bare2 subdir/bare3 && |
| 528 | git clean -f -d && |
| 529 | test_path_is_missing bare1 && |
| 530 | test_path_is_missing bare2 && |
| 531 | test_path_is_missing subdir |
| 532 | ' |
| 533 | |
Erik Elfström | 0179ca7 | 2015-06-15 21:39:55 +0200 | [diff] [blame] | 534 | test_expect_failure 'nested (empty) bare repositories should be cleaned even when in .git' ' |
Erik Elfström | 91479b9 | 2015-06-15 21:39:53 +0200 | [diff] [blame] | 535 | rm -fr strange_bare && |
| 536 | mkdir strange_bare && |
| 537 | git init --bare strange_bare/.git && |
| 538 | git clean -f -d && |
| 539 | test_path_is_missing strange_bare |
| 540 | ' |
| 541 | |
| 542 | test_expect_failure 'nested (non-empty) bare repositories should be cleaned even when in .git' ' |
| 543 | rm -fr strange_bare && |
| 544 | mkdir strange_bare && |
| 545 | git clone --local --bare . strange_bare/.git && |
| 546 | git clean -f -d && |
| 547 | test_path_is_missing strange_bare |
| 548 | ' |
| 549 | |
| 550 | test_expect_success 'giving path in nested git work tree will remove it' ' |
| 551 | rm -fr repo && |
| 552 | mkdir repo && |
| 553 | ( |
| 554 | cd repo && |
| 555 | git init && |
| 556 | mkdir -p bar/baz && |
| 557 | test_commit msg bar/baz/hello.world |
| 558 | ) && |
| 559 | git clean -f -d repo/bar/baz && |
| 560 | test_path_is_file repo/.git/HEAD && |
| 561 | test_path_is_dir repo/bar/ && |
| 562 | test_path_is_missing repo/bar/baz |
| 563 | ' |
| 564 | |
| 565 | test_expect_success 'giving path to nested .git will not remove it' ' |
| 566 | rm -fr repo && |
| 567 | mkdir repo untracked && |
| 568 | ( |
| 569 | cd repo && |
| 570 | git init && |
| 571 | test_commit msg hello.world |
| 572 | ) && |
| 573 | git clean -f -d repo/.git && |
| 574 | test_path_is_file repo/.git/HEAD && |
| 575 | test_path_is_dir repo/.git/refs && |
| 576 | test_path_is_dir repo/.git/objects && |
| 577 | test_path_is_dir untracked/ |
| 578 | ' |
| 579 | |
| 580 | test_expect_success 'giving path to nested .git/ will remove contents' ' |
| 581 | rm -fr repo untracked && |
| 582 | mkdir repo untracked && |
| 583 | ( |
| 584 | cd repo && |
| 585 | git init && |
| 586 | test_commit msg hello.world |
| 587 | ) && |
| 588 | git clean -f -d repo/.git/ && |
| 589 | test_path_is_dir repo/.git && |
| 590 | test_dir_is_empty repo/.git && |
| 591 | test_path_is_dir untracked/ |
| 592 | ' |
| 593 | |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 594 | test_expect_success 'force removal of nested git work tree' ' |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 595 | rm -fr foo bar baz && |
| 596 | mkdir -p foo bar baz/boo && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 597 | ( |
| 598 | cd foo && |
| 599 | git init && |
Erik Elfström | 1733ed3 | 2015-08-30 11:18:09 +0200 | [diff] [blame] | 600 | test_commit nested hello.world |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 601 | ) && |
| 602 | ( |
| 603 | cd bar && |
| 604 | >goodbye.people |
| 605 | ) && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 606 | ( |
| 607 | cd baz/boo && |
| 608 | git init && |
Erik Elfström | 1733ed3 | 2015-08-30 11:18:09 +0200 | [diff] [blame] | 609 | test_commit deeply.nested deeper.world |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 610 | ) && |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 611 | git clean -f -f -d && |
| 612 | ! test -d foo && |
Junio C Hamano | ae2f203 | 2012-03-15 01:04:12 -0700 | [diff] [blame] | 613 | ! test -d bar && |
| 614 | ! test -d baz |
Junio C Hamano | a0f4afb | 2009-06-30 15:33:45 -0700 | [diff] [blame] | 615 | ' |
| 616 | |
Jared Hance | 2c76c3f | 2010-07-20 15:36:21 -0400 | [diff] [blame] | 617 | test_expect_success 'git clean -e' ' |
| 618 | rm -fr repo && |
| 619 | mkdir repo && |
| 620 | ( |
| 621 | cd repo && |
| 622 | git init && |
Brandon Casey | 84d6940 | 2010-09-15 15:58:22 -0500 | [diff] [blame] | 623 | touch known 1 2 3 && |
Jared Hance | 2c76c3f | 2010-07-20 15:36:21 -0400 | [diff] [blame] | 624 | git add known && |
| 625 | git clean -f -e 1 -e 2 && |
| 626 | test -e 1 && |
| 627 | test -e 2 && |
| 628 | ! (test -e 3) && |
| 629 | test -e known |
| 630 | ) |
| 631 | ' |
| 632 | |
Alex Riesen | 0235017 | 2011-04-01 10:29:16 +0200 | [diff] [blame] | 633 | test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' |
| 634 | mkdir foo && |
| 635 | chmod a= foo && |
| 636 | git clean -dfx foo && |
| 637 | ! test -d foo |
| 638 | ' |
| 639 | |
Jeff King | cf424f5 | 2014-03-10 16:37:30 -0400 | [diff] [blame] | 640 | test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' ' |
| 641 | mkdir -p foo && |
| 642 | mkdir -p foobar && |
| 643 | git clean -df foobar && |
| 644 | test_path_is_dir foo && |
| 645 | test_path_is_missing foobar |
| 646 | ' |
| 647 | |
| 648 | test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)' ' |
| 649 | mkdir -p foo && |
| 650 | mkdir -p foobar && |
| 651 | git clean -df foo && |
| 652 | test_path_is_missing foo && |
| 653 | test_path_is_dir foobar |
| 654 | ' |
| 655 | |
Samuel Lijin | 6b1db43 | 2017-05-23 06:09:37 -0400 | [diff] [blame] | 656 | test_expect_success 'git clean -d skips untracked dirs containing ignored files' ' |
Samuel Lijin | b3487cc | 2017-05-18 04:21:49 -0400 | [diff] [blame] | 657 | echo /foo/bar >.gitignore && |
| 658 | echo ignoreme >>.gitignore && |
| 659 | rm -rf foo && |
| 660 | mkdir -p foo/a/aa/aaa foo/b/bb/bbb && |
| 661 | touch foo/bar foo/baz foo/a/aa/ignoreme foo/b/ignoreme foo/b/bb/1 foo/b/bb/2 && |
| 662 | git clean -df && |
| 663 | test_path_is_dir foo && |
| 664 | test_path_is_file foo/bar && |
| 665 | test_path_is_missing foo/baz && |
| 666 | test_path_is_file foo/a/aa/ignoreme && |
| 667 | test_path_is_missing foo/a/aa/aaa && |
| 668 | test_path_is_file foo/b/ignoreme && |
| 669 | test_path_is_missing foo/b/bb |
| 670 | ' |
| 671 | |
Michael Spang | ec0e0f2 | 2007-05-06 15:50:54 -0400 | [diff] [blame] | 672 | test_done |