]>
Commit | Line | Data |
---|---|---|
ec0e0f25 MS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Michael Spang | |
4 | # | |
5 | ||
47a528ad | 6 | test_description='git clean basic tests' |
ec0e0f25 | 7 | |
0e0fefb2 | 8 | TEST_PASSES_SANITIZE_LEAK=true |
ec0e0f25 MS |
9 | . ./test-lib.sh |
10 | ||
562ca192 JH |
11 | git config clean.requireForce no |
12 | ||
ec0e0f25 MS |
13 | test_expect_success 'setup' ' |
14 | ||
15 | mkdir -p src && | |
16 | touch src/part1.c Makefile && | |
17 | echo build >.gitignore && | |
18 | echo \*.o >>.gitignore && | |
5be60078 | 19 | git add . && |
47a528ad | 20 | git commit -m setup && |
ec0e0f25 | 21 | touch src/part2.c README && |
5be60078 | 22 | git add . |
ec0e0f25 MS |
23 | |
24 | ' | |
25 | ||
c28b3d6e NTND |
26 | test_expect_success 'git clean with skip-worktree .gitignore' ' |
27 | git update-index --skip-worktree .gitignore && | |
28 | rm .gitignore && | |
29 | mkdir -p build docs && | |
30 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
31 | git clean && | |
32 | test -f Makefile && | |
33 | test -f README && | |
34 | test -f src/part1.c && | |
35 | test -f src/part2.c && | |
36 | test ! -f a.out && | |
37 | test ! -f src/part3.c && | |
38 | test -f docs/manual.txt && | |
39 | test -f obj.o && | |
40 | test -f build/lib.so && | |
41 | git update-index --no-skip-worktree .gitignore && | |
42 | git checkout .gitignore | |
43 | ' | |
44 | ||
47a528ad | 45 | test_expect_success 'git clean' ' |
ec0e0f25 MS |
46 | |
47 | mkdir -p build docs && | |
48 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 49 | git clean && |
ec0e0f25 MS |
50 | test -f Makefile && |
51 | test -f README && | |
52 | test -f src/part1.c && | |
53 | test -f src/part2.c && | |
54 | test ! -f a.out && | |
55 | test ! -f src/part3.c && | |
56 | test -f docs/manual.txt && | |
57 | test -f obj.o && | |
58 | test -f build/lib.so | |
59 | ||
60 | ' | |
61 | ||
47a528ad | 62 | test_expect_success 'git clean src/' ' |
ae3e76c2 SB |
63 | |
64 | mkdir -p build docs && | |
65 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 66 | git clean src/ && |
ae3e76c2 SB |
67 | test -f Makefile && |
68 | test -f README && | |
69 | test -f src/part1.c && | |
70 | test -f src/part2.c && | |
71 | test -f a.out && | |
72 | test ! -f src/part3.c && | |
73 | test -f docs/manual.txt && | |
74 | test -f obj.o && | |
75 | test -f build/lib.so | |
76 | ||
77 | ' | |
78 | ||
47a528ad | 79 | test_expect_success 'git clean src/ src/' ' |
ae3e76c2 SB |
80 | |
81 | mkdir -p build docs && | |
82 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 83 | git clean src/ src/ && |
ae3e76c2 SB |
84 | test -f Makefile && |
85 | test -f README && | |
86 | test -f src/part1.c && | |
87 | test -f src/part2.c && | |
88 | test -f a.out && | |
89 | test ! -f src/part3.c && | |
90 | test -f docs/manual.txt && | |
91 | test -f obj.o && | |
92 | test -f build/lib.so | |
93 | ||
94 | ' | |
95 | ||
47a528ad | 96 | test_expect_success 'git clean with prefix' ' |
ae3e76c2 | 97 | |
2b6f0b0a SB |
98 | mkdir -p build docs src/test && |
99 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so src/test/1.c && | |
47a528ad | 100 | (cd src/ && git clean) && |
ae3e76c2 SB |
101 | test -f Makefile && |
102 | test -f README && | |
103 | test -f src/part1.c && | |
104 | test -f src/part2.c && | |
105 | test -f a.out && | |
106 | test ! -f src/part3.c && | |
2b6f0b0a | 107 | test -f src/test/1.c && |
ae3e76c2 SB |
108 | test -f docs/manual.txt && |
109 | test -f obj.o && | |
110 | test -f build/lib.so | |
111 | ||
112 | ' | |
5b7570cf | 113 | |
a926c4b9 | 114 | test_expect_success 'git clean with relative prefix' ' |
5b7570cf JH |
115 | |
116 | mkdir -p build docs && | |
117 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
118 | would_clean=$( | |
119 | cd docs && | |
120 | git clean -n ../src | | |
e86bbcf9 | 121 | grep part3 | |
5b7570cf JH |
122 | sed -n -e "s|^Would remove ||p" |
123 | ) && | |
8ddfce71 | 124 | test "$would_clean" = ../src/part3.c |
5b7570cf JH |
125 | ' |
126 | ||
a926c4b9 | 127 | test_expect_success 'git clean with absolute path' ' |
5b7570cf JH |
128 | |
129 | mkdir -p build docs && | |
130 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
131 | would_clean=$( | |
132 | cd docs && | |
f69e836f | 133 | git clean -n "$(pwd)/../src" | |
e86bbcf9 | 134 | grep part3 | |
5b7570cf JH |
135 | sed -n -e "s|^Would remove ||p" |
136 | ) && | |
8ddfce71 | 137 | test "$would_clean" = ../src/part3.c |
5b7570cf JH |
138 | ' |
139 | ||
47a528ad | 140 | test_expect_success 'git clean with out of work tree relative path' ' |
5b7570cf JH |
141 | |
142 | mkdir -p build docs && | |
143 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
144 | ( | |
145 | cd docs && | |
146 | test_must_fail git clean -n ../.. | |
147 | ) | |
148 | ' | |
149 | ||
47a528ad | 150 | test_expect_success 'git clean with out of work tree absolute path' ' |
5b7570cf JH |
151 | |
152 | mkdir -p build docs && | |
153 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
154 | dd=$(cd .. && pwd) && | |
155 | ( | |
156 | cd docs && | |
157 | test_must_fail git clean -n $dd | |
158 | ) | |
159 | ' | |
160 | ||
47a528ad | 161 | test_expect_success 'git clean -d with prefix and path' ' |
ae3e76c2 SB |
162 | |
163 | mkdir -p build docs src/feature && | |
164 | touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 165 | (cd src/ && git clean -d feature/) && |
ae3e76c2 SB |
166 | test -f Makefile && |
167 | test -f README && | |
168 | test -f src/part1.c && | |
169 | test -f src/part2.c && | |
170 | test -f a.out && | |
171 | test -f src/part3.c && | |
172 | test ! -f src/feature/file.c && | |
173 | test -f docs/manual.txt && | |
174 | test -f obj.o && | |
175 | test -f build/lib.so | |
176 | ||
177 | ' | |
178 | ||
7569c1f4 | 179 | test_expect_success SYMLINKS 'git clean symbolic link' ' |
ae3e76c2 SB |
180 | |
181 | mkdir -p build docs && | |
182 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
2dec68cf | 183 | ln -s docs/manual.txt src/part4.c && |
47a528ad | 184 | git clean && |
ae3e76c2 SB |
185 | test -f Makefile && |
186 | test -f README && | |
187 | test -f src/part1.c && | |
188 | test -f src/part2.c && | |
189 | test ! -f a.out && | |
190 | test ! -f src/part3.c && | |
191 | test ! -f src/part4.c && | |
192 | test -f docs/manual.txt && | |
193 | test -f obj.o && | |
194 | test -f build/lib.so | |
195 | ||
196 | ' | |
197 | ||
47a528ad | 198 | test_expect_success 'git clean with wildcard' ' |
d3357ab8 JK |
199 | |
200 | touch a.clean b.clean other.c && | |
47a528ad | 201 | git clean "*.clean" && |
d3357ab8 JK |
202 | test -f Makefile && |
203 | test -f README && | |
204 | test -f src/part1.c && | |
205 | test -f src/part2.c && | |
206 | test ! -f a.clean && | |
207 | test ! -f b.clean && | |
208 | test -f other.c | |
209 | ||
210 | ' | |
211 | ||
47a528ad | 212 | test_expect_success 'git clean -n' ' |
ec0e0f25 MS |
213 | |
214 | mkdir -p build docs && | |
215 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 216 | git clean -n && |
ec0e0f25 MS |
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 -f docs/manual.txt && | |
224 | test -f obj.o && | |
225 | test -f build/lib.so | |
226 | ||
227 | ' | |
228 | ||
47a528ad | 229 | test_expect_success 'git clean -d' ' |
ec0e0f25 MS |
230 | |
231 | mkdir -p build docs && | |
232 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 233 | git clean -d && |
ec0e0f25 MS |
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 ! -d docs && | |
241 | test -f obj.o && | |
242 | test -f build/lib.so | |
243 | ||
244 | ' | |
245 | ||
47a528ad | 246 | test_expect_success 'git clean -d src/ examples/' ' |
ae3e76c2 SB |
247 | |
248 | mkdir -p build docs examples && | |
249 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c && | |
47a528ad | 250 | git clean -d src/ examples/ && |
ae3e76c2 SB |
251 | test -f Makefile && |
252 | test -f README && | |
253 | test -f src/part1.c && | |
254 | test -f src/part2.c && | |
255 | test -f a.out && | |
256 | test ! -f src/part3.c && | |
257 | test ! -f examples/1.c && | |
258 | test -f docs/manual.txt && | |
259 | test -f obj.o && | |
260 | test -f build/lib.so | |
261 | ||
262 | ' | |
263 | ||
47a528ad | 264 | test_expect_success 'git clean -x' ' |
ec0e0f25 MS |
265 | |
266 | mkdir -p build docs && | |
267 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 268 | git clean -x && |
ec0e0f25 MS |
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 -f docs/manual.txt && | |
276 | test ! -f obj.o && | |
277 | test -f build/lib.so | |
278 | ||
279 | ' | |
280 | ||
47a528ad | 281 | test_expect_success 'git clean -d -x' ' |
ec0e0f25 MS |
282 | |
283 | mkdir -p build docs && | |
284 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 285 | git clean -d -x && |
ec0e0f25 MS |
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 ! -d docs && | |
293 | test ! -f obj.o && | |
294 | test ! -d build | |
295 | ||
296 | ' | |
297 | ||
5bd8e2d8 KB |
298 | test_expect_success 'git clean -d -x with ignored tracked directory' ' |
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 -e src && | |
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 ! -d docs && | |
310 | test ! -f obj.o && | |
311 | test ! -d build | |
312 | ||
313 | ' | |
314 | ||
47a528ad | 315 | test_expect_success 'git clean -X' ' |
ec0e0f25 MS |
316 | |
317 | mkdir -p build docs && | |
318 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 319 | git clean -X && |
ec0e0f25 MS |
320 | test -f Makefile && |
321 | test -f README && | |
322 | test -f src/part1.c && | |
323 | test -f src/part2.c && | |
324 | test -f a.out && | |
325 | test -f src/part3.c && | |
326 | test -f docs/manual.txt && | |
327 | test ! -f obj.o && | |
328 | test -f build/lib.so | |
329 | ||
330 | ' | |
331 | ||
47a528ad | 332 | test_expect_success 'git clean -d -X' ' |
ec0e0f25 MS |
333 | |
334 | mkdir -p build docs && | |
335 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 336 | git clean -d -X && |
ec0e0f25 MS |
337 | test -f Makefile && |
338 | test -f README && | |
339 | test -f src/part1.c && | |
340 | test -f src/part2.c && | |
341 | test -f a.out && | |
342 | test -f src/part3.c && | |
343 | test -f docs/manual.txt && | |
344 | test ! -f obj.o && | |
345 | test ! -d build | |
346 | ||
347 | ' | |
348 | ||
5bd8e2d8 KB |
349 | test_expect_success 'git clean -d -X with ignored tracked directory' ' |
350 | ||
351 | mkdir -p build docs && | |
352 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
353 | git clean -d -X -e src && | |
354 | test -f Makefile && | |
355 | test -f README && | |
356 | test -f src/part1.c && | |
357 | test -f src/part2.c && | |
358 | test -f a.out && | |
359 | test ! -f src/part3.c && | |
360 | test -f docs/manual.txt && | |
361 | test ! -f obj.o && | |
362 | test ! -d build | |
363 | ||
364 | ' | |
365 | ||
562ca192 JH |
366 | test_expect_success 'clean.requireForce defaults to true' ' |
367 | ||
368 | git config --unset clean.requireForce && | |
d492b31c | 369 | test_must_fail git clean |
562ca192 JH |
370 | |
371 | ' | |
372 | ||
ec0e0f25 MS |
373 | test_expect_success 'clean.requireForce' ' |
374 | ||
5be60078 | 375 | git config clean.requireForce true && |
d492b31c | 376 | test_must_fail git clean |
ec0e0f25 MS |
377 | |
378 | ' | |
379 | ||
380 | test_expect_success 'clean.requireForce and -n' ' | |
381 | ||
382 | mkdir -p build docs && | |
383 | touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && | |
47a528ad | 384 | git clean -n && |
ec0e0f25 MS |
385 | test -f Makefile && |
386 | test -f README && | |
387 | test -f src/part1.c && | |
388 | test -f src/part2.c && | |
389 | test -f a.out && | |
390 | test -f src/part3.c && | |
391 | test -f docs/manual.txt && | |
392 | test -f obj.o && | |
393 | test -f build/lib.so | |
394 | ||
395 | ' | |
396 | ||
397 | test_expect_success 'clean.requireForce and -f' ' | |
398 | ||
47a528ad | 399 | git clean -f && |
ec0e0f25 MS |
400 | test -f README && |
401 | test -f src/part1.c && | |
402 | test -f src/part2.c && | |
403 | test ! -f a.out && | |
404 | test ! -f src/part3.c && | |
405 | test -f docs/manual.txt && | |
406 | test -f obj.o && | |
407 | test -f build/lib.so | |
408 | ||
409 | ' | |
410 | ||
105ec9ae JH |
411 | test_expect_success 'clean.requireForce and --interactive' ' |
412 | git clean --interactive </dev/null >output 2>error && | |
413 | test_grep ! "requireForce is true and" error && | |
414 | test_grep "\*\*\* Commands \*\*\*" output | |
415 | ' | |
416 | ||
a926c4b9 | 417 | test_expect_success 'core.excludesfile' ' |
b57321f5 JH |
418 | |
419 | echo excludes >excludes && | |
420 | echo included >included && | |
421 | git config core.excludesfile excludes && | |
422 | output=$(git clean -n excludes included 2>&1) && | |
423 | expr "$output" : ".*included" >/dev/null && | |
424 | ! expr "$output" : ".*excludes" >/dev/null | |
425 | ||
426 | ' | |
427 | ||
c91cfd19 | 428 | test_expect_success SANITY 'removal failure' ' |
aa9c83c2 MV |
429 | |
430 | mkdir foo && | |
431 | touch foo/bar && | |
45067fc9 | 432 | test_when_finished "chmod 755 foo" && |
e2c24076 JS |
433 | (exec <foo/bar && |
434 | chmod 0 foo && | |
45067fc9 | 435 | test_must_fail git clean -f -d) |
aa9c83c2 | 436 | ' |
aa9c83c2 | 437 | |
a0f4afbe | 438 | test_expect_success 'nested git work tree' ' |
ae2f203e JH |
439 | rm -fr foo bar baz && |
440 | mkdir -p foo bar baz/boo && | |
a0f4afbe JH |
441 | ( |
442 | cd foo && | |
443 | git init && | |
1733ed3d | 444 | test_commit nested hello.world |
a0f4afbe JH |
445 | ) && |
446 | ( | |
447 | cd bar && | |
448 | >goodbye.people | |
449 | ) && | |
ae2f203e JH |
450 | ( |
451 | cd baz/boo && | |
452 | git init && | |
1733ed3d | 453 | test_commit deeply.nested deeper.world |
ae2f203e | 454 | ) && |
a0f4afbe JH |
455 | git clean -f -d && |
456 | test -f foo/.git/index && | |
457 | test -f foo/hello.world && | |
ae2f203e JH |
458 | test -f baz/boo/.git/index && |
459 | test -f baz/boo/deeper.world && | |
a0f4afbe JH |
460 | ! test -d bar |
461 | ' | |
462 | ||
0179ca7a | 463 | test_expect_success 'should clean things that almost look like git but are not' ' |
91479b9c EE |
464 | rm -fr almost_git almost_bare_git almost_submodule && |
465 | mkdir -p almost_git/.git/objects && | |
466 | mkdir -p almost_git/.git/refs && | |
467 | cat >almost_git/.git/HEAD <<-\EOF && | |
468 | garbage | |
469 | EOF | |
470 | cp -r almost_git/.git/ almost_bare_git && | |
471 | mkdir almost_submodule/ && | |
472 | cat >almost_submodule/.git <<-\EOF && | |
473 | garbage | |
474 | EOF | |
475 | test_when_finished "rm -rf almost_*" && | |
91479b9c EE |
476 | git clean -f -d && |
477 | test_path_is_missing almost_git && | |
478 | test_path_is_missing almost_bare_git && | |
479 | test_path_is_missing almost_submodule | |
480 | ' | |
481 | ||
482 | test_expect_success 'should not clean submodules' ' | |
483 | rm -fr repo to_clean sub1 sub2 && | |
484 | mkdir repo to_clean && | |
485 | ( | |
486 | cd repo && | |
487 | git init && | |
488 | test_commit msg hello.world | |
489 | ) && | |
0d3beb71 | 490 | test_config_global protocol.file.allow always && |
91479b9c EE |
491 | git submodule add ./repo/.git sub1 && |
492 | git commit -m "sub1" && | |
493 | git branch before_sub2 && | |
494 | git submodule add ./repo/.git sub2 && | |
495 | git commit -m "sub2" && | |
496 | git checkout before_sub2 && | |
497 | >to_clean/should_clean.this && | |
498 | git clean -f -d && | |
499 | test_path_is_file repo/.git/index && | |
500 | test_path_is_file repo/hello.world && | |
501 | test_path_is_file sub1/.git && | |
502 | test_path_is_file sub1/hello.world && | |
503 | test_path_is_file sub2/.git && | |
504 | test_path_is_file sub2/hello.world && | |
505 | test_path_is_missing to_clean | |
506 | ' | |
507 | ||
cadfbef9 | 508 | test_expect_success POSIXPERM,SANITY 'should avoid cleaning possible submodules' ' |
91479b9c EE |
509 | rm -fr to_clean possible_sub1 && |
510 | mkdir to_clean possible_sub1 && | |
511 | test_when_finished "rm -rf possible_sub*" && | |
512 | echo "gitdir: foo" >possible_sub1/.git && | |
513 | >possible_sub1/hello.world && | |
514 | chmod 0 possible_sub1/.git && | |
515 | >to_clean/should_clean.this && | |
516 | git clean -f -d && | |
517 | test_path_is_file possible_sub1/.git && | |
518 | test_path_is_file possible_sub1/hello.world && | |
519 | test_path_is_missing to_clean | |
520 | ' | |
521 | ||
0179ca7a | 522 | test_expect_success 'nested (empty) git should be kept' ' |
91479b9c EE |
523 | rm -fr empty_repo to_clean && |
524 | git init empty_repo && | |
525 | mkdir to_clean && | |
526 | >to_clean/should_clean.this && | |
390c5b07 PS |
527 | # Note that we put the expect file in the .git directory so that it |
528 | # does not get cleaned. | |
529 | find empty_repo | sort >.git/expect && | |
91479b9c | 530 | git clean -f -d && |
390c5b07 PS |
531 | find empty_repo | sort >actual && |
532 | test_cmp .git/expect actual && | |
91479b9c EE |
533 | test_path_is_missing to_clean |
534 | ' | |
535 | ||
536 | test_expect_success 'nested bare repositories should be cleaned' ' | |
537 | rm -fr bare1 bare2 subdir && | |
538 | git init --bare bare1 && | |
539 | git clone --local --bare . bare2 && | |
540 | mkdir subdir && | |
541 | cp -r bare2 subdir/bare3 && | |
542 | git clean -f -d && | |
543 | test_path_is_missing bare1 && | |
544 | test_path_is_missing bare2 && | |
545 | test_path_is_missing subdir | |
546 | ' | |
547 | ||
0179ca7a | 548 | test_expect_failure 'nested (empty) bare repositories should be cleaned even when in .git' ' |
91479b9c EE |
549 | rm -fr strange_bare && |
550 | mkdir strange_bare && | |
551 | git init --bare strange_bare/.git && | |
552 | git clean -f -d && | |
553 | test_path_is_missing strange_bare | |
554 | ' | |
555 | ||
556 | test_expect_failure 'nested (non-empty) bare repositories should be cleaned even when in .git' ' | |
557 | rm -fr strange_bare && | |
558 | mkdir strange_bare && | |
559 | git clone --local --bare . strange_bare/.git && | |
560 | git clean -f -d && | |
561 | test_path_is_missing strange_bare | |
562 | ' | |
563 | ||
09487f2c | 564 | test_expect_success 'giving path in nested git work tree will NOT remove it' ' |
91479b9c EE |
565 | rm -fr repo && |
566 | mkdir repo && | |
567 | ( | |
568 | cd repo && | |
569 | git init && | |
570 | mkdir -p bar/baz && | |
571 | test_commit msg bar/baz/hello.world | |
572 | ) && | |
390c5b07 | 573 | find repo | sort >expect && |
91479b9c | 574 | git clean -f -d repo/bar/baz && |
390c5b07 PS |
575 | find repo | sort >actual && |
576 | test_cmp expect actual | |
91479b9c EE |
577 | ' |
578 | ||
579 | test_expect_success 'giving path to nested .git will not remove it' ' | |
580 | rm -fr repo && | |
581 | mkdir repo untracked && | |
582 | ( | |
583 | cd repo && | |
584 | git init && | |
585 | test_commit msg hello.world | |
586 | ) && | |
390c5b07 | 587 | find repo | sort >expect && |
91479b9c | 588 | git clean -f -d repo/.git && |
390c5b07 PS |
589 | find repo | sort >actual && |
590 | test_cmp expect actual && | |
91479b9c EE |
591 | test_path_is_dir untracked/ |
592 | ' | |
593 | ||
09487f2c | 594 | test_expect_success 'giving path to nested .git/ will NOT remove contents' ' |
91479b9c EE |
595 | rm -fr repo untracked && |
596 | mkdir repo untracked && | |
597 | ( | |
598 | cd repo && | |
599 | git init && | |
600 | test_commit msg hello.world | |
601 | ) && | |
390c5b07 | 602 | find repo | sort >expect && |
91479b9c | 603 | git clean -f -d repo/.git/ && |
390c5b07 PS |
604 | find repo | sort >actual && |
605 | test_cmp expect actual && | |
91479b9c EE |
606 | test_path_is_dir untracked/ |
607 | ' | |
608 | ||
a0f4afbe | 609 | test_expect_success 'force removal of nested git work tree' ' |
ae2f203e JH |
610 | rm -fr foo bar baz && |
611 | mkdir -p foo bar baz/boo && | |
a0f4afbe JH |
612 | ( |
613 | cd foo && | |
614 | git init && | |
1733ed3d | 615 | test_commit nested hello.world |
a0f4afbe JH |
616 | ) && |
617 | ( | |
618 | cd bar && | |
619 | >goodbye.people | |
620 | ) && | |
ae2f203e JH |
621 | ( |
622 | cd baz/boo && | |
623 | git init && | |
1733ed3d | 624 | test_commit deeply.nested deeper.world |
ae2f203e | 625 | ) && |
a0f4afbe JH |
626 | git clean -f -f -d && |
627 | ! test -d foo && | |
ae2f203e JH |
628 | ! test -d bar && |
629 | ! test -d baz | |
a0f4afbe JH |
630 | ' |
631 | ||
2c76c3fe JH |
632 | test_expect_success 'git clean -e' ' |
633 | rm -fr repo && | |
634 | mkdir repo && | |
635 | ( | |
636 | cd repo && | |
637 | git init && | |
84d69402 | 638 | touch known 1 2 3 && |
2c76c3fe JH |
639 | git add known && |
640 | git clean -f -e 1 -e 2 && | |
641 | test -e 1 && | |
642 | test -e 2 && | |
643 | ! (test -e 3) && | |
644 | test -e known | |
645 | ) | |
646 | ' | |
647 | ||
0235017e AR |
648 | test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' |
649 | mkdir foo && | |
650 | chmod a= foo && | |
651 | git clean -dfx foo && | |
652 | ! test -d foo | |
653 | ' | |
654 | ||
cf424f5f JK |
655 | test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' ' |
656 | mkdir -p foo && | |
657 | mkdir -p foobar && | |
658 | git clean -df foobar && | |
659 | test_path_is_dir foo && | |
660 | test_path_is_missing foobar | |
661 | ' | |
662 | ||
663 | test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)' ' | |
664 | mkdir -p foo && | |
665 | mkdir -p foobar && | |
666 | git clean -df foo && | |
667 | test_path_is_missing foo && | |
668 | test_path_is_dir foobar | |
669 | ' | |
670 | ||
6b1db431 | 671 | test_expect_success 'git clean -d skips untracked dirs containing ignored files' ' |
b3487ccc SL |
672 | echo /foo/bar >.gitignore && |
673 | echo ignoreme >>.gitignore && | |
674 | rm -rf foo && | |
675 | mkdir -p foo/a/aa/aaa foo/b/bb/bbb && | |
676 | touch foo/bar foo/baz foo/a/aa/ignoreme foo/b/ignoreme foo/b/bb/1 foo/b/bb/2 && | |
677 | git clean -df && | |
678 | test_path_is_dir foo && | |
679 | test_path_is_file foo/bar && | |
680 | test_path_is_missing foo/baz && | |
681 | test_path_is_file foo/a/aa/ignoreme && | |
682 | test_path_is_missing foo/a/aa/aaa && | |
683 | test_path_is_file foo/b/ignoreme && | |
684 | test_path_is_missing foo/b/bb | |
685 | ' | |
686 | ||
09487f2c | 687 | test_expect_success 'git clean -d skips nested repo containing ignored files' ' |
502c386f SG |
688 | test_when_finished "rm -rf nested-repo-with-ignored-file" && |
689 | ||
690 | git init nested-repo-with-ignored-file && | |
691 | ( | |
692 | cd nested-repo-with-ignored-file && | |
693 | >file && | |
694 | git add file && | |
695 | git commit -m Initial && | |
696 | ||
697 | # This file is ignored by a .gitignore rule in the outer repo | |
698 | # added in the previous test. | |
699 | >ignoreme | |
700 | ) && | |
701 | ||
702 | git clean -fd && | |
703 | ||
704 | test_path_is_file nested-repo-with-ignored-file/.git/index && | |
705 | test_path_is_file nested-repo-with-ignored-file/ignoreme && | |
706 | test_path_is_file nested-repo-with-ignored-file/file | |
707 | ' | |
708 | ||
89a1f4aa | 709 | test_expect_success 'git clean handles being told what to clean' ' |
7541cc53 EN |
710 | mkdir -p d1 d2 && |
711 | touch d1/ut d2/ut && | |
712 | git clean -f */ut && | |
713 | test_path_is_missing d1/ut && | |
714 | test_path_is_missing d2/ut | |
715 | ' | |
716 | ||
404ebced | 717 | test_expect_success 'git clean handles being told what to clean, with -d' ' |
7541cc53 EN |
718 | mkdir -p d1 d2 && |
719 | touch d1/ut d2/ut && | |
720 | git clean -ffd */ut && | |
721 | test_path_is_missing d1/ut && | |
722 | test_path_is_missing d2/ut | |
723 | ' | |
724 | ||
89a1f4aa | 725 | test_expect_success 'git clean works if a glob is passed without -d' ' |
7541cc53 EN |
726 | mkdir -p d1 d2 && |
727 | touch d1/ut d2/ut && | |
728 | git clean -f "*ut" && | |
729 | test_path_is_missing d1/ut && | |
730 | test_path_is_missing d2/ut | |
731 | ' | |
732 | ||
404ebced | 733 | test_expect_success 'git clean works if a glob is passed with -d' ' |
7541cc53 EN |
734 | mkdir -p d1 d2 && |
735 | touch d1/ut d2/ut && | |
736 | git clean -ffd "*ut" && | |
737 | test_path_is_missing d1/ut && | |
738 | test_path_is_missing d2/ut | |
739 | ' | |
740 | ||
b09364c4 JS |
741 | test_expect_success MINGW 'handle clean & core.longpaths = false nicely' ' |
742 | test_config core.longpaths false && | |
743 | a50=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && | |
744 | mkdir -p $a50$a50/$a50$a50/$a50$a50 && | |
745 | : >"$a50$a50/test.txt" 2>"$a50$a50/$a50$a50/$a50$a50/test.txt" && | |
746 | # create a temporary outside the working tree to hide from "git clean" | |
747 | test_must_fail git clean -xdf 2>.git/err && | |
748 | # grepping for a strerror string is unportable but it is OK here with | |
749 | # MINGW prereq | |
6789275d | 750 | test_grep "too long" .git/err |
b09364c4 JS |
751 | ' |
752 | ||
22705334 | 753 | test_expect_success 'clean untracked paths by pathspec' ' |
f365bf40 DS |
754 | git init untracked && |
755 | mkdir untracked/dir && | |
756 | echo >untracked/dir/file.txt && | |
757 | git -C untracked clean -f dir/file.txt && | |
758 | ls untracked/dir >actual && | |
759 | test_must_be_empty actual | |
760 | ' | |
761 | ||
aa6e1b21 | 762 | test_expect_success 'avoid traversing into ignored directories' ' |
2e4e43a6 EN |
763 | test_when_finished rm -f output error trace.* && |
764 | test_create_repo avoid-traversing-deep-hierarchy && | |
765 | ( | |
766 | cd avoid-traversing-deep-hierarchy && | |
767 | ||
768 | mkdir -p untracked/subdir/with/a && | |
769 | >untracked/subdir/with/a/random-file.txt && | |
770 | ||
771 | GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ | |
772 | git clean -ffdxn -e untracked | |
773 | ) && | |
774 | ||
775 | # Make sure we only visited into the top-level directory, and did | |
776 | # not traverse into the "untracked" subdirectory since it was excluded | |
777 | grep data.*read_directo.*directories-visited trace.output | | |
778 | cut -d "|" -f 9 >trace.relevant && | |
779 | cat >trace.expect <<-EOF && | |
780 | ..directories-visited:1 | |
781 | EOF | |
782 | test_cmp trace.expect trace.relevant | |
783 | ' | |
784 | ||
dd55fc0d | 785 | test_expect_success 'traverse into directories that may have ignored entries' ' |
a97c7a8b EN |
786 | test_when_finished rm -f output && |
787 | test_create_repo need-to-traverse-into-hierarchy && | |
788 | ( | |
789 | cd need-to-traverse-into-hierarchy && | |
790 | mkdir -p modules/foobar/src/generated && | |
791 | > modules/foobar/src/generated/code.c && | |
792 | > modules/foobar/Makefile && | |
793 | echo "/modules/**/src/generated/" >.gitignore && | |
794 | ||
795 | git clean -fX modules/foobar >../output && | |
796 | ||
797 | grep Removing ../output && | |
798 | ||
799 | test_path_is_missing modules/foobar/src/generated/code.c && | |
800 | test_path_is_file modules/foobar/Makefile | |
801 | ) | |
802 | ' | |
803 | ||
ec0e0f25 | 804 | test_done |