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" != "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" != "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" != "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" != "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" != "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" != "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" != "0" ]; then
88 echo "got add failed unexpectedly" >&2
89 test_done "$testroot" 1
93 echo "A foo" > $testroot/stdout.expected
94 echo "A bar" >> $testroot/stdout.expected
95 echo "A baz" >> $testroot/stdout.expected
97 cmp -s $testroot/stdout.expected $testroot/stdout
99 if [ "$ret" != "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" != "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" != "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" != "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" == "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" != "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" != "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" != "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: disregarding ignores requires -R option" \
185 > $testroot/stderr.expected
186 cmp -s $testroot/stderr.expected $testroot/stderr
188 if [ "$ret" != "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" != "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" != "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" != "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 'A tree2/foo' > $testroot/stdout.expected
242 cmp -s $testroot/stdout.expected $testroot/stdout
244 if [ "$ret" != "0" ]; then
245 diff -u $testroot/stdout.expected $testroot/stdout
246 test_done "$testroot" "$ret"
249 test_done "$testroot" "$ret"
252 test_add_clashes_with_submodule() {
253 local testroot=`test_init add_clashes_with_submodule`
255 make_single_file_repo $testroot/repo2 foo
257 (cd $testroot/repo && git submodule -q add ../repo2)
258 (cd $testroot/repo && git commit -q -m 'adding submodule')
260 got checkout $testroot/repo $testroot/wt > /dev/null
262 # Atttempt to add a file clashes with a submodule
263 echo "This is a file called repo2" > $testroot/wt/repo2
264 (cd $testroot/wt && got add repo2 > /dev/null)
266 (cd $testroot/wt && got status > $testroot/stdout)
267 echo "A repo2" > $testroot/stdout.expected
268 cmp -s $testroot/stdout.expected $testroot/stdout
270 if [ "$ret" != "0" ]; then
271 diff -u $testroot/stdout.expected $testroot/stdout
272 test_done "$testroot" "$ret"
276 # Update for good measure; see the error below.
277 (cd $testroot/wt && got update > /dev/null)
279 # This currently fails with "work tree must be updated"...
280 (cd $testroot/wt && got commit -m 'add file repo2' \
281 > $testroot/stdout 2> $testroot/stderr)
283 if [ "$ret" == "0" ]; then
284 echo "commit succeeded unexpectedly" >&2
285 test_done "$testroot" "1"
289 echo -n "got: work tree must be updated " > $testroot/stderr.expected
290 echo "before these changes can be committed" >> $testroot/stderr.expected
291 cmp -s $testroot/stderr.expected $testroot/stderr
293 if [ "$ret" != "0" ]; then
294 diff -u $testroot/stderr.expected $testroot/stderr
296 test_done "$testroot" "$ret"
300 local testroot=`test_init add_symlink`
302 got checkout $testroot/repo $testroot/wt > /dev/null
304 if [ "$ret" != "0" ]; then
305 test_done "$testroot" "$ret"
309 (cd $testroot/wt && ln -s alpha alpha.link)
310 (cd $testroot/wt && ln -s epsilon epsilon.link)
311 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
312 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
313 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
315 echo "A alpha.link" > $testroot/stdout.expected
316 (cd $testroot/wt && got add alpha.link > $testroot/stdout)
318 if [ "$ret" != "0" ]; then
319 diff -u $testroot/stdout.expected $testroot/stdout
320 test_done "$testroot" "$ret"
324 echo "A epsilon.link" > $testroot/stdout.expected
325 (cd $testroot/wt && got add epsilon.link > $testroot/stdout)
326 cmp -s $testroot/stdout.expected $testroot/stdout
328 if [ "$ret" != "0" ]; then
329 diff -u $testroot/stdout.expected $testroot/stdout
330 test_done "$testroot" "$ret"
334 echo "A passwd.link" > $testroot/stdout.expected
335 (cd $testroot/wt && got add passwd.link > $testroot/stdout)
336 cmp -s $testroot/stdout.expected $testroot/stdout
338 if [ "$ret" != "0" ]; then
339 diff -u $testroot/stdout.expected $testroot/stdout
340 test_done "$testroot" "$ret"
344 echo "A epsilon/beta.link" > $testroot/stdout.expected
345 (cd $testroot/wt && got add epsilon/beta.link > $testroot/stdout)
346 cmp -s $testroot/stdout.expected $testroot/stdout
348 if [ "$ret" != "0" ]; then
349 diff -u $testroot/stdout.expected $testroot/stdout
350 test_done "$testroot" "$ret"
354 echo "A nonexistent.link" > $testroot/stdout.expected
355 (cd $testroot/wt && got add nonexistent.link > $testroot/stdout)
356 cmp -s $testroot/stdout.expected $testroot/stdout
358 if [ "$ret" != "0" ]; then
359 diff -u $testroot/stdout.expected $testroot/stdout
361 test_done "$testroot" "$ret"
365 run_test test_add_basic
366 run_test test_double_add
367 run_test test_add_multiple
368 run_test test_add_file_in_new_subdir
369 run_test test_add_deleted
370 run_test test_add_directory
371 run_test test_add_clashes_with_submodule
372 run_test test_add_symlink