3 6dbf1e9e 2019-03-26 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 6dbf1e9e 2019-03-26 stsp # Permission to use, copy, modify, and distribute this software for any
6 6dbf1e9e 2019-03-26 stsp # purpose with or without fee is hereby granted, provided that the above
7 6dbf1e9e 2019-03-26 stsp # copyright notice and this permission notice appear in all copies.
9 6dbf1e9e 2019-03-26 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 6dbf1e9e 2019-03-26 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 6dbf1e9e 2019-03-26 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 6dbf1e9e 2019-03-26 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 6dbf1e9e 2019-03-26 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 6dbf1e9e 2019-03-26 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 6dbf1e9e 2019-03-26 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 6dbf1e9e 2019-03-26 stsp . ./common.sh
19 f6cae3ed 2020-09-13 naddy test_add_basic() {
20 6dbf1e9e 2019-03-26 stsp local testroot=`test_init add_basic`
22 6dbf1e9e 2019-03-26 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
25 6dbf1e9e 2019-03-26 stsp test_done "$testroot" "$ret"
29 6dbf1e9e 2019-03-26 stsp echo "new file" > $testroot/wt/foo
31 6dbf1e9e 2019-03-26 stsp echo 'A foo' > $testroot/stdout.expected
32 6dbf1e9e 2019-03-26 stsp (cd $testroot/wt && got add foo > $testroot/stdout)
34 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
36 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
37 6dbf1e9e 2019-03-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
39 6dbf1e9e 2019-03-26 stsp test_done "$testroot" "$ret"
42 f6cae3ed 2020-09-13 naddy test_double_add() {
43 5c99ca9f 2019-03-27 stsp local testroot=`test_init double_add`
45 5c99ca9f 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
47 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
48 5c99ca9f 2019-03-27 stsp test_done "$testroot" "$ret"
52 5c99ca9f 2019-03-27 stsp echo "new file" > $testroot/wt/foo
53 5c99ca9f 2019-03-27 stsp (cd $testroot/wt && got add foo > /dev/null)
55 dbb83fbd 2019-12-12 stsp (cd $testroot/wt && got add foo > $testroot/stdout)
57 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
58 723c305c 2019-05-11 jcs echo "got add failed unexpectedly" >&2
59 5c99ca9f 2019-03-27 stsp test_done "$testroot" 1
63 dbb83fbd 2019-12-12 stsp echo -n > $testroot/stdout.expected
64 dbb83fbd 2019-12-12 stsp cmp -s $testroot/stdout.expected $testroot/stdout
66 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
67 dbb83fbd 2019-12-12 stsp diff -u $testroot/stdout.expected $testroot/stdout
69 723c305c 2019-05-11 jcs test_done "$testroot" "$ret"
72 f6cae3ed 2020-09-13 naddy test_add_multiple() {
73 723c305c 2019-05-11 jcs local testroot=`test_init multiple_add`
75 723c305c 2019-05-11 jcs got checkout $testroot/repo $testroot/wt > /dev/null
77 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
78 723c305c 2019-05-11 jcs test_done "$testroot" "$ret"
82 723c305c 2019-05-11 jcs echo "new file" > $testroot/wt/foo
83 723c305c 2019-05-11 jcs echo "new file" > $testroot/wt/bar
84 723c305c 2019-05-11 jcs echo "new file" > $testroot/wt/baz
85 2b01eb6c 2019-05-11 stsp (cd $testroot/wt && got add foo bar baz > $testroot/stdout)
87 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
88 723c305c 2019-05-11 jcs echo "got add failed unexpectedly" >&2
89 723c305c 2019-05-11 jcs test_done "$testroot" 1
93 10a623df 2021-10-11 stsp echo "A bar" > $testroot/stdout.expected
94 2b01eb6c 2019-05-11 stsp echo "A baz" >> $testroot/stdout.expected
95 10a623df 2021-10-11 stsp echo "A foo" >> $testroot/stdout.expected
97 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
99 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
100 2b01eb6c 2019-05-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
102 5c99ca9f 2019-03-27 stsp test_done "$testroot" "$ret"
105 f6cae3ed 2020-09-13 naddy test_add_file_in_new_subdir() {
106 a9fa2909 2019-07-27 stsp local testroot=`test_init add_file_in_new_subdir`
108 a9fa2909 2019-07-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
110 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
111 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
115 a9fa2909 2019-07-27 stsp mkdir -p $testroot/wt/new
116 a9fa2909 2019-07-27 stsp echo "new file" > $testroot/wt/new/foo
118 a9fa2909 2019-07-27 stsp echo 'A new/foo' > $testroot/stdout.expected
119 a9fa2909 2019-07-27 stsp (cd $testroot/wt && got add new/foo > $testroot/stdout)
121 a9fa2909 2019-07-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
123 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
124 a9fa2909 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
126 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
129 f6cae3ed 2020-09-13 naddy test_add_deleted() {
130 6d022e97 2019-08-04 stsp local testroot=`test_init add_deleted`
132 6d022e97 2019-08-04 stsp got checkout $testroot/repo $testroot/wt > /dev/null
134 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
135 6d022e97 2019-08-04 stsp test_done "$testroot" "$ret"
139 6d022e97 2019-08-04 stsp (cd $testroot/wt && got rm beta > /dev/null)
141 6d022e97 2019-08-04 stsp echo -n > $testroot/stdout.expected
142 6d022e97 2019-08-04 stsp (cd $testroot/wt && got add beta > $testroot/stdout 2> $testroot/stderr)
144 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
145 6d022e97 2019-08-04 stsp echo "got add command succeeded unexpectedly" >&2
146 6d022e97 2019-08-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
147 6d022e97 2019-08-04 stsp test_done "$testroot" "1"
151 6d022e97 2019-08-04 stsp echo "got: beta: file has unexpected status" > $testroot/stderr.expected
152 6d022e97 2019-08-04 stsp cmp -s $testroot/stderr.expected $testroot/stderr
154 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
155 6d022e97 2019-08-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
157 6d022e97 2019-08-04 stsp test_done "$testroot" "$ret"
160 f6cae3ed 2020-09-13 naddy test_add_directory() {
161 4e68cba3 2019-11-23 stsp local testroot=`test_init add_directory`
163 4e68cba3 2019-11-23 stsp got checkout $testroot/repo $testroot/wt > /dev/null
165 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
166 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
170 4e68cba3 2019-11-23 stsp (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
172 4e68cba3 2019-11-23 stsp echo "got: adding directories requires -R option" \
173 4e68cba3 2019-11-23 stsp > $testroot/stderr.expected
174 4e68cba3 2019-11-23 stsp cmp -s $testroot/stderr.expected $testroot/stderr
176 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
177 4e68cba3 2019-11-23 stsp diff -u $testroot/stderr.expected $testroot/stderr
178 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
182 022fae89 2019-12-06 tracey (cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
184 ff56836b 2021-07-08 stsp echo "got: adding directories requires -R option" \
185 022fae89 2019-12-06 tracey > $testroot/stderr.expected
186 022fae89 2019-12-06 tracey cmp -s $testroot/stderr.expected $testroot/stderr
188 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
189 022fae89 2019-12-06 tracey diff -u $testroot/stderr.expected $testroot/stderr
190 022fae89 2019-12-06 tracey test_done "$testroot" "$ret"
194 4e68cba3 2019-11-23 stsp echo -n > $testroot/stdout.expected
195 4e68cba3 2019-11-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
197 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
198 4e68cba3 2019-11-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
199 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
203 022fae89 2019-12-06 tracey mkdir -p $testroot/wt/tree1
204 022fae89 2019-12-06 tracey mkdir -p $testroot/wt/tree2
205 022fae89 2019-12-06 tracey echo "tree1/**" > $testroot/wt/.gitignore
206 022fae89 2019-12-06 tracey echo "tree2/**" >> $testroot/wt/.gitignore
207 022fae89 2019-12-06 tracey echo -n > $testroot/wt/tree1/foo
208 022fae89 2019-12-06 tracey echo -n > $testroot/wt/tree2/foo
209 022fae89 2019-12-06 tracey echo -n > $testroot/wt/epsilon/zeta1
210 022fae89 2019-12-06 tracey echo -n > $testroot/wt/epsilon/zeta2
212 4e68cba3 2019-11-23 stsp (cd $testroot/wt && got add -R . > $testroot/stdout)
214 022fae89 2019-12-06 tracey echo 'A .gitignore' > $testroot/stdout.expected
215 022fae89 2019-12-06 tracey echo 'A epsilon/zeta1' >> $testroot/stdout.expected
216 4e68cba3 2019-11-23 stsp echo 'A epsilon/zeta2' >> $testroot/stdout.expected
218 4e68cba3 2019-11-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
220 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
221 4e68cba3 2019-11-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
222 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
226 022fae89 2019-12-06 tracey (cd $testroot/wt && got add -RI tree1 > $testroot/stdout)
228 022fae89 2019-12-06 tracey echo 'A tree1/foo' > $testroot/stdout.expected
230 022fae89 2019-12-06 tracey cmp -s $testroot/stdout.expected $testroot/stdout
232 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
233 022fae89 2019-12-06 tracey diff -u $testroot/stdout.expected $testroot/stdout
234 022fae89 2019-12-06 tracey test_done "$testroot" "$ret"
238 022fae89 2019-12-06 tracey (cd $testroot/wt && got add tree2/foo > $testroot/stdout)
240 ff56836b 2021-07-08 stsp echo -n '' > $testroot/stdout.expected
242 ff56836b 2021-07-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
244 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
245 ff56836b 2021-07-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
246 ff56836b 2021-07-08 stsp test_done "$testroot" "$ret"
250 ff56836b 2021-07-08 stsp (cd $testroot/wt && got add -I tree2/foo > $testroot/stdout)
252 022fae89 2019-12-06 tracey echo 'A tree2/foo' > $testroot/stdout.expected
254 022fae89 2019-12-06 tracey cmp -s $testroot/stdout.expected $testroot/stdout
256 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
257 022fae89 2019-12-06 tracey diff -u $testroot/stdout.expected $testroot/stdout
258 022fae89 2019-12-06 tracey test_done "$testroot" "$ret"
261 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
264 f6cae3ed 2020-09-13 naddy test_add_clashes_with_submodule() {
265 e7303626 2020-05-14 stsp local testroot=`test_init add_clashes_with_submodule`
267 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
269 f1aec6ed 2022-10-24 stsp (cd $testroot/repo && git -c protocol.file.allow=always \
270 f1aec6ed 2022-10-24 stsp submodule -q add ../repo2)
271 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
273 e7303626 2020-05-14 stsp got checkout $testroot/repo $testroot/wt > /dev/null
275 e7303626 2020-05-14 stsp # Atttempt to add a file clashes with a submodule
276 e7303626 2020-05-14 stsp echo "This is a file called repo2" > $testroot/wt/repo2
277 e7303626 2020-05-14 stsp (cd $testroot/wt && got add repo2 > /dev/null)
279 e7303626 2020-05-14 stsp (cd $testroot/wt && got status > $testroot/stdout)
280 e7303626 2020-05-14 stsp echo "A repo2" > $testroot/stdout.expected
281 e7303626 2020-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
283 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
284 e7303626 2020-05-14 stsp diff -u $testroot/stdout.expected $testroot/stdout
285 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
289 e7303626 2020-05-14 stsp # Update for good measure; see the error below.
290 e7303626 2020-05-14 stsp (cd $testroot/wt && got update > /dev/null)
292 e7303626 2020-05-14 stsp # This currently fails with "work tree must be updated"...
293 e7303626 2020-05-14 stsp (cd $testroot/wt && got commit -m 'add file repo2' \
294 e7303626 2020-05-14 stsp > $testroot/stdout 2> $testroot/stderr)
296 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
297 e7303626 2020-05-14 stsp echo "commit succeeded unexpectedly" >&2
298 e7303626 2020-05-14 stsp test_done "$testroot" "1"
302 e7303626 2020-05-14 stsp echo -n "got: work tree must be updated " > $testroot/stderr.expected
303 e7303626 2020-05-14 stsp echo "before these changes can be committed" >> $testroot/stderr.expected
304 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
306 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
307 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
309 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
312 f6cae3ed 2020-09-13 naddy test_add_symlink() {
313 00bb5ea0 2020-07-23 stsp local testroot=`test_init add_symlink`
315 00bb5ea0 2020-07-23 stsp got checkout $testroot/repo $testroot/wt > /dev/null
317 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
318 00bb5ea0 2020-07-23 stsp test_done "$testroot" "$ret"
322 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && ln -s alpha alpha.link)
323 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && ln -s epsilon epsilon.link)
324 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && ln -s /etc/passwd passwd.link)
325 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && ln -s ../beta epsilon/beta.link)
326 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && ln -s nonexistent nonexistent.link)
328 00bb5ea0 2020-07-23 stsp echo "A alpha.link" > $testroot/stdout.expected
329 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && got add alpha.link > $testroot/stdout)
331 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
332 00bb5ea0 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
333 00bb5ea0 2020-07-23 stsp test_done "$testroot" "$ret"
337 00bb5ea0 2020-07-23 stsp echo "A epsilon.link" > $testroot/stdout.expected
338 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && got add epsilon.link > $testroot/stdout)
339 00bb5ea0 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
341 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
342 00bb5ea0 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
343 00bb5ea0 2020-07-23 stsp test_done "$testroot" "$ret"
347 00bb5ea0 2020-07-23 stsp echo "A passwd.link" > $testroot/stdout.expected
348 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && got add passwd.link > $testroot/stdout)
349 00bb5ea0 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
351 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
352 00bb5ea0 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
353 00bb5ea0 2020-07-23 stsp test_done "$testroot" "$ret"
357 00bb5ea0 2020-07-23 stsp echo "A epsilon/beta.link" > $testroot/stdout.expected
358 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && got add epsilon/beta.link > $testroot/stdout)
359 00bb5ea0 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
361 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
362 00bb5ea0 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
363 00bb5ea0 2020-07-23 stsp test_done "$testroot" "$ret"
367 00bb5ea0 2020-07-23 stsp echo "A nonexistent.link" > $testroot/stdout.expected
368 00bb5ea0 2020-07-23 stsp (cd $testroot/wt && got add nonexistent.link > $testroot/stdout)
369 00bb5ea0 2020-07-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
371 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
372 00bb5ea0 2020-07-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
374 00bb5ea0 2020-07-23 stsp test_done "$testroot" "$ret"
377 7fb414ae 2020-08-08 stsp test_parseargs "$@"
378 6dbf1e9e 2019-03-26 stsp run_test test_add_basic
379 5c99ca9f 2019-03-27 stsp run_test test_double_add
380 2b01eb6c 2019-05-11 stsp run_test test_add_multiple
381 a9fa2909 2019-07-27 stsp run_test test_add_file_in_new_subdir
382 6d022e97 2019-08-04 stsp run_test test_add_deleted
383 4e68cba3 2019-11-23 stsp run_test test_add_directory
384 e7303626 2020-05-14 stsp run_test test_add_clashes_with_submodule
385 00bb5ea0 2020-07-23 stsp run_test test_add_symlink