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_directory() {
200 local testroot=`test_init add_directory`
202 got checkout $testroot/repo $testroot/wt > /dev/null
204 if [ $ret -ne 0 ]; then
205 test_done "$testroot" "$ret"
209 (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
211 echo "got: adding directories requires -R option" \
212 > $testroot/stderr.expected
213 cmp -s $testroot/stderr.expected $testroot/stderr
215 if [ $ret -ne 0 ]; then
216 diff -u $testroot/stderr.expected $testroot/stderr
217 test_done "$testroot" "$ret"
221 (cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
223 echo "got: adding directories requires -R option" \
224 > $testroot/stderr.expected
225 cmp -s $testroot/stderr.expected $testroot/stderr
227 if [ $ret -ne 0 ]; then
228 diff -u $testroot/stderr.expected $testroot/stderr
229 test_done "$testroot" "$ret"
233 echo -n > $testroot/stdout.expected
234 cmp -s $testroot/stdout.expected $testroot/stdout
236 if [ $ret -ne 0 ]; then
237 diff -u $testroot/stdout.expected $testroot/stdout
238 test_done "$testroot" "$ret"
242 mkdir -p $testroot/wt/tree1
243 mkdir -p $testroot/wt/tree2
244 echo "tree1/**" > $testroot/wt/.gitignore
245 echo "tree2/**" >> $testroot/wt/.gitignore
246 echo -n > $testroot/wt/tree1/foo
247 echo -n > $testroot/wt/tree2/foo
248 echo -n > $testroot/wt/epsilon/zeta1
249 echo -n > $testroot/wt/epsilon/zeta2
251 (cd $testroot/wt && got add -R . > $testroot/stdout)
253 echo 'A .gitignore' > $testroot/stdout.expected
254 echo 'A epsilon/zeta1' >> $testroot/stdout.expected
255 echo 'A epsilon/zeta2' >> $testroot/stdout.expected
257 cmp -s $testroot/stdout.expected $testroot/stdout
259 if [ $ret -ne 0 ]; then
260 diff -u $testroot/stdout.expected $testroot/stdout
261 test_done "$testroot" "$ret"
265 (cd $testroot/wt && got add -RI tree1 > $testroot/stdout)
267 echo 'A tree1/foo' > $testroot/stdout.expected
269 cmp -s $testroot/stdout.expected $testroot/stdout
271 if [ $ret -ne 0 ]; then
272 diff -u $testroot/stdout.expected $testroot/stdout
273 test_done "$testroot" "$ret"
277 (cd $testroot/wt && got add tree2/foo > $testroot/stdout)
279 echo -n '' > $testroot/stdout.expected
281 cmp -s $testroot/stdout.expected $testroot/stdout
283 if [ $ret -ne 0 ]; then
284 diff -u $testroot/stdout.expected $testroot/stdout
285 test_done "$testroot" "$ret"
289 (cd $testroot/wt && got add -I tree2/foo > $testroot/stdout)
291 echo 'A tree2/foo' > $testroot/stdout.expected
293 cmp -s $testroot/stdout.expected $testroot/stdout
295 if [ $ret -ne 0 ]; then
296 diff -u $testroot/stdout.expected $testroot/stdout
297 test_done "$testroot" "$ret"
300 test_done "$testroot" "$ret"
303 test_add_clashes_with_submodule() {
304 local testroot=`test_init add_clashes_with_submodule`
306 make_single_file_repo $testroot/repo2 foo
308 (cd $testroot/repo && git -c protocol.file.allow=always \
309 submodule -q add ../repo2)
310 (cd $testroot/repo && git commit -q -m 'adding submodule')
312 got checkout $testroot/repo $testroot/wt > /dev/null
314 # Atttempt to add a file clashes with a submodule
315 echo "This is a file called repo2" > $testroot/wt/repo2
316 (cd $testroot/wt && got add repo2 > /dev/null)
318 (cd $testroot/wt && got status > $testroot/stdout)
319 echo "A repo2" > $testroot/stdout.expected
320 cmp -s $testroot/stdout.expected $testroot/stdout
322 if [ $ret -ne 0 ]; then
323 diff -u $testroot/stdout.expected $testroot/stdout
324 test_done "$testroot" "$ret"
328 # Update for good measure; see the error below.
329 (cd $testroot/wt && got update > /dev/null)
331 # This currently fails with "work tree must be updated"...
332 (cd $testroot/wt && got commit -m 'add file repo2' \
333 > $testroot/stdout 2> $testroot/stderr)
335 if [ $ret -eq 0 ]; then
336 echo "commit succeeded unexpectedly" >&2
337 test_done "$testroot" "1"
341 echo -n "got: work tree must be updated " > $testroot/stderr.expected
342 echo "before these changes can be committed" >> $testroot/stderr.expected
343 cmp -s $testroot/stderr.expected $testroot/stderr
345 if [ $ret -ne 0 ]; then
346 diff -u $testroot/stderr.expected $testroot/stderr
348 test_done "$testroot" "$ret"
352 local testroot=`test_init add_symlink`
354 got checkout $testroot/repo $testroot/wt > /dev/null
356 if [ $ret -ne 0 ]; then
357 test_done "$testroot" "$ret"
361 (cd $testroot/wt && ln -s alpha alpha.link)
362 (cd $testroot/wt && ln -s epsilon epsilon.link)
363 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
364 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
365 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
367 echo "A alpha.link" > $testroot/stdout.expected
368 (cd $testroot/wt && got add alpha.link > $testroot/stdout)
370 if [ $ret -ne 0 ]; then
371 diff -u $testroot/stdout.expected $testroot/stdout
372 test_done "$testroot" "$ret"
376 echo "A epsilon.link" > $testroot/stdout.expected
377 (cd $testroot/wt && got add epsilon.link > $testroot/stdout)
378 cmp -s $testroot/stdout.expected $testroot/stdout
380 if [ $ret -ne 0 ]; then
381 diff -u $testroot/stdout.expected $testroot/stdout
382 test_done "$testroot" "$ret"
386 echo "A passwd.link" > $testroot/stdout.expected
387 (cd $testroot/wt && got add passwd.link > $testroot/stdout)
388 cmp -s $testroot/stdout.expected $testroot/stdout
390 if [ $ret -ne 0 ]; then
391 diff -u $testroot/stdout.expected $testroot/stdout
392 test_done "$testroot" "$ret"
396 echo "A epsilon/beta.link" > $testroot/stdout.expected
397 (cd $testroot/wt && got add epsilon/beta.link > $testroot/stdout)
398 cmp -s $testroot/stdout.expected $testroot/stdout
400 if [ $ret -ne 0 ]; then
401 diff -u $testroot/stdout.expected $testroot/stdout
402 test_done "$testroot" "$ret"
406 echo "A nonexistent.link" > $testroot/stdout.expected
407 (cd $testroot/wt && got add nonexistent.link > $testroot/stdout)
408 cmp -s $testroot/stdout.expected $testroot/stdout
410 if [ $ret -ne 0 ]; then
411 diff -u $testroot/stdout.expected $testroot/stdout
413 test_done "$testroot" "$ret"
417 run_test test_add_basic
418 run_test test_double_add
419 run_test test_add_multiple
420 run_test test_add_file_in_new_subdir
421 run_test test_add_deleted
422 run_test test_add_directory
423 run_test test_add_clashes_with_submodule
424 run_test test_add_symlink