git-clean: add tests for relative path
[git/trast.git] / t / t7300-clean.sh
blobafccfc9973ba864167387b1e1caf6fe8b12f68f9
1 #!/bin/sh
3 # Copyright (c) 2007 Michael Spang
6 test_description='git-clean basic tests'
8 . ./test-lib.sh
10 git config clean.requireForce no
12 test_expect_success 'setup' '
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 .
25 test_expect_success 'git-clean' '
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
42 test_expect_success 'git-clean src/' '
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
59 test_expect_success 'git-clean src/ src/' '
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
76 test_expect_success 'git-clean with prefix' '
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
93 test_expect_success 'git-clean with relative prefix' '
95 mkdir -p build docs &&
96 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
97 would_clean=$(
98 cd docs &&
99 git clean -n ../src |
100 sed -n -e "s|^Would remove ||p"
101 ) &&
102 test "$would_clean" = ../src/part3.c || {
103 echo "OOps <$would_clean>"
104 false
108 test_expect_success 'git-clean with absolute path' '
110 mkdir -p build docs &&
111 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
112 would_clean=$(
113 cd docs &&
114 git clean -n $(pwd)/../src |
115 sed -n -e "s|^Would remove ||p"
116 ) &&
117 test "$would_clean" = ../src/part3.c || {
118 echo "OOps <$would_clean>"
119 false
123 test_expect_success 'git-clean with out of work tree relative path' '
125 mkdir -p build docs &&
126 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
128 cd docs &&
129 test_must_fail git clean -n ../..
133 test_expect_success 'git-clean with out of work tree absolute path' '
135 mkdir -p build docs &&
136 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
137 dd=$(cd .. && pwd) &&
139 cd docs &&
140 test_must_fail git clean -n $dd
144 test_expect_success 'git-clean -d with prefix and path' '
146 mkdir -p build docs src/feature &&
147 touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
148 (cd src/ && git-clean -d feature/) &&
149 test -f Makefile &&
150 test -f README &&
151 test -f src/part1.c &&
152 test -f src/part2.c &&
153 test -f a.out &&
154 test -f src/part3.c &&
155 test ! -f src/feature/file.c &&
156 test -f docs/manual.txt &&
157 test -f obj.o &&
158 test -f build/lib.so
162 test_expect_success 'git-clean symbolic link' '
164 mkdir -p build docs &&
165 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
166 ln -s docs/manual.txt src/part4.c
167 git-clean &&
168 test -f Makefile &&
169 test -f README &&
170 test -f src/part1.c &&
171 test -f src/part2.c &&
172 test ! -f a.out &&
173 test ! -f src/part3.c &&
174 test ! -f src/part4.c &&
175 test -f docs/manual.txt &&
176 test -f obj.o &&
177 test -f build/lib.so
181 test_expect_success 'git-clean with wildcard' '
183 touch a.clean b.clean other.c &&
184 git-clean "*.clean" &&
185 test -f Makefile &&
186 test -f README &&
187 test -f src/part1.c &&
188 test -f src/part2.c &&
189 test ! -f a.clean &&
190 test ! -f b.clean &&
191 test -f other.c
195 test_expect_success 'git-clean -n' '
197 mkdir -p build docs &&
198 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
199 git-clean -n &&
200 test -f Makefile &&
201 test -f README &&
202 test -f src/part1.c &&
203 test -f src/part2.c &&
204 test -f a.out &&
205 test -f src/part3.c &&
206 test -f docs/manual.txt &&
207 test -f obj.o &&
208 test -f build/lib.so
212 test_expect_success 'git-clean -d' '
214 mkdir -p build docs &&
215 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
216 git-clean -d &&
217 test -f Makefile &&
218 test -f README &&
219 test -f src/part1.c &&
220 test -f src/part2.c &&
221 test ! -f a.out &&
222 test ! -f src/part3.c &&
223 test ! -d docs &&
224 test -f obj.o &&
225 test -f build/lib.so
229 test_expect_success 'git-clean -d src/ examples/' '
231 mkdir -p build docs examples &&
232 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
233 git-clean -d src/ examples/ &&
234 test -f Makefile &&
235 test -f README &&
236 test -f src/part1.c &&
237 test -f src/part2.c &&
238 test -f a.out &&
239 test ! -f src/part3.c &&
240 test ! -f examples/1.c &&
241 test -f docs/manual.txt &&
242 test -f obj.o &&
243 test -f build/lib.so
247 test_expect_success 'git-clean -x' '
249 mkdir -p build docs &&
250 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
251 git-clean -x &&
252 test -f Makefile &&
253 test -f README &&
254 test -f src/part1.c &&
255 test -f src/part2.c &&
256 test ! -f a.out &&
257 test ! -f src/part3.c &&
258 test -f docs/manual.txt &&
259 test ! -f obj.o &&
260 test -f build/lib.so
264 test_expect_success 'git-clean -d -x' '
266 mkdir -p build docs &&
267 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
268 git-clean -d -x &&
269 test -f Makefile &&
270 test -f README &&
271 test -f src/part1.c &&
272 test -f src/part2.c &&
273 test ! -f a.out &&
274 test ! -f src/part3.c &&
275 test ! -d docs &&
276 test ! -f obj.o &&
277 test ! -d build
281 test_expect_success 'git-clean -X' '
283 mkdir -p build docs &&
284 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
285 git-clean -X &&
286 test -f Makefile &&
287 test -f README &&
288 test -f src/part1.c &&
289 test -f src/part2.c &&
290 test -f a.out &&
291 test -f src/part3.c &&
292 test -f docs/manual.txt &&
293 test ! -f obj.o &&
294 test -f build/lib.so
298 test_expect_success 'git-clean -d -X' '
300 mkdir -p build docs &&
301 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
302 git-clean -d -X &&
303 test -f Makefile &&
304 test -f README &&
305 test -f src/part1.c &&
306 test -f src/part2.c &&
307 test -f a.out &&
308 test -f src/part3.c &&
309 test -f docs/manual.txt &&
310 test ! -f obj.o &&
311 test ! -d build
315 test_expect_success 'clean.requireForce defaults to true' '
317 git config --unset clean.requireForce &&
318 ! git-clean
322 test_expect_success 'clean.requireForce' '
324 git config clean.requireForce true &&
325 ! git-clean
329 test_expect_success 'clean.requireForce and -n' '
331 mkdir -p build docs &&
332 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
333 git-clean -n &&
334 test -f Makefile &&
335 test -f README &&
336 test -f src/part1.c &&
337 test -f src/part2.c &&
338 test -f a.out &&
339 test -f src/part3.c &&
340 test -f docs/manual.txt &&
341 test -f obj.o &&
342 test -f build/lib.so
346 test_expect_success 'clean.requireForce and -f' '
348 git-clean -f &&
349 test -f README &&
350 test -f src/part1.c &&
351 test -f src/part2.c &&
352 test ! -f a.out &&
353 test ! -f src/part3.c &&
354 test -f docs/manual.txt &&
355 test -f obj.o &&
356 test -f build/lib.so
360 test_expect_success 'core.excludesfile' '
362 echo excludes >excludes &&
363 echo included >included &&
364 git config core.excludesfile excludes &&
365 output=$(git clean -n excludes included 2>&1) &&
366 expr "$output" : ".*included" >/dev/null &&
367 ! expr "$output" : ".*excludes" >/dev/null
371 test_expect_success 'removal failure' '
373 mkdir foo &&
374 touch foo/bar &&
375 exec <foo/bar &&
376 chmod 0 foo &&
377 test_must_fail git clean -f -d
380 chmod 755 foo
382 test_done