3 # Copyright (c) 2024 Omar Polo <op@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.
17 . ../cmdline/common.sh
20 # flan:password encoded in base64
21 AUTH="ZmxhbjpwYXNzd29yZA=="
24 local testroot=`test_init file_changed 1`
26 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
28 if [ $ret -ne 0 ]; then
29 echo "got clone failed unexpectedly" >&2
30 test_done "$testroot" 1
34 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
36 if [ $ret -ne 0 ]; then
37 echo "got checkout failed unexpectedly" >&2
38 test_done "$testroot" 1
42 echo "change alpha" > $testroot/wt/alpha
43 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
44 local commit_id=`git_show_head $testroot/repo-clone`
45 local author_time=`git_show_author_time $testroot/repo-clone`
47 timeout 5 ./http-server -a $AUTH -p $GOTD_TEST_HTTP_PORT \
50 got send -b main -q -r $testroot/repo-clone
52 if [ $ret -ne 0 ]; then
53 echo "got send failed unexpectedly" >&2
54 test_done "$testroot" "1"
58 wait %1 # wait for the http "server"
60 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
62 touch "$testroot/stdout.expected"
63 ed -s "$testroot/stdout.expected" <<-EOF
72 "name":"$GIT_AUTHOR_NAME",
73 "mail":"$GIT_AUTHOR_EMAIL",
74 "user":"$GOT_AUTHOR_11"
78 "name":"$GIT_AUTHOR_NAME",
79 "mail":"$GIT_AUTHOR_EMAIL",
80 "user":"$GOT_AUTHOR_11"
83 "short_message":"make changes",
84 "message":"make changes\n",
103 cmp -s $testroot/stdout.expected $testroot/stdout
105 if [ $ret -ne 0 ]; then
106 diff -u $testroot/stdout.expected $testroot/stdout
107 test_done "$testroot" "$ret"
111 test_done "$testroot" "$ret"
115 local testroot=`test_init bad_utf8 1`
117 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
119 if [ $ret -ne 0 ]; then
120 echo "got clone failed unexpectedly" >&2
121 test_done "$testroot" 1
125 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
127 if [ $ret -ne 0 ]; then
128 echo "got checkout failed unexpectedly" >&2
129 test_done "$testroot" 1
132 # invalid utf8 sequence
133 commit_msg="make$(printf '\xED\xA0\x80')changes"
135 echo "changed" > $testroot/wt/alpha
136 (cd $testroot/wt && got commit -m "$commit_msg" > /dev/null)
137 local commit_id=`git_show_head $testroot/repo-clone`
138 local author_time=`git_show_author_time $testroot/repo-clone`
140 timeout 5 ./http-server -a $AUTH -p $GOTD_TEST_HTTP_PORT \
143 got send -b main -q -r $testroot/repo-clone
145 if [ $ret -ne 0 ]; then
146 echo "got send failed unexpectedly" >&2
147 test_done "$testroot" "1"
151 wait %1 # wait for the http "server"
153 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
155 touch "$testroot/stdout.expected"
156 ed -s "$testroot/stdout.expected" <<-EOF
164 "full":"$GOT_AUTHOR",
165 "name":"$GIT_AUTHOR_NAME",
166 "mail":"$GIT_AUTHOR_EMAIL",
167 "user":"$GOT_AUTHOR_11"
170 "full":"$GOT_AUTHOR",
171 "name":"$GIT_AUTHOR_NAME",
172 "mail":"$GIT_AUTHOR_EMAIL",
173 "user":"$GOT_AUTHOR_11"
176 "short_message":"make\uFFFD\uFFFDchanges",
177 "message":"make\uFFFD\uFFFDchanges\n",
196 cmp -s $testroot/stdout.expected $testroot/stdout
198 if [ $ret -ne 0 ]; then
199 diff -u $testroot/stdout.expected $testroot/stdout
200 test_done "$testroot" "$ret"
204 test_done "$testroot" "$ret"
207 test_many_commits_not_summarized() {
208 local testroot=`test_init many_commits_not_summarized 1`
210 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
212 if [ $ret -ne 0 ]; then
213 echo "got clone failed unexpectedly" >&2
214 test_done "$testroot" 1
218 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
220 if [ $ret -ne 0 ]; then
221 echo "got checkout failed unexpectedly" >&2
222 test_done "$testroot" 1
226 for i in `seq 1 24`; do
227 echo "alpha $i" > $testroot/wt/alpha
228 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
229 local commit_id=`git_show_head $testroot/repo-clone`
230 local author_time=`git_show_author_time $testroot/repo-clone`
231 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
232 set -- "$@" "$commit_id $d"
235 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
238 got send -b main -q -r $testroot/repo-clone
240 if [ $ret -ne 0 ]; then
241 echo "got send failed unexpectedly" >&2
242 test_done "$testroot" "1"
246 wait %1 # wait for the http "server"
248 printf '{"notifications":[' > $testroot/stdout.expected
250 for i in `seq 1 24`; do
252 commit_id=$(echo $s | cut -d' ' -f1)
253 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
265 "full":"$GOT_AUTHOR",
266 "name":"$GIT_AUTHOR_NAME",
267 "mail":"$GIT_AUTHOR_EMAIL",
268 "user":"$GOT_AUTHOR_11"
271 "full":"$GOT_AUTHOR",
272 "name":"$GIT_AUTHOR_NAME",
273 "mail":"$GIT_AUTHOR_EMAIL",
274 "user":"$GOT_AUTHOR_11"
276 "date":"$commit_time",
277 "short_message":"make changes",
278 "message":"make changes\n",
293 done >> $testroot/stdout.expected
294 echo "]}" >> $testroot/stdout.expected
295 ed -s "$testroot/stdout.expected" <<-EOF
300 cmp -s $testroot/stdout.expected $testroot/stdout
302 if [ $ret -ne 0 ]; then
303 diff -u $testroot/stdout.expected $testroot/stdout
304 test_done "$testroot" "$ret"
308 test_done "$testroot" "$ret"
311 test_many_commits_summarized() {
312 local testroot=`test_init many_commits_summarized 1`
314 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
316 if [ $ret -ne 0 ]; then
317 echo "got clone failed unexpectedly" >&2
318 test_done "$testroot" 1
322 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
324 if [ $ret -ne 0 ]; then
325 echo "got checkout failed unexpectedly" >&2
326 test_done "$testroot" 1
330 for i in `seq 1 51`; do
331 echo "alpha $i" > $testroot/wt/alpha
332 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
333 local commit_id=`git_show_head $testroot/repo-clone`
334 local short_commit_id=`trim_obj_id 33 $commit_id`
335 local author_time=`git_show_author_time $testroot/repo-clone`
336 d=`date -u -r $author_time +"%G-%m-%d"`
337 set -- "$@" "$short_commit_id $d"
340 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
343 got send -b main -q -r $testroot/repo-clone
345 if [ $ret -ne 0 ]; then
346 echo "got send failed unexpectedly" >&2
347 test_done "$testroot" "1"
351 wait %1 # wait for the http "server"
353 printf '{"notifications":[' > $testroot/stdout.expected
355 for i in `seq 1 51`; do
357 commit_id=$(echo $s | cut -d' ' -f1)
358 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
370 "user":"$GOT_AUTHOR_8"
372 "date":"$commit_time",
373 "short_message":"make changes"
376 done >> $testroot/stdout.expected
377 echo "]}" >> $testroot/stdout.expected
378 ed -s "$testroot/stdout.expected" <<-EOF
383 cmp -s $testroot/stdout.expected $testroot/stdout
385 if [ $ret -ne 0 ]; then
386 diff -u $testroot/stdout.expected $testroot/stdout
387 test_done "$testroot" "$ret"
391 test_done "$testroot" "$ret"
394 test_branch_created() {
395 local testroot=`test_init branch_created 1`
397 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
399 if [ $ret -ne 0 ]; then
400 echo "got clone failed unexpectedly" >&2
401 test_done "$testroot" 1
405 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
407 if [ $ret -ne 0 ]; then
408 echo "got checkout failed unexpectedly" >&2
409 test_done "$testroot" 1
413 (cd $testroot/wt && got branch newbranch > /dev/null)
415 echo "change alpha on branch" > $testroot/wt/alpha
416 (cd $testroot/wt && got commit -m 'newbranch' > /dev/null)
417 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
418 local author_time=`git_show_author_time $testroot/repo-clone $commit_id`
420 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
423 got send -b newbranch -q -r $testroot/repo-clone
425 if [ $ret -ne 0 ]; then
426 echo "got send failed unexpectedly" >&2
427 test_done "$testroot" "1"
431 wait %1 # wait for the http "server"
433 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
435 # in the future it should contain something like this too
437 # "type":"new-branch",
438 # "user":"${GOTD_DEVUSER}",
439 # "ref":"refs/heads/newbranch"
442 touch "$testroot/stdout.expected"
443 ed -s "$testroot/stdout.expected" <<-EOF
452 "full":"$GOT_AUTHOR",
453 "name":"$GIT_AUTHOR_NAME",
454 "mail":"$GIT_AUTHOR_EMAIL",
455 "user":"$GOT_AUTHOR_11"
458 "full":"$GOT_AUTHOR",
459 "name":"$GIT_AUTHOR_NAME",
460 "mail":"$GIT_AUTHOR_EMAIL",
461 "user":"$GOT_AUTHOR_11"
464 "short_message":"newbranch",
465 "message":"newbranch\n",
485 cmp -s $testroot/stdout.expected $testroot/stdout
487 if [ $ret -ne 0 ]; then
488 diff -u $testroot/stdout.expected $testroot/stdout
489 test_done "$testroot" "$ret"
493 test_done "$testroot" "$ret"
496 test_branch_removed() {
497 local testroot=`test_init branch_removed 1`
499 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
501 if [ $ret -ne 0 ]; then
502 echo "got clone failed unexpectedly" >&2
503 test_done "$testroot" 1
507 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
510 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
512 got send -d newbranch -q -r $testroot/repo-clone
514 if [ $ret -ne 0 ]; then
515 echo "got send failed unexpectedly" >&2
516 test_done "$testroot" "1"
520 wait %1 # wait for the http "server"
522 touch "$testroot/stdout.expected"
523 ed -s "$testroot/stdout.expected" <<-EOF
526 "type":"branch-deleted",
528 "ref":"refs/heads/newbranch",
536 cmp -s $testroot/stdout.expected $testroot/stdout
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 test_done "$testroot" "$ret"
544 test_done "$testroot" "$ret"
548 local testroot=`test_init tag_created 1`
550 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
552 if [ $ret -ne 0 ]; then
553 echo "got clone failed unexpectedly" >&2
554 test_done "$testroot" 1
558 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
559 local commit_id=`git_show_head $testroot/repo-clone`
560 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
562 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
565 got send -t 1.0 -q -r $testroot/repo-clone
567 if [ $ret -ne 0 ]; then
568 echo "got send failed unexpectedly" >&2
569 test_done "$testroot" "1"
573 wait %1 # wait for the http "server"
575 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
577 touch "$testroot/stdout.expected"
578 ed -s "$testroot/stdout.expected" <<-EOF
583 "tag":"refs/tags/1.0",
585 "full":"$GOT_AUTHOR",
586 "name":"$GIT_AUTHOR_NAME",
587 "mail":"$GIT_AUTHOR_EMAIL",
588 "user":"$GOT_AUTHOR_11"
595 "message":"new tag\n\n"
602 cmp -s $testroot/stdout.expected $testroot/stdout
604 if [ $ret -ne 0 ]; then
605 diff -u $testroot/stdout.expected $testroot/stdout
606 test_done "$testroot" "$ret"
610 test_done "$testroot" "$ret"
614 local testroot=`test_init tag_changed 1`
616 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
618 if [ $ret -ne 0 ]; then
619 echo "got clone failed unexpectedly" >&2
620 test_done "$testroot" 1
624 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
626 if [ $ret -ne 0 ]; then
627 echo "got checkout failed unexpectedly" >&2
628 test_done "$testroot" 1
632 echo "change alpha" > $testroot/wt/alpha
633 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
634 local commit_id=`git_show_head $testroot/repo-clone`
636 got ref -r $testroot/repo-clone -d refs/tags/1.0 >/dev/null
637 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
638 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
640 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
643 got send -f -t 1.0 -q -r $testroot/repo-clone
645 if [ $ret -ne 0 ]; then
646 echo "got send failed unexpectedly" >&2
647 test_done "$testroot" "1"
651 wait %1 # wait for the http "server"
653 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
655 # XXX: at the moment this is exactly the same as the "new tag"
658 touch "$testroot/stdout.expected"
659 ed -s "$testroot/stdout.expected" <<-EOF
664 "tag":"refs/tags/1.0",
666 "full":"$GOT_AUTHOR",
667 "name":"$GIT_AUTHOR_NAME",
668 "mail":"$GIT_AUTHOR_EMAIL",
669 "user":"$GOT_AUTHOR_11"
676 "message":"new tag\n\n"
683 cmp -s $testroot/stdout.expected $testroot/stdout
685 if [ $ret -ne 0 ]; then
686 diff -u $testroot/stdout.expected $testroot/stdout
687 test_done "$testroot" "$ret"
691 test_done "$testroot" "$ret"
695 run_test test_file_changed
696 run_test test_bad_utf8
697 run_test test_many_commits_not_summarized
698 run_test test_many_commits_summarized
699 run_test test_branch_created
700 run_test test_branch_removed
701 run_test test_tag_created
702 run_test test_tag_changed