1#!/bin/sh
2#
3# Copyright (c) 2007 Michael Spang
4#
5
6test_description='git-clean basic tests'
7
8. ./test-lib.sh
9
10git config clean.requireForce no
11
12test_expect_success 'setup' '
13
14 mkdir -p src &&
15 touch src/part1.c Makefile &&
16 echo build >.gitignore &&
17 echo \*.o >>.gitignore &&
18 git add . &&
19 git-commit -m setup &&
20 touch src/part2.c README &&
21 git add .
22
23'
24
25test_expect_success 'git-clean' '
26
27 mkdir -p build docs &&
28 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
29 git-clean &&
30 test -f Makefile &&
31 test -f README &&
32 test -f src/part1.c &&
33 test -f src/part2.c &&
34 test ! -f a.out &&
35 test ! -f src/part3.c &&
36 test -f docs/manual.txt &&
37 test -f obj.o &&
38 test -f build/lib.so
39
40'
41
42test_expect_success 'git-clean src/' '
43
44 mkdir -p build docs &&
45 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
46 git-clean src/ &&
47 test -f Makefile &&
48 test -f README &&
49 test -f src/part1.c &&
50 test -f src/part2.c &&
51 test -f a.out &&
52 test ! -f src/part3.c &&
53 test -f docs/manual.txt &&
54 test -f obj.o &&
55 test -f build/lib.so
56
57'
58
59test_expect_success 'git-clean src/ src/' '
60
61 mkdir -p build docs &&
62 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
63 git-clean src/ src/ &&
64 test -f Makefile &&
65 test -f README &&
66 test -f src/part1.c &&
67 test -f src/part2.c &&
68 test -f a.out &&
69 test ! -f src/part3.c &&
70 test -f docs/manual.txt &&
71 test -f obj.o &&
72 test -f build/lib.so
73
74'
75
76test_expect_success 'git-clean with prefix' '
77
78 mkdir -p build docs &&
79 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
80 (cd src/ && git-clean) &&
81 test -f Makefile &&
82 test -f README &&
83 test -f src/part1.c &&
84 test -f src/part2.c &&
85 test -f a.out &&
86 test ! -f src/part3.c &&
87 test -f docs/manual.txt &&
88 test -f obj.o &&
89 test -f build/lib.so
90
91'
92test_expect_success 'git-clean -d with prefix and path' '
93
94 mkdir -p build docs src/feature &&
95 touch a.out src/part3.c src/feature/file.c docs/manual.txt obj.o build/lib.so &&
96 (cd src/ && git-clean -d feature/) &&
97 test -f Makefile &&
98 test -f README &&
99 test -f src/part1.c &&
100 test -f src/part2.c &&
101 test -f a.out &&
102 test -f src/part3.c &&
103 test ! -f src/feature/file.c &&
104 test -f docs/manual.txt &&
105 test -f obj.o &&
106 test -f build/lib.so
107
108'
109
110test_expect_success 'git-clean symbolic link' '
111
112 mkdir -p build docs &&
113 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
114 ln -s docs/manual.txt src/part4.c
115 git-clean &&
116 test -f Makefile &&
117 test -f README &&
118 test -f src/part1.c &&
119 test -f src/part2.c &&
120 test ! -f a.out &&
121 test ! -f src/part3.c &&
122 test ! -f src/part4.c &&
123 test -f docs/manual.txt &&
124 test -f obj.o &&
125 test -f build/lib.so
126
127'
128
129test_expect_success 'git-clean with wildcard' '
130
131 touch a.clean b.clean other.c &&
132 git-clean "*.clean" &&
133 test -f Makefile &&
134 test -f README &&
135 test -f src/part1.c &&
136 test -f src/part2.c &&
137 test ! -f a.clean &&
138 test ! -f b.clean &&
139 test -f other.c
140
141'
142
143test_expect_success 'git-clean -n' '
144
145 mkdir -p build docs &&
146 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
147 git-clean -n &&
148 test -f Makefile &&
149 test -f README &&
150 test -f src/part1.c &&
151 test -f src/part2.c &&
152 test -f a.out &&
153 test -f src/part3.c &&
154 test -f docs/manual.txt &&
155 test -f obj.o &&
156 test -f build/lib.so
157
158'
159
160test_expect_success 'git-clean -d' '
161
162 mkdir -p build docs &&
163 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
164 git-clean -d &&
165 test -f Makefile &&
166 test -f README &&
167 test -f src/part1.c &&
168 test -f src/part2.c &&
169 test ! -f a.out &&
170 test ! -f src/part3.c &&
171 test ! -d docs &&
172 test -f obj.o &&
173 test -f build/lib.so
174
175'
176
177test_expect_success 'git-clean -d src/ examples/' '
178
179 mkdir -p build docs examples &&
180 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so examples/1.c &&
181 git-clean -d src/ examples/ &&
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 examples/1.c &&
189 test -f docs/manual.txt &&
190 test -f obj.o &&
191 test -f build/lib.so
192
193'
194
195test_expect_success 'git-clean -x' '
196
197 mkdir -p build docs &&
198 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
199 git-clean -x &&
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
209
210'
211
212test_expect_success 'git-clean -d -x' '
213
214 mkdir -p build docs &&
215 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
216 git-clean -d -x &&
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 ! -d build
226
227'
228
229test_expect_success 'git-clean -X' '
230
231 mkdir -p build docs &&
232 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
233 git-clean -X &&
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 docs/manual.txt &&
241 test ! -f obj.o &&
242 test -f build/lib.so
243
244'
245
246test_expect_success 'git-clean -d -X' '
247
248 mkdir -p build docs &&
249 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
250 git-clean -d -X &&
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 docs/manual.txt &&
258 test ! -f obj.o &&
259 test ! -d build
260
261'
262
263test_expect_success 'clean.requireForce defaults to true' '
264
265 git config --unset clean.requireForce &&
266 ! git-clean
267
268'
269
270test_expect_success 'clean.requireForce' '
271
272 git config clean.requireForce true &&
273 ! git-clean
274
275'
276
277test_expect_success 'clean.requireForce and -n' '
278
279 mkdir -p build docs &&
280 touch a.out src/part3.c docs/manual.txt obj.o build/lib.so &&
281 git-clean -n &&
282 test -f Makefile &&
283 test -f README &&
284 test -f src/part1.c &&
285 test -f src/part2.c &&
286 test -f a.out &&
287 test -f src/part3.c &&
288 test -f docs/manual.txt &&
289 test -f obj.o &&
290 test -f build/lib.so
291
292'
293
294test_expect_success 'clean.requireForce and -f' '
295
296 git-clean -f &&
297 test -f README &&
298 test -f src/part1.c &&
299 test -f src/part2.c &&
300 test ! -f a.out &&
301 test ! -f src/part3.c &&
302 test -f docs/manual.txt &&
303 test -f obj.o &&
304 test -f build/lib.so
305
306'
307
308test_expect_success 'core.excludesfile' '
309
310 echo excludes >excludes &&
311 echo included >included &&
312 git config core.excludesfile excludes &&
313 output=$(git clean -n excludes included 2>&1) &&
314 expr "$output" : ".*included" >/dev/null &&
315 ! expr "$output" : ".*excludes" >/dev/null
316
317'
318
319test_expect_success 'removal failure' '
320
321 mkdir foo &&
322 touch foo/bar &&
323 exec <foo/bar &&
324 chmod 0 foo &&
325 test_must_fail git clean -f -d
326
327'
328chmod 755 foo
329
330test_done