Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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
27 fi
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
38 fi
39 test_done "$testroot" "$ret"
40 }
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
50 fi
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
61 fi
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 fi
69 test_done "$testroot" "$ret"
70 }
72 test_add_multiple() {
73 local testroot=`test_init multiple_add`
75 got checkout $testroot/repo $testroot/wt > /dev/null
76 ret=$?
77 if [ $ret -ne 0 ]; then
78 test_done "$testroot" "$ret"
79 return 1
80 fi
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)
86 ret=$?
87 if [ $ret -ne 0 ]; then
88 echo "got add failed unexpectedly" >&2
89 test_done "$testroot" 1
90 return 1
91 fi
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
98 ret=$?
99 if [ $ret -ne 0 ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 fi
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
109 ret=$?
110 if [ $ret -ne 0 ]; then
111 test_done "$testroot" "$ret"
112 return 1
113 fi
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
122 ret=$?
123 if [ $ret -ne 0 ]; then
124 diff -u $testroot/stdout.expected $testroot/stdout
125 fi
126 test_done "$testroot" "$ret"
129 test_add_deleted() {
130 local testroot=`test_init add_deleted`
132 got checkout $testroot/repo $testroot/wt > /dev/null
133 ret=$?
134 if [ $ret -ne 0 ]; then
135 test_done "$testroot" "$ret"
136 return 1
137 fi
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)
143 ret=$?
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"
148 return 1
149 fi
151 echo "got: beta: file has unexpected status" > $testroot/stderr.expected
152 cmp -s $testroot/stderr.expected $testroot/stderr
153 ret=$?
154 if [ $ret -ne 0 ]; then
155 diff -u $testroot/stderr.expected $testroot/stderr
156 fi
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
164 ret=$?
165 if [ $ret -ne 0 ]; then
166 test_done "$testroot" "$ret"
167 return 1
168 fi
170 (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
171 ret=$?
172 echo "got: adding directories requires -R option" \
173 > $testroot/stderr.expected
174 cmp -s $testroot/stderr.expected $testroot/stderr
175 ret=$?
176 if [ $ret -ne 0 ]; then
177 diff -u $testroot/stderr.expected $testroot/stderr
178 test_done "$testroot" "$ret"
179 return 1
180 fi
182 (cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
183 ret=$?
184 echo "got: adding directories requires -R option" \
185 > $testroot/stderr.expected
186 cmp -s $testroot/stderr.expected $testroot/stderr
187 ret=$?
188 if [ $ret -ne 0 ]; then
189 diff -u $testroot/stderr.expected $testroot/stderr
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 echo -n > $testroot/stdout.expected
195 cmp -s $testroot/stdout.expected $testroot/stdout
196 ret=$?
197 if [ $ret -ne 0 ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
200 return 1
201 fi
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
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 diff -u $testroot/stdout.expected $testroot/stdout
222 test_done "$testroot" "$ret"
223 return 1
224 fi
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
231 ret=$?
232 if [ $ret -ne 0 ]; then
233 diff -u $testroot/stdout.expected $testroot/stdout
234 test_done "$testroot" "$ret"
235 return 1
236 fi
238 (cd $testroot/wt && got add tree2/foo > $testroot/stdout)
240 echo -n '' > $testroot/stdout.expected
242 cmp -s $testroot/stdout.expected $testroot/stdout
243 ret=$?
244 if [ $ret -ne 0 ]; then
245 diff -u $testroot/stdout.expected $testroot/stdout
246 test_done "$testroot" "$ret"
247 return 1
248 fi
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
255 ret=$?
256 if [ $ret -ne 0 ]; then
257 diff -u $testroot/stdout.expected $testroot/stdout
258 test_done "$testroot" "$ret"
259 return 1
260 fi
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 submodule -q add ../repo2)
270 (cd $testroot/repo && git commit -q -m 'adding submodule')
272 got checkout $testroot/repo $testroot/wt > /dev/null
274 # Atttempt to add a file clashes with a submodule
275 echo "This is a file called repo2" > $testroot/wt/repo2
276 (cd $testroot/wt && got add repo2 > /dev/null)
278 (cd $testroot/wt && got status > $testroot/stdout)
279 echo "A repo2" > $testroot/stdout.expected
280 cmp -s $testroot/stdout.expected $testroot/stdout
281 ret=$?
282 if [ $ret -ne 0 ]; then
283 diff -u $testroot/stdout.expected $testroot/stdout
284 test_done "$testroot" "$ret"
285 return 1
286 fi
288 # Update for good measure; see the error below.
289 (cd $testroot/wt && got update > /dev/null)
291 # This currently fails with "work tree must be updated"...
292 (cd $testroot/wt && got commit -m 'add file repo2' \
293 > $testroot/stdout 2> $testroot/stderr)
294 ret=$?
295 if [ $ret -eq 0 ]; then
296 echo "commit succeeded unexpectedly" >&2
297 test_done "$testroot" "1"
298 return 1
299 fi
301 echo -n "got: work tree must be updated " > $testroot/stderr.expected
302 echo "before these changes can be committed" >> $testroot/stderr.expected
303 cmp -s $testroot/stderr.expected $testroot/stderr
304 ret=$?
305 if [ $ret -ne 0 ]; then
306 diff -u $testroot/stderr.expected $testroot/stderr
307 fi
308 test_done "$testroot" "$ret"
311 test_add_symlink() {
312 local testroot=`test_init add_symlink`
314 got checkout $testroot/repo $testroot/wt > /dev/null
315 ret=$?
316 if [ $ret -ne 0 ]; then
317 test_done "$testroot" "$ret"
318 return 1
319 fi
321 (cd $testroot/wt && ln -s alpha alpha.link)
322 (cd $testroot/wt && ln -s epsilon epsilon.link)
323 (cd $testroot/wt && ln -s /etc/passwd passwd.link)
324 (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
325 (cd $testroot/wt && ln -s nonexistent nonexistent.link)
327 echo "A alpha.link" > $testroot/stdout.expected
328 (cd $testroot/wt && got add alpha.link > $testroot/stdout)
329 ret=$?
330 if [ $ret -ne 0 ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 test_done "$testroot" "$ret"
333 return 1
334 fi
336 echo "A epsilon.link" > $testroot/stdout.expected
337 (cd $testroot/wt && got add epsilon.link > $testroot/stdout)
338 cmp -s $testroot/stdout.expected $testroot/stdout
339 ret=$?
340 if [ $ret -ne 0 ]; then
341 diff -u $testroot/stdout.expected $testroot/stdout
342 test_done "$testroot" "$ret"
343 return 1
344 fi
346 echo "A passwd.link" > $testroot/stdout.expected
347 (cd $testroot/wt && got add passwd.link > $testroot/stdout)
348 cmp -s $testroot/stdout.expected $testroot/stdout
349 ret=$?
350 if [ $ret -ne 0 ]; then
351 diff -u $testroot/stdout.expected $testroot/stdout
352 test_done "$testroot" "$ret"
353 return 1
354 fi
356 echo "A epsilon/beta.link" > $testroot/stdout.expected
357 (cd $testroot/wt && got add epsilon/beta.link > $testroot/stdout)
358 cmp -s $testroot/stdout.expected $testroot/stdout
359 ret=$?
360 if [ $ret -ne 0 ]; then
361 diff -u $testroot/stdout.expected $testroot/stdout
362 test_done "$testroot" "$ret"
363 return 1
364 fi
366 echo "A nonexistent.link" > $testroot/stdout.expected
367 (cd $testroot/wt && got add nonexistent.link > $testroot/stdout)
368 cmp -s $testroot/stdout.expected $testroot/stdout
369 ret=$?
370 if [ $ret -ne 0 ]; then
371 diff -u $testroot/stdout.expected $testroot/stdout
372 fi
373 test_done "$testroot" "$ret"
376 test_parseargs "$@"
377 run_test test_add_basic
378 run_test test_double_add
379 run_test test_add_multiple
380 run_test test_add_file_in_new_subdir
381 run_test test_add_deleted
382 run_test test_add_directory
383 run_test test_add_clashes_with_submodule
384 run_test test_add_symlink