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 -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
282 ret=$?
283 if [ $ret -ne 0 ]; then
284 diff -u $testroot/stdout.expected $testroot/stdout
285 test_done "$testroot" "$ret"
286 return 1
287 fi
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)
295 ret=$?
296 if [ $ret -eq 0 ]; then
297 echo "commit succeeded unexpectedly" >&2
298 test_done "$testroot" "1"
299 return 1
300 fi
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
305 ret=$?
306 if [ $ret -ne 0 ]; then
307 diff -u $testroot/stderr.expected $testroot/stderr
308 fi
309 test_done "$testroot" "$ret"
312 test_add_symlink() {
313 local testroot=`test_init add_symlink`
315 got checkout $testroot/repo $testroot/wt > /dev/null
316 ret=$?
317 if [ $ret -ne 0 ]; then
318 test_done "$testroot" "$ret"
319 return 1
320 fi
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)
330 ret=$?
331 if [ $ret -ne 0 ]; then
332 diff -u $testroot/stdout.expected $testroot/stdout
333 test_done "$testroot" "$ret"
334 return 1
335 fi
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
340 ret=$?
341 if [ $ret -ne 0 ]; then
342 diff -u $testroot/stdout.expected $testroot/stdout
343 test_done "$testroot" "$ret"
344 return 1
345 fi
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
350 ret=$?
351 if [ $ret -ne 0 ]; then
352 diff -u $testroot/stdout.expected $testroot/stdout
353 test_done "$testroot" "$ret"
354 return 1
355 fi
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
360 ret=$?
361 if [ $ret -ne 0 ]; then
362 diff -u $testroot/stdout.expected $testroot/stdout
363 test_done "$testroot" "$ret"
364 return 1
365 fi
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
370 ret=$?
371 if [ $ret -ne 0 ]; then
372 diff -u $testroot/stdout.expected $testroot/stdout
373 fi
374 test_done "$testroot" "$ret"
377 test_parseargs "$@"
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