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
69 test_done "$testroot" "$ret"
73 local testroot=`test_init multiple_add`
75 got checkout $testroot/repo $testroot/wt > /dev/null
77 if [ $ret -ne 0 ]; then
78 test_done "$testroot" "$ret"
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)
87 if [ $ret -ne 0 ]; then
88 echo "got add failed unexpectedly" >&2
89 test_done "$testroot" 1
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
99 if [ $ret -ne 0 ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
102 test_done "$testroot" "$ret"
105 test_add_file_in_new_subdir() {
106 local testroot=`test_init add_file_in_new_subdir`
108 got checkout $testroot/repo $testroot/wt > /dev/null
110 if [ $ret -ne 0 ]; then
111 test_done "$testroot" "$ret"
115 mkdir -p $testroot/wt/new
116 echo "new file" > $testroot/wt/new/foo
118 echo 'A new/foo' > $testroot/stdout.expected
119 (cd $testroot/wt && got add new/foo > $testroot/stdout)
121 cmp -s $testroot/stdout.expected $testroot/stdout
123 if [ $ret -ne 0 ]; then
124 diff -u $testroot/stdout.expected $testroot/stdout
126 test_done "$testroot" "$ret"
130 local testroot=`test_init add_deleted`
132 got checkout $testroot/repo $testroot/wt > /dev/null
134 if [ $ret -ne 0 ]; then
135 test_done "$testroot" "$ret"
139 (cd $testroot/wt && got rm beta > /dev/null)
141 echo -n > $testroot/stdout.expected
142 (cd $testroot/wt && got add beta > $testroot/stdout 2> $testroot/stderr)
144 if [ $ret -eq 0 ]; then
145 echo "got add command succeeded unexpectedly" >&2
146 diff -u $testroot/stdout.expected $testroot/stdout
147 test_done "$testroot" "1"
151 echo "got: beta: file has unexpected status" > $testroot/stderr.expected
152 cmp -s $testroot/stderr.expected $testroot/stderr
154 if [ $ret -ne 0 ]; then
155 diff -u $testroot/stderr.expected $testroot/stderr
157 test_done "$testroot" "$ret"
160 test_add_directory() {
161 local testroot=`test_init add_directory`
163 got checkout $testroot/repo $testroot/wt > /dev/null
165 if [ $ret -ne 0 ]; then
166 test_done "$testroot" "$ret"
170 (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
172 echo "got: adding directories requires -R option" \
173 > $testroot/stderr.expected
174 cmp -s $testroot/stderr.expected $testroot/stderr
176 if [ $ret -ne 0 ]; then
177 diff -u $testroot/stderr.expected $testroot/stderr
178 test_done "$testroot" "$ret"
182 (cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
184 echo "got: adding directories requires -R option" \
185 > $testroot/stderr.expected
186 cmp -s $testroot/stderr.expected $testroot/stderr
188 if [ $ret -ne 0 ]; then
189 diff -u $testroot/stderr.expected $testroot/stderr
190 test_done "$testroot" "$ret"
194 echo -n > $testroot/stdout.expected
195 cmp -s $testroot/stdout.expected $testroot/stdout
197 if [ $ret -ne 0 ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
203 mkdir -p $testroot/wt/tree1
204 mkdir -p $testroot/wt/tree2
205 echo "tree1/**" > $testroot/wt/.gitignore
206 echo "tree2/**" >> $testroot/wt/.gitignore
207 echo -n > $testroot/wt/tree1/foo
208 echo -n > $testroot/wt/tree2/foo
209 echo -n > $testroot/wt/epsilon/zeta1
210 echo -n > $testroot/wt/epsilon/zeta2
212 (cd $testroot/wt && got add -R . > $testroot/stdout)
214 echo 'A .gitignore' > $testroot/stdout.expected
215 echo 'A epsilon/zeta1' >> $testroot/stdout.expected
216 echo 'A epsilon/zeta2' >> $testroot/stdout.expected
218 cmp -s $testroot/stdout.expected $testroot/stdout
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/stdout.expected $testroot/stdout
222 test_done "$testroot" "$ret"
226 (cd $testroot/wt && got add -RI tree1 > $testroot/stdout)
228 echo 'A tree1/foo' > $testroot/stdout.expected
230 cmp -s $testroot/stdout.expected $testroot/stdout
232 if [ $ret -ne 0 ]; then
233 diff -u $testroot/stdout.expected $testroot/stdout
234 test_done "$testroot" "$ret"
238 (cd $testroot/wt && got add tree2/foo > $testroot/stdout)
240 echo -n '' > $testroot/stdout.expected
242 cmp -s $testroot/stdout.expected $testroot/stdout
244 if [ $ret -ne 0 ]; then
245 diff -u $testroot/stdout.expected $testroot/stdout
246 test_done "$testroot" "$ret"
250 (cd $testroot/wt && got add -I tree2/foo > $testroot/stdout)
252 echo 'A tree2/foo' > $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"
261 test_done "$testroot" "$ret"
264 test_add_clashes_with_submodule() {
265 local testroot=`test_init add_clashes_with_submodule`
267 make_single_file_repo $testroot/repo2 foo
269 (cd $testroot/repo && git -c protocol.file.allow=always \
270 submodule -q add ../repo2)
271 (cd $testroot/repo && git commit -q -m 'adding submodule')
273 got checkout $testroot/repo $testroot/wt > /dev/null
275 # Atttempt to add a file clashes with a submodule
276 echo "This is a file called repo2" > $testroot/wt/repo2
277 (cd $testroot/wt && got add repo2 > /dev/null)
279 (cd $testroot/wt && got status > $testroot/stdout)
280 echo "A repo2" > $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 # Update for good measure; see the error below.
290 (cd $testroot/wt && got update > /dev/null)
292 # This currently fails with "work tree must be updated"...
293 (cd $testroot/wt && got commit -m 'add file repo2' \
294 > $testroot/stdout 2> $testroot/stderr)
296 if [ $ret -eq 0 ]; then
297 echo "commit succeeded unexpectedly" >&2
298 test_done "$testroot" "1"
302 echo -n "got: work tree must be updated " > $testroot/stderr.expected
303 echo "before these changes can be committed" >> $testroot/stderr.expected
304 cmp -s $testroot/stderr.expected $testroot/stderr
306 if [ $ret -ne 0 ]; then
307 diff -u $testroot/stderr.expected $testroot/stderr
309 test_done "$testroot" "$ret"
313 local testroot=`test_init add_symlink`
315 got checkout $testroot/repo $testroot/wt > /dev/null
317 if [ $ret -ne 0 ]; then
318 test_done "$testroot" "$ret"
322 (cd $testroot/wt && ln -s alpha alpha.link)
323 (cd $testroot/wt && ln -s epsilon epsilon.link)
324 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
325 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
326 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
328 echo "A alpha.link" > $testroot/stdout.expected
329 (cd $testroot/wt && got add alpha.link > $testroot/stdout)
331 if [ $ret -ne 0 ]; then
332 diff -u $testroot/stdout.expected $testroot/stdout
333 test_done "$testroot" "$ret"
337 echo "A epsilon.link" > $testroot/stdout.expected
338 (cd $testroot/wt && got add epsilon.link > $testroot/stdout)
339 cmp -s $testroot/stdout.expected $testroot/stdout
341 if [ $ret -ne 0 ]; then
342 diff -u $testroot/stdout.expected $testroot/stdout
343 test_done "$testroot" "$ret"
347 echo "A passwd.link" > $testroot/stdout.expected
348 (cd $testroot/wt && got add passwd.link > $testroot/stdout)
349 cmp -s $testroot/stdout.expected $testroot/stdout
351 if [ $ret -ne 0 ]; then
352 diff -u $testroot/stdout.expected $testroot/stdout
353 test_done "$testroot" "$ret"
357 echo "A epsilon/beta.link" > $testroot/stdout.expected
358 (cd $testroot/wt && got add epsilon/beta.link > $testroot/stdout)
359 cmp -s $testroot/stdout.expected $testroot/stdout
361 if [ $ret -ne 0 ]; then
362 diff -u $testroot/stdout.expected $testroot/stdout
363 test_done "$testroot" "$ret"
367 echo "A nonexistent.link" > $testroot/stdout.expected
368 (cd $testroot/wt && got add nonexistent.link > $testroot/stdout)
369 cmp -s $testroot/stdout.expected $testroot/stdout
371 if [ $ret -ne 0 ]; then
372 diff -u $testroot/stdout.expected $testroot/stdout
374 test_done "$testroot" "$ret"
378 run_test test_add_basic
379 run_test test_double_add
380 run_test test_add_multiple
381 run_test test_add_file_in_new_subdir
382 run_test test_add_deleted
383 run_test test_add_directory
384 run_test test_add_clashes_with_submodule
385 run_test test_add_symlink