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.
20 local testroot
=`test_init add_basic`
22 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
24 if [ $ret -ne 0 ]; then
25 test_done
"$testroot" "$ret"
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
36 if [ $ret -ne 0 ]; then
37 diff -u $testroot/stdout.expected
$testroot/stdout
39 test_done
"$testroot" "$ret"
43 local testroot
=`test_init double_add`
45 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
47 if [ $ret -ne 0 ]; then
48 test_done
"$testroot" "$ret"
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
)
57 if [ $ret -ne 0 ]; then
58 echo "got add failed unexpectedly" >&2
59 test_done
"$testroot" 1
63 echo -n > $testroot/stdout.expected
64 cmp -s $testroot/stdout.expected
$testroot/stdout
66 if [ $ret -ne 0 ]; then
67 diff -u $testroot/stdout.expected
$testroot/stdout
68 test_done
"$testroot" "$ret"
72 echo "new file" > $testroot/wt
/epsilon
/zeta2
73 (cd $testroot/wt
&& got add epsilon
/zeta
* > $testroot/stdout
)
75 if [ $ret -ne 0 ]; then
76 echo "got add failed unexpectedly" >&2
77 test_done
"$testroot" 1
81 echo 'A epsilon/zeta2' > $testroot/stdout.expected
82 cmp -s $testroot/stdout.expected
$testroot/stdout
84 if [ $ret -ne 0 ]; then
85 diff -u $testroot/stdout.expected
$testroot/stdout
87 test_done
"$testroot" "$ret"
91 local testroot
=`test_init multiple_add`
93 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
95 if [ $ret -ne 0 ]; then
96 test_done
"$testroot" "$ret"
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
)
105 if [ $ret -ne 0 ]; then
106 echo "got add failed unexpectedly" >&2
107 test_done
"$testroot" 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
117 if [ $ret -ne 0 ]; then
118 diff -u $testroot/stdout.expected
$testroot/stdout
119 test_done
"$testroot" "$ret"
123 echo "changed file" > $testroot/wt
/alpha
124 echo "new file" > $testroot/wt
/bax
125 (cd $testroot/wt
&& got add
-R * > $testroot/stdout
)
127 if [ $ret -ne 0 ]; then
128 echo "got add failed unexpectedly" >&2
129 test_done
"$testroot" 1
133 echo "A bax" > $testroot/stdout.expected
135 cmp -s $testroot/stdout.expected
$testroot/stdout
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
149 if [ $ret -ne 0 ]; then
150 test_done
"$testroot" "$ret"
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
162 if [ $ret -ne 0 ]; then
163 diff -u $testroot/stdout.expected
$testroot/stdout
165 test_done
"$testroot" "$ret"
169 local testroot
=`test_init add_deleted`
171 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
173 if [ $ret -ne 0 ]; then
174 test_done
"$testroot" "$ret"
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
)
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"
190 echo "got: beta: file has unexpected status" > $testroot/stderr.expected
191 cmp -s $testroot/stderr.expected
$testroot/stderr
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
204 if [ $ret -ne 0 ]; then
205 test_done
"$testroot" "$ret"
209 echo new
> $testroot/wt
/new
211 echo -n > $testroot/stdout.expected
212 (cd $testroot/wt
&& got add new
> $testroot/stdout
2> $testroot/stderr
)
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"
221 (cd $testroot/wt
&& mv new new2
> $testroot/stdout
2> $testroot/stderr
)
223 if [ $ret -ne 0 ]; then
224 echo "rename the file failed unexpectedly" >&2
226 test_done
"$testroot" "1"
231 (cd $testroot/wt
&& got add new2
> $testroot/stdout
2> $testroot/stderr
)
233 if [ $ret -ne 0 ]; then
234 echo "got add command failed unexpectedly" >&2
235 test_done
"$testroot" "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 \
245 if [ $ret -ne 0 ]; then
246 echo "got remove -f command failed unexpectedly" >&2
247 test_done
"$testroot" "1"
251 (cd $testroot/wt
&& got status
> $testroot/stdout
)
253 echo 'A new2' > $testroot/stdout.expected
254 cmp -s $testroot/stdout.expected
$testroot/stdout
256 if [ $ret -ne 0 ]; then
257 diff -u $testroot/stdout.expected
$testroot/stdout
258 test_done
"$testroot" "$ret"
262 (cd $testroot/wt
&& got commit
-m "add force remove commit" \
263 > $testroot/stdout
2> $testroot/stderr
)
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
276 if [ $ret -ne 0 ]; then
277 test_done
"$testroot" "$ret"
281 (cd $testroot/wt
&& got add .
> $testroot/stdout
2> $testroot/stderr
)
283 echo "got: adding directories requires -R option" \
284 > $testroot/stderr.expected
285 cmp -s $testroot/stderr.expected
$testroot/stderr
287 if [ $ret -ne 0 ]; then
288 diff -u $testroot/stderr.expected
$testroot/stderr
289 test_done
"$testroot" "$ret"
293 (cd $testroot/wt
&& got add
-I .
> $testroot/stdout
2> $testroot/stderr
)
295 echo "got: adding directories requires -R option" \
296 > $testroot/stderr.expected
297 cmp -s $testroot/stderr.expected
$testroot/stderr
299 if [ $ret -ne 0 ]; then
300 diff -u $testroot/stderr.expected
$testroot/stderr
301 test_done
"$testroot" "$ret"
305 echo -n > $testroot/stdout.expected
306 cmp -s $testroot/stdout.expected
$testroot/stdout
308 if [ $ret -ne 0 ]; then
309 diff -u $testroot/stdout.expected
$testroot/stdout
310 test_done
"$testroot" "$ret"
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
/tree
1/foo
319 echo -n > $testroot/wt
/tree
2/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
331 if [ $ret -ne 0 ]; then
332 diff -u $testroot/stdout.expected
$testroot/stdout
333 test_done
"$testroot" "$ret"
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
343 if [ $ret -ne 0 ]; then
344 diff -u $testroot/stdout.expected
$testroot/stdout
345 test_done
"$testroot" "$ret"
349 (cd $testroot/wt
&& got add tree
2/foo
> $testroot/stdout
)
351 echo -n '' > $testroot/stdout.expected
353 cmp -s $testroot/stdout.expected
$testroot/stdout
355 if [ $ret -ne 0 ]; then
356 diff -u $testroot/stdout.expected
$testroot/stdout
357 test_done
"$testroot" "$ret"
361 (cd $testroot/wt
&& got add
-I tree
2/foo
> $testroot/stdout
)
363 echo 'A tree2/foo' > $testroot/stdout.expected
365 cmp -s $testroot/stdout.expected
$testroot/stdout
367 if [ $ret -ne 0 ]; then
368 diff -u $testroot/stdout.expected
$testroot/stdout
369 test_done
"$testroot" "$ret"
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 git
-C $testroot/repo
-c protocol.
file.allow
=always \
381 submodule
-q add ..
/repo2
382 git
-C $testroot/repo commit
-q -m 'adding submodule'
384 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
386 # Attempt 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
394 if [ $ret -ne 0 ]; then
395 diff -u $testroot/stdout.expected
$testroot/stdout
396 test_done
"$testroot" "$ret"
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
)
407 if [ $ret -eq 0 ]; then
408 echo "commit succeeded unexpectedly" >&2
409 test_done
"$testroot" "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
417 if [ $ret -ne 0 ]; then
418 diff -u $testroot/stderr.expected
$testroot/stderr
420 test_done
"$testroot" "$ret"
424 local testroot
=`test_init add_symlink`
426 got checkout
$testroot/repo
$testroot/wt
> /dev
/null
428 if [ $ret -ne 0 ]; then
429 test_done
"$testroot" "$ret"
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
)
442 if [ $ret -ne 0 ]; then
443 diff -u $testroot/stdout.expected
$testroot/stdout
444 test_done
"$testroot" "$ret"
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
452 if [ $ret -ne 0 ]; then
453 diff -u $testroot/stdout.expected
$testroot/stdout
454 test_done
"$testroot" "$ret"
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
462 if [ $ret -ne 0 ]; then
463 diff -u $testroot/stdout.expected
$testroot/stdout
464 test_done
"$testroot" "$ret"
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
472 if [ $ret -ne 0 ]; then
473 diff -u $testroot/stdout.expected
$testroot/stdout
474 test_done
"$testroot" "$ret"
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
482 if [ $ret -ne 0 ]; then
483 diff -u $testroot/stdout.expected
$testroot/stdout
485 test_done
"$testroot" "$ret"
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