Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 test_add_basic() {
20 local testroot=`test_init add_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret=$?
24 if [ $ret -ne 0 ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "new file" > $testroot/wt/foo
31 echo 'A foo' > $testroot/stdout.expected
32 (cd $testroot/wt && got add foo > $testroot/stdout)
34 cmp -s $testroot/stdout.expected $testroot/stdout
35 ret=$?
36 if [ $ret -ne 0 ]; then
37 diff -u $testroot/stdout.expected $testroot/stdout
38 fi
39 test_done "$testroot" "$ret"
40 }
42 test_double_add() {
43 local testroot=`test_init double_add`
45 got checkout $testroot/repo $testroot/wt > /dev/null
46 ret=$?
47 if [ $ret -ne 0 ]; then
48 test_done "$testroot" "$ret"
49 return 1
50 fi
52 echo "new file" > $testroot/wt/foo
53 (cd $testroot/wt && got add foo > /dev/null)
55 (cd $testroot/wt && got add foo > $testroot/stdout)
56 ret=$?
57 if [ $ret -ne 0 ]; then
58 echo "got add failed unexpectedly" >&2
59 test_done "$testroot" 1
60 return 1
61 fi
63 echo -n > $testroot/stdout.expected
64 cmp -s $testroot/stdout.expected $testroot/stdout
65 ret=$?
66 if [ $ret -ne 0 ]; then
67 diff -u $testroot/stdout.expected $testroot/stdout
68 fi
69 test_done "$testroot" "$ret"
70 }
72 test_add_multiple() {
73 local testroot=`test_init multiple_add`
75 got checkout $testroot/repo $testroot/wt > /dev/null
76 ret=$?
77 if [ $ret -ne 0 ]; then
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 echo "new file" > $testroot/wt/foo
83 echo "new file" > $testroot/wt/bar
84 echo "new file" > $testroot/wt/baz
85 (cd $testroot/wt && got add foo bar baz > $testroot/stdout)
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 echo "got add failed unexpectedly" >&2
89 test_done "$testroot" 1
90 return 1
91 fi
93 echo "A bar" > $testroot/stdout.expected
94 echo "A baz" >> $testroot/stdout.expected
95 echo "A foo" >> $testroot/stdout.expected
97 cmp -s $testroot/stdout.expected $testroot/stdout
98 ret=$?
99 if [ $ret -ne 0 ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 test_done "$testroot" "$ret"
102 return 1
103 fi
105 echo "new file" > $testroot/wt/bax
106 (cd $testroot/wt && got add -R * > $testroot/stdout)
107 ret=$?
108 if [ $ret -ne 0 ]; then
109 echo "got add failed unexpectedly" >&2
110 test_done "$testroot" 1
111 return 1
112 fi
114 echo "A bax" > $testroot/stdout.expected
116 cmp -s $testroot/stdout.expected $testroot/stdout
117 ret=$?
118 if [ $ret -ne 0 ]; then
119 diff -u $testroot/stdout.expected $testroot/stdout
120 fi
122 test_done "$testroot" "$ret"
125 test_add_file_in_new_subdir() {
126 local testroot=`test_init add_file_in_new_subdir`
128 got checkout $testroot/repo $testroot/wt > /dev/null
129 ret=$?
130 if [ $ret -ne 0 ]; then
131 test_done "$testroot" "$ret"
132 return 1
133 fi
135 mkdir -p $testroot/wt/new
136 echo "new file" > $testroot/wt/new/foo
138 echo 'A new/foo' > $testroot/stdout.expected
139 (cd $testroot/wt && got add new/foo > $testroot/stdout)
141 cmp -s $testroot/stdout.expected $testroot/stdout
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 diff -u $testroot/stdout.expected $testroot/stdout
145 fi
146 test_done "$testroot" "$ret"
149 test_add_deleted() {
150 local testroot=`test_init add_deleted`
152 got checkout $testroot/repo $testroot/wt > /dev/null
153 ret=$?
154 if [ $ret -ne 0 ]; then
155 test_done "$testroot" "$ret"
156 return 1
157 fi
159 (cd $testroot/wt && got rm beta > /dev/null)
161 echo -n > $testroot/stdout.expected
162 (cd $testroot/wt && got add beta > $testroot/stdout 2> $testroot/stderr)
163 ret=$?
164 if [ $ret -eq 0 ]; then
165 echo "got add command succeeded unexpectedly" >&2
166 diff -u $testroot/stdout.expected $testroot/stdout
167 test_done "$testroot" "1"
168 return 1
169 fi
171 echo "got: beta: file has unexpected status" > $testroot/stderr.expected
172 cmp -s $testroot/stderr.expected $testroot/stderr
173 ret=$?
174 if [ $ret -ne 0 ]; then
175 diff -u $testroot/stderr.expected $testroot/stderr
176 fi
177 test_done "$testroot" "$ret"
180 test_add_directory() {
181 local testroot=`test_init add_directory`
183 got checkout $testroot/repo $testroot/wt > /dev/null
184 ret=$?
185 if [ $ret -ne 0 ]; then
186 test_done "$testroot" "$ret"
187 return 1
188 fi
190 (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
191 ret=$?
192 echo "got: adding directories requires -R option" \
193 > $testroot/stderr.expected
194 cmp -s $testroot/stderr.expected $testroot/stderr
195 ret=$?
196 if [ $ret -ne 0 ]; then
197 diff -u $testroot/stderr.expected $testroot/stderr
198 test_done "$testroot" "$ret"
199 return 1
200 fi
202 (cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
203 ret=$?
204 echo "got: adding directories requires -R option" \
205 > $testroot/stderr.expected
206 cmp -s $testroot/stderr.expected $testroot/stderr
207 ret=$?
208 if [ $ret -ne 0 ]; then
209 diff -u $testroot/stderr.expected $testroot/stderr
210 test_done "$testroot" "$ret"
211 return 1
212 fi
214 echo -n > $testroot/stdout.expected
215 cmp -s $testroot/stdout.expected $testroot/stdout
216 ret=$?
217 if [ $ret -ne 0 ]; then
218 diff -u $testroot/stdout.expected $testroot/stdout
219 test_done "$testroot" "$ret"
220 return 1
221 fi
223 mkdir -p $testroot/wt/tree1
224 mkdir -p $testroot/wt/tree2
225 echo "tree1/**" > $testroot/wt/.gitignore
226 echo "tree2/**" >> $testroot/wt/.gitignore
227 echo -n > $testroot/wt/tree1/foo
228 echo -n > $testroot/wt/tree2/foo
229 echo -n > $testroot/wt/epsilon/zeta1
230 echo -n > $testroot/wt/epsilon/zeta2
232 (cd $testroot/wt && got add -R . > $testroot/stdout)
234 echo 'A .gitignore' > $testroot/stdout.expected
235 echo 'A epsilon/zeta1' >> $testroot/stdout.expected
236 echo 'A epsilon/zeta2' >> $testroot/stdout.expected
238 cmp -s $testroot/stdout.expected $testroot/stdout
239 ret=$?
240 if [ $ret -ne 0 ]; then
241 diff -u $testroot/stdout.expected $testroot/stdout
242 test_done "$testroot" "$ret"
243 return 1
244 fi
246 (cd $testroot/wt && got add -RI tree1 > $testroot/stdout)
248 echo 'A tree1/foo' > $testroot/stdout.expected
250 cmp -s $testroot/stdout.expected $testroot/stdout
251 ret=$?
252 if [ $ret -ne 0 ]; then
253 diff -u $testroot/stdout.expected $testroot/stdout
254 test_done "$testroot" "$ret"
255 return 1
256 fi
258 (cd $testroot/wt && got add tree2/foo > $testroot/stdout)
260 echo -n '' > $testroot/stdout.expected
262 cmp -s $testroot/stdout.expected $testroot/stdout
263 ret=$?
264 if [ $ret -ne 0 ]; then
265 diff -u $testroot/stdout.expected $testroot/stdout
266 test_done "$testroot" "$ret"
267 return 1
268 fi
270 (cd $testroot/wt && got add -I tree2/foo > $testroot/stdout)
272 echo 'A tree2/foo' > $testroot/stdout.expected
274 cmp -s $testroot/stdout.expected $testroot/stdout
275 ret=$?
276 if [ $ret -ne 0 ]; then
277 diff -u $testroot/stdout.expected $testroot/stdout
278 test_done "$testroot" "$ret"
279 return 1
280 fi
281 test_done "$testroot" "$ret"
284 test_add_clashes_with_submodule() {
285 local testroot=`test_init add_clashes_with_submodule`
287 make_single_file_repo $testroot/repo2 foo
289 (cd $testroot/repo && git -c protocol.file.allow=always \
290 submodule -q add ../repo2)
291 (cd $testroot/repo && git commit -q -m 'adding submodule')
293 got checkout $testroot/repo $testroot/wt > /dev/null
295 # Atttempt to add a file clashes with a submodule
296 echo "This is a file called repo2" > $testroot/wt/repo2
297 (cd $testroot/wt && got add repo2 > /dev/null)
299 (cd $testroot/wt && got status > $testroot/stdout)
300 echo "A repo2" > $testroot/stdout.expected
301 cmp -s $testroot/stdout.expected $testroot/stdout
302 ret=$?
303 if [ $ret -ne 0 ]; then
304 diff -u $testroot/stdout.expected $testroot/stdout
305 test_done "$testroot" "$ret"
306 return 1
307 fi
309 # Update for good measure; see the error below.
310 (cd $testroot/wt && got update > /dev/null)
312 # This currently fails with "work tree must be updated"...
313 (cd $testroot/wt && got commit -m 'add file repo2' \
314 > $testroot/stdout 2> $testroot/stderr)
315 ret=$?
316 if [ $ret -eq 0 ]; then
317 echo "commit succeeded unexpectedly" >&2
318 test_done "$testroot" "1"
319 return 1
320 fi
322 echo -n "got: work tree must be updated " > $testroot/stderr.expected
323 echo "before these changes can be committed" >> $testroot/stderr.expected
324 cmp -s $testroot/stderr.expected $testroot/stderr
325 ret=$?
326 if [ $ret -ne 0 ]; then
327 diff -u $testroot/stderr.expected $testroot/stderr
328 fi
329 test_done "$testroot" "$ret"
332 test_add_symlink() {
333 local testroot=`test_init add_symlink`
335 got checkout $testroot/repo $testroot/wt > /dev/null
336 ret=$?
337 if [ $ret -ne 0 ]; then
338 test_done "$testroot" "$ret"
339 return 1
340 fi
342 (cd $testroot/wt && ln -s alpha alpha.link)
343 (cd $testroot/wt && ln -s epsilon epsilon.link)
344 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
345 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
346 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
348 echo "A alpha.link" > $testroot/stdout.expected
349 (cd $testroot/wt && got add alpha.link > $testroot/stdout)
350 ret=$?
351 if [ $ret -ne 0 ]; then
352 diff -u $testroot/stdout.expected $testroot/stdout
353 test_done "$testroot" "$ret"
354 return 1
355 fi
357 echo "A epsilon.link" > $testroot/stdout.expected
358 (cd $testroot/wt && got add epsilon.link > $testroot/stdout)
359 cmp -s $testroot/stdout.expected $testroot/stdout
360 ret=$?
361 if [ $ret -ne 0 ]; then
362 diff -u $testroot/stdout.expected $testroot/stdout
363 test_done "$testroot" "$ret"
364 return 1
365 fi
367 echo "A passwd.link" > $testroot/stdout.expected
368 (cd $testroot/wt && got add passwd.link > $testroot/stdout)
369 cmp -s $testroot/stdout.expected $testroot/stdout
370 ret=$?
371 if [ $ret -ne 0 ]; then
372 diff -u $testroot/stdout.expected $testroot/stdout
373 test_done "$testroot" "$ret"
374 return 1
375 fi
377 echo "A epsilon/beta.link" > $testroot/stdout.expected
378 (cd $testroot/wt && got add epsilon/beta.link > $testroot/stdout)
379 cmp -s $testroot/stdout.expected $testroot/stdout
380 ret=$?
381 if [ $ret -ne 0 ]; then
382 diff -u $testroot/stdout.expected $testroot/stdout
383 test_done "$testroot" "$ret"
384 return 1
385 fi
387 echo "A nonexistent.link" > $testroot/stdout.expected
388 (cd $testroot/wt && got add nonexistent.link > $testroot/stdout)
389 cmp -s $testroot/stdout.expected $testroot/stdout
390 ret=$?
391 if [ $ret -ne 0 ]; then
392 diff -u $testroot/stdout.expected $testroot/stdout
393 fi
394 test_done "$testroot" "$ret"
397 test_parseargs "$@"
398 run_test test_add_basic
399 run_test test_double_add
400 run_test test_add_multiple
401 run_test test_add_file_in_new_subdir
402 run_test test_add_deleted
403 run_test test_add_directory
404 run_test test_add_clashes_with_submodule
405 run_test test_add_symlink