portable: release 0.93
[got-portable.git] / regress / cmdline / add.sh
blob31567d2fc90dcccd8d23c81bc042414e05d514b1
1 #!/bin/sh
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
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.
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
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
39 test_done "$testroot" "$ret"
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
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
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 test_done "$testroot" "$ret"
69 return 1
72 echo "new file" > $testroot/wt/epsilon/zeta2
73 (cd $testroot/wt && got add epsilon/zeta* > $testroot/stdout)
74 ret=$?
75 if [ $ret -ne 0 ]; then
76 echo "got add failed unexpectedly" >&2
77 test_done "$testroot" 1
78 return 1
81 echo 'A epsilon/zeta2' > $testroot/stdout.expected
82 cmp -s $testroot/stdout.expected $testroot/stdout
83 ret=$?
84 if [ $ret -ne 0 ]; then
85 diff -u $testroot/stdout.expected $testroot/stdout
87 test_done "$testroot" "$ret"
90 test_add_multiple() {
91 local testroot=`test_init multiple_add`
93 got checkout $testroot/repo $testroot/wt > /dev/null
94 ret=$?
95 if [ $ret -ne 0 ]; then
96 test_done "$testroot" "$ret"
97 return 1
100 echo "new file" > $testroot/wt/foo
101 echo "new file" > $testroot/wt/bar
102 echo "new file" > $testroot/wt/baz
103 (cd $testroot/wt && got add foo bar baz > $testroot/stdout)
104 ret=$?
105 if [ $ret -ne 0 ]; then
106 echo "got add failed unexpectedly" >&2
107 test_done "$testroot" 1
108 return 1
111 echo "A bar" > $testroot/stdout.expected
112 echo "A baz" >> $testroot/stdout.expected
113 echo "A foo" >> $testroot/stdout.expected
115 cmp -s $testroot/stdout.expected $testroot/stdout
116 ret=$?
117 if [ $ret -ne 0 ]; then
118 diff -u $testroot/stdout.expected $testroot/stdout
119 test_done "$testroot" "$ret"
120 return 1
123 echo "changed file" > $testroot/wt/alpha
124 echo "new file" > $testroot/wt/bax
125 (cd $testroot/wt && got add -R * > $testroot/stdout)
126 ret=$?
127 if [ $ret -ne 0 ]; then
128 echo "got add failed unexpectedly" >&2
129 test_done "$testroot" 1
130 return 1
133 echo "A bax" > $testroot/stdout.expected
135 cmp -s $testroot/stdout.expected $testroot/stdout
136 ret=$?
137 if [ $ret -ne 0 ]; then
138 diff -u $testroot/stdout.expected $testroot/stdout
141 test_done "$testroot" "$ret"
144 test_add_file_in_new_subdir() {
145 local testroot=`test_init add_file_in_new_subdir`
147 got checkout $testroot/repo $testroot/wt > /dev/null
148 ret=$?
149 if [ $ret -ne 0 ]; then
150 test_done "$testroot" "$ret"
151 return 1
154 mkdir -p $testroot/wt/new
155 echo "new file" > $testroot/wt/new/foo
157 echo 'A new/foo' > $testroot/stdout.expected
158 (cd $testroot/wt && got add new/foo > $testroot/stdout)
160 cmp -s $testroot/stdout.expected $testroot/stdout
161 ret=$?
162 if [ $ret -ne 0 ]; then
163 diff -u $testroot/stdout.expected $testroot/stdout
165 test_done "$testroot" "$ret"
168 test_add_deleted() {
169 local testroot=`test_init add_deleted`
171 got checkout $testroot/repo $testroot/wt > /dev/null
172 ret=$?
173 if [ $ret -ne 0 ]; then
174 test_done "$testroot" "$ret"
175 return 1
178 (cd $testroot/wt && got rm beta > /dev/null)
180 echo -n > $testroot/stdout.expected
181 (cd $testroot/wt && got add beta > $testroot/stdout 2> $testroot/stderr)
182 ret=$?
183 if [ $ret -eq 0 ]; then
184 echo "got add command succeeded unexpectedly" >&2
185 diff -u $testroot/stdout.expected $testroot/stdout
186 test_done "$testroot" "1"
187 return 1
190 echo "got: beta: file has unexpected status" > $testroot/stderr.expected
191 cmp -s $testroot/stderr.expected $testroot/stderr
192 ret=$?
193 if [ $ret -ne 0 ]; then
194 diff -u $testroot/stderr.expected $testroot/stderr
196 test_done "$testroot" "$ret"
199 test_add_force_delete_commit() {
200 local testroot=`test_init add_force_delete_commit`
202 got checkout $testroot/repo $testroot/wt > /dev/null
203 ret=$?
204 if [ $ret -ne 0 ]; then
205 test_done "$testroot" "$ret"
206 return 1
209 echo new > $testroot/wt/new
211 echo -n > $testroot/stdout.expected
212 (cd $testroot/wt && got add new > $testroot/stdout 2> $testroot/stderr)
213 ret=$?
214 if [ $ret -ne 0 ]; then
215 echo "got add command failed unexpectedly" >&2
216 diff -u $testroot/stdout.expected $testroot/stdout
217 test_done "$testroot" "1"
218 return 1
221 (cd $testroot/wt && mv new new2 > $testroot/stdout 2> $testroot/stderr)
222 ret=$?
223 if [ $ret -ne 0 ]; then
224 echo "rename the file failed unexpectedly" >&2
225 ls beta2
226 test_done "$testroot" "1"
227 return 1
231 (cd $testroot/wt && got add new2 > $testroot/stdout 2> $testroot/stderr)
232 ret=$?
233 if [ $ret -ne 0 ]; then
234 echo "got add command failed unexpectedly" >&2
235 test_done "$testroot" "1"
236 return 1
239 # File 'new' was once in A status (locally added) but is now
240 # in "!" (missing) status since it was never committed.
241 # Removing it effectively reverts the local addition.
242 (cd $testroot/wt && got remove -f new > $testroot/stdout \
243 2> $testroot/stderr)
244 ret=$?
245 if [ $ret -ne 0 ]; then
246 echo "got remove -f command failed unexpectedly" >&2
247 test_done "$testroot" "1"
248 return 1
251 (cd $testroot/wt && got status > $testroot/stdout)
253 echo 'A new2' > $testroot/stdout.expected
254 cmp -s $testroot/stdout.expected $testroot/stdout
255 ret=$?
256 if [ $ret -ne 0 ]; then
257 diff -u $testroot/stdout.expected $testroot/stdout
258 test_done "$testroot" "$ret"
259 return 1
262 (cd $testroot/wt && got commit -m "add force remove commit" \
263 > $testroot/stdout 2> $testroot/stderr)
264 ret=$?
265 if [ $ret -ne 0 ]; then
266 echo "got commit command failed unexpectedly" >&2
268 test_done "$testroot" "$ret"
271 test_add_directory() {
272 local testroot=`test_init add_directory`
274 got checkout $testroot/repo $testroot/wt > /dev/null
275 ret=$?
276 if [ $ret -ne 0 ]; then
277 test_done "$testroot" "$ret"
278 return 1
281 (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
282 ret=$?
283 echo "got: adding directories requires -R option" \
284 > $testroot/stderr.expected
285 cmp -s $testroot/stderr.expected $testroot/stderr
286 ret=$?
287 if [ $ret -ne 0 ]; then
288 diff -u $testroot/stderr.expected $testroot/stderr
289 test_done "$testroot" "$ret"
290 return 1
293 (cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
294 ret=$?
295 echo "got: adding directories requires -R option" \
296 > $testroot/stderr.expected
297 cmp -s $testroot/stderr.expected $testroot/stderr
298 ret=$?
299 if [ $ret -ne 0 ]; then
300 diff -u $testroot/stderr.expected $testroot/stderr
301 test_done "$testroot" "$ret"
302 return 1
305 echo -n > $testroot/stdout.expected
306 cmp -s $testroot/stdout.expected $testroot/stdout
307 ret=$?
308 if [ $ret -ne 0 ]; then
309 diff -u $testroot/stdout.expected $testroot/stdout
310 test_done "$testroot" "$ret"
311 return 1
314 mkdir -p $testroot/wt/tree1
315 mkdir -p $testroot/wt/tree2
316 echo "tree1/**" > $testroot/wt/.gitignore
317 echo "tree2/**" >> $testroot/wt/.gitignore
318 echo -n > $testroot/wt/tree1/foo
319 echo -n > $testroot/wt/tree2/foo
320 echo -n > $testroot/wt/epsilon/zeta1
321 echo -n > $testroot/wt/epsilon/zeta2
323 (cd $testroot/wt && got add -R . > $testroot/stdout)
325 echo 'A .gitignore' > $testroot/stdout.expected
326 echo 'A epsilon/zeta1' >> $testroot/stdout.expected
327 echo 'A epsilon/zeta2' >> $testroot/stdout.expected
329 cmp -s $testroot/stdout.expected $testroot/stdout
330 ret=$?
331 if [ $ret -ne 0 ]; then
332 diff -u $testroot/stdout.expected $testroot/stdout
333 test_done "$testroot" "$ret"
334 return 1
337 (cd $testroot/wt && got add -RI tree1 > $testroot/stdout)
339 echo 'A tree1/foo' > $testroot/stdout.expected
341 cmp -s $testroot/stdout.expected $testroot/stdout
342 ret=$?
343 if [ $ret -ne 0 ]; then
344 diff -u $testroot/stdout.expected $testroot/stdout
345 test_done "$testroot" "$ret"
346 return 1
349 (cd $testroot/wt && got add tree2/foo > $testroot/stdout)
351 echo -n '' > $testroot/stdout.expected
353 cmp -s $testroot/stdout.expected $testroot/stdout
354 ret=$?
355 if [ $ret -ne 0 ]; then
356 diff -u $testroot/stdout.expected $testroot/stdout
357 test_done "$testroot" "$ret"
358 return 1
361 (cd $testroot/wt && got add -I tree2/foo > $testroot/stdout)
363 echo 'A tree2/foo' > $testroot/stdout.expected
365 cmp -s $testroot/stdout.expected $testroot/stdout
366 ret=$?
367 if [ $ret -ne 0 ]; then
368 diff -u $testroot/stdout.expected $testroot/stdout
369 test_done "$testroot" "$ret"
370 return 1
372 test_done "$testroot" "$ret"
375 test_add_clashes_with_submodule() {
376 local testroot=`test_init add_clashes_with_submodule`
378 make_single_file_repo $testroot/repo2 foo
380 (cd $testroot/repo && git -c protocol.file.allow=always \
381 submodule -q add ../repo2)
382 (cd $testroot/repo && git commit -q -m 'adding submodule')
384 got checkout $testroot/repo $testroot/wt > /dev/null
386 # Atttempt to add a file clashes with a submodule
387 echo "This is a file called repo2" > $testroot/wt/repo2
388 (cd $testroot/wt && got add repo2 > /dev/null)
390 (cd $testroot/wt && got status > $testroot/stdout)
391 echo "A repo2" > $testroot/stdout.expected
392 cmp -s $testroot/stdout.expected $testroot/stdout
393 ret=$?
394 if [ $ret -ne 0 ]; then
395 diff -u $testroot/stdout.expected $testroot/stdout
396 test_done "$testroot" "$ret"
397 return 1
400 # Update for good measure; see the error below.
401 (cd $testroot/wt && got update > /dev/null)
403 # This currently fails with "work tree must be updated"...
404 (cd $testroot/wt && got commit -m 'add file repo2' \
405 > $testroot/stdout 2> $testroot/stderr)
406 ret=$?
407 if [ $ret -eq 0 ]; then
408 echo "commit succeeded unexpectedly" >&2
409 test_done "$testroot" "1"
410 return 1
413 echo -n "got: work tree must be updated " > $testroot/stderr.expected
414 echo "before these changes can be committed" >> $testroot/stderr.expected
415 cmp -s $testroot/stderr.expected $testroot/stderr
416 ret=$?
417 if [ $ret -ne 0 ]; then
418 diff -u $testroot/stderr.expected $testroot/stderr
420 test_done "$testroot" "$ret"
423 test_add_symlink() {
424 local testroot=`test_init add_symlink`
426 got checkout $testroot/repo $testroot/wt > /dev/null
427 ret=$?
428 if [ $ret -ne 0 ]; then
429 test_done "$testroot" "$ret"
430 return 1
433 (cd $testroot/wt && ln -s alpha alpha.link)
434 (cd $testroot/wt && ln -s epsilon epsilon.link)
435 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
436 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
437 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
439 echo "A alpha.link" > $testroot/stdout.expected
440 (cd $testroot/wt && got add alpha.link > $testroot/stdout)
441 ret=$?
442 if [ $ret -ne 0 ]; then
443 diff -u $testroot/stdout.expected $testroot/stdout
444 test_done "$testroot" "$ret"
445 return 1
448 echo "A epsilon.link" > $testroot/stdout.expected
449 (cd $testroot/wt && got add epsilon.link > $testroot/stdout)
450 cmp -s $testroot/stdout.expected $testroot/stdout
451 ret=$?
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/stdout.expected $testroot/stdout
454 test_done "$testroot" "$ret"
455 return 1
458 echo "A passwd.link" > $testroot/stdout.expected
459 (cd $testroot/wt && got add passwd.link > $testroot/stdout)
460 cmp -s $testroot/stdout.expected $testroot/stdout
461 ret=$?
462 if [ $ret -ne 0 ]; then
463 diff -u $testroot/stdout.expected $testroot/stdout
464 test_done "$testroot" "$ret"
465 return 1
468 echo "A epsilon/beta.link" > $testroot/stdout.expected
469 (cd $testroot/wt && got add epsilon/beta.link > $testroot/stdout)
470 cmp -s $testroot/stdout.expected $testroot/stdout
471 ret=$?
472 if [ $ret -ne 0 ]; then
473 diff -u $testroot/stdout.expected $testroot/stdout
474 test_done "$testroot" "$ret"
475 return 1
478 echo "A nonexistent.link" > $testroot/stdout.expected
479 (cd $testroot/wt && got add nonexistent.link > $testroot/stdout)
480 cmp -s $testroot/stdout.expected $testroot/stdout
481 ret=$?
482 if [ $ret -ne 0 ]; then
483 diff -u $testroot/stdout.expected $testroot/stdout
485 test_done "$testroot" "$ret"
488 test_parseargs "$@"
489 run_test test_add_basic
490 run_test test_double_add
491 run_test test_add_multiple
492 run_test test_add_file_in_new_subdir
493 run_test test_add_deleted
494 run_test test_add_force_delete_commit
495 run_test test_add_directory
496 run_test test_add_clashes_with_submodule
497 run_test test_add_symlink