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
21 local testroot=`test_init file_changed 1`
23 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
25 if [ $ret -ne 0 ]; then
26 echo "got clone failed unexpectedly" >&2
27 test_done "$testroot" 1
31 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
33 if [ $ret -ne 0 ]; then
34 echo "got checkout failed unexpectedly" >&2
35 test_done "$testroot" 1
39 echo "change alpha" > $testroot/wt/alpha
40 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
41 local commit_id=`git_show_head $testroot/repo-clone`
42 local author_time=`git_show_author_time $testroot/repo-clone`
44 timeout 5 ./http-server -p $GOTD_TEST_HTTP_PORT \
47 got send -b main -q -r $testroot/repo-clone
49 if [ $ret -ne 0 ]; then
50 echo "got send failed unexpectedly" >&2
51 test_done "$testroot" "1"
55 wait %1 # wait for the http "server"
57 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
59 touch "$testroot/stdout.expected"
60 ed -s "$testroot/stdout.expected" <<-EOF
68 "name":"$GIT_AUTHOR_NAME",
69 "mail":"$GIT_AUTHOR_EMAIL",
70 "user":"$GOT_AUTHOR_11"
74 "name":"$GIT_AUTHOR_NAME",
75 "mail":"$GIT_AUTHOR_EMAIL",
76 "user":"$GOT_AUTHOR_11"
79 "short_message":"make changes",
80 "message":"make changes\n",
99 cmp -s $testroot/stdout.expected $testroot/stdout
101 if [ $ret -ne 0 ]; then
102 diff -u $testroot/stdout.expected $testroot/stdout
103 test_done "$testroot" "$ret"
107 test_done "$testroot" "$ret"
111 local testroot=`test_init bad_utf8 1`
113 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
115 if [ $ret -ne 0 ]; then
116 echo "got clone failed unexpectedly" >&2
117 test_done "$testroot" 1
121 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
123 if [ $ret -ne 0 ]; then
124 echo "got checkout failed unexpectedly" >&2
125 test_done "$testroot" 1
128 # invalid utf8 sequence
129 commit_msg="make$(printf '\xED\xA0\x80')changes"
131 echo "changed" > $testroot/wt/alpha
132 (cd $testroot/wt && got commit -m "$commit_msg" > /dev/null)
133 local commit_id=`git_show_head $testroot/repo-clone`
134 local author_time=`git_show_author_time $testroot/repo-clone`
136 timeout 5 ./http-server -p $GOTD_TEST_HTTP_PORT \
139 got send -b main -q -r $testroot/repo-clone
141 if [ $ret -ne 0 ]; then
142 echo "got send failed unexpectedly" >&2
143 test_done "$testroot" "1"
147 wait %1 # wait for the http "server"
149 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
151 touch "$testroot/stdout.expected"
152 ed -s "$testroot/stdout.expected" <<-EOF
159 "full":"$GOT_AUTHOR",
160 "name":"$GIT_AUTHOR_NAME",
161 "mail":"$GIT_AUTHOR_EMAIL",
162 "user":"$GOT_AUTHOR_11"
165 "full":"$GOT_AUTHOR",
166 "name":"$GIT_AUTHOR_NAME",
167 "mail":"$GIT_AUTHOR_EMAIL",
168 "user":"$GOT_AUTHOR_11"
171 "short_message":"make\uFFFD\uFFFDchanges",
172 "message":"make\uFFFD\uFFFDchanges\n",
191 cmp -s $testroot/stdout.expected $testroot/stdout
193 if [ $ret -ne 0 ]; then
194 diff -u $testroot/stdout.expected $testroot/stdout
195 test_done "$testroot" "$ret"
199 test_done "$testroot" "$ret"
202 test_many_commits_not_summarized() {
203 local testroot=`test_init many_commits_not_summarized 1`
205 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
207 if [ $ret -ne 0 ]; then
208 echo "got clone failed unexpectedly" >&2
209 test_done "$testroot" 1
213 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
215 if [ $ret -ne 0 ]; then
216 echo "got checkout failed unexpectedly" >&2
217 test_done "$testroot" 1
221 for i in `seq 1 24`; do
222 echo "alpha $i" > $testroot/wt/alpha
223 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
224 local commit_id=`git_show_head $testroot/repo-clone`
225 local author_time=`git_show_author_time $testroot/repo-clone`
226 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
227 set -- "$@" "$commit_id $d"
230 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
233 got send -b main -q -r $testroot/repo-clone
235 if [ $ret -ne 0 ]; then
236 echo "got send failed unexpectedly" >&2
237 test_done "$testroot" "1"
241 wait %1 # wait for the http "server"
243 printf '{"notifications":[' > $testroot/stdout.expected
245 for i in `seq 1 24`; do
247 commit_id=$(echo $s | cut -d' ' -f1)
248 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
259 "full":"$GOT_AUTHOR",
260 "name":"$GIT_AUTHOR_NAME",
261 "mail":"$GIT_AUTHOR_EMAIL",
262 "user":"$GOT_AUTHOR_11"
265 "full":"$GOT_AUTHOR",
266 "name":"$GIT_AUTHOR_NAME",
267 "mail":"$GIT_AUTHOR_EMAIL",
268 "user":"$GOT_AUTHOR_11"
270 "date":"$commit_time",
271 "short_message":"make changes",
272 "message":"make changes\n",
287 done >> $testroot/stdout.expected
288 echo "]}" >> $testroot/stdout.expected
289 ed -s "$testroot/stdout.expected" <<-EOF
294 cmp -s $testroot/stdout.expected $testroot/stdout
296 if [ $ret -ne 0 ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$ret"
302 test_done "$testroot" "$ret"
305 test_many_commits_summarized() {
306 local testroot=`test_init many_commits_summarized 1`
308 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
310 if [ $ret -ne 0 ]; then
311 echo "got clone failed unexpectedly" >&2
312 test_done "$testroot" 1
316 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
318 if [ $ret -ne 0 ]; then
319 echo "got checkout failed unexpectedly" >&2
320 test_done "$testroot" 1
324 for i in `seq 1 51`; do
325 echo "alpha $i" > $testroot/wt/alpha
326 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
327 local commit_id=`git_show_head $testroot/repo-clone`
328 local short_commit_id=`trim_obj_id 33 $commit_id`
329 local author_time=`git_show_author_time $testroot/repo-clone`
330 d=`date -u -r $author_time +"%G-%m-%d"`
331 set -- "$@" "$short_commit_id $d"
334 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
337 got send -b main -q -r $testroot/repo-clone
339 if [ $ret -ne 0 ]; then
340 echo "got send failed unexpectedly" >&2
341 test_done "$testroot" "1"
345 wait %1 # wait for the http "server"
347 printf '{"notifications":[' > $testroot/stdout.expected
349 for i in `seq 1 51`; do
351 commit_id=$(echo $s | cut -d' ' -f1)
352 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
363 "user":"$GOT_AUTHOR_8"
365 "date":"$commit_time",
366 "short_message":"make changes"
369 done >> $testroot/stdout.expected
370 echo "]}" >> $testroot/stdout.expected
371 ed -s "$testroot/stdout.expected" <<-EOF
376 cmp -s $testroot/stdout.expected $testroot/stdout
378 if [ $ret -ne 0 ]; then
379 diff -u $testroot/stdout.expected $testroot/stdout
380 test_done "$testroot" "$ret"
384 test_done "$testroot" "$ret"
387 test_branch_created() {
388 local testroot=`test_init branch_created 1`
390 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
392 if [ $ret -ne 0 ]; then
393 echo "got clone failed unexpectedly" >&2
394 test_done "$testroot" 1
398 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
400 if [ $ret -ne 0 ]; then
401 echo "got checkout failed unexpectedly" >&2
402 test_done "$testroot" 1
406 (cd $testroot/wt && got branch newbranch > /dev/null)
408 echo "change alpha on branch" > $testroot/wt/alpha
409 (cd $testroot/wt && got commit -m 'newbranch' > /dev/null)
410 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
411 local author_time=`git_show_author_time $testroot/repo-clone $commit_id`
413 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
416 got send -b newbranch -q -r $testroot/repo-clone
418 if [ $ret -ne 0 ]; then
419 echo "got send failed unexpectedly" >&2
420 test_done "$testroot" "1"
424 wait %1 # wait for the http "server"
426 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
428 # in the future it should contain something like this too
430 # "type":"new-branch",
431 # "user":"${GOTD_DEVUSER}",
432 # "ref":"refs/heads/newbranch"
435 touch "$testroot/stdout.expected"
436 ed -s "$testroot/stdout.expected" <<-EOF
444 "full":"$GOT_AUTHOR",
445 "name":"$GIT_AUTHOR_NAME",
446 "mail":"$GIT_AUTHOR_EMAIL",
447 "user":"$GOT_AUTHOR_11"
450 "full":"$GOT_AUTHOR",
451 "name":"$GIT_AUTHOR_NAME",
452 "mail":"$GIT_AUTHOR_EMAIL",
453 "user":"$GOT_AUTHOR_11"
456 "short_message":"newbranch",
457 "message":"newbranch\n",
477 cmp -s $testroot/stdout.expected $testroot/stdout
479 if [ $ret -ne 0 ]; then
480 diff -u $testroot/stdout.expected $testroot/stdout
481 test_done "$testroot" "$ret"
485 test_done "$testroot" "$ret"
488 test_branch_removed() {
489 local testroot=`test_init branch_removed 1`
491 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
493 if [ $ret -ne 0 ]; then
494 echo "got clone failed unexpectedly" >&2
495 test_done "$testroot" 1
499 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
502 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
504 got send -d newbranch -q -r $testroot/repo-clone
506 if [ $ret -ne 0 ]; then
507 echo "got send failed unexpectedly" >&2
508 test_done "$testroot" "1"
512 wait %1 # wait for the http "server"
514 touch "$testroot/stdout.expected"
515 ed -s "$testroot/stdout.expected" <<-EOF
518 "type":"branch-deleted",
519 "ref":"refs/heads/newbranch",
527 cmp -s $testroot/stdout.expected $testroot/stdout
529 if [ $ret -ne 0 ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 test_done "$testroot" "$ret"
535 test_done "$testroot" "$ret"
539 local testroot=`test_init tag_created 1`
541 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
543 if [ $ret -ne 0 ]; then
544 echo "got clone failed unexpectedly" >&2
545 test_done "$testroot" 1
549 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
550 local commit_id=`git_show_head $testroot/repo-clone`
551 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
553 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
556 got send -t 1.0 -q -r $testroot/repo-clone
558 if [ $ret -ne 0 ]; then
559 echo "got send failed unexpectedly" >&2
560 test_done "$testroot" "1"
564 wait %1 # wait for the http "server"
566 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
568 touch "$testroot/stdout.expected"
569 ed -s "$testroot/stdout.expected" <<-EOF
573 "tag":"refs/tags/1.0",
575 "full":"$GOT_AUTHOR",
576 "name":"$GIT_AUTHOR_NAME",
577 "mail":"$GIT_AUTHOR_EMAIL",
578 "user":"$GOT_AUTHOR_11"
585 "message":"new tag\n\n"
592 cmp -s $testroot/stdout.expected $testroot/stdout
594 if [ $ret -ne 0 ]; then
595 diff -u $testroot/stdout.expected $testroot/stdout
596 test_done "$testroot" "$ret"
600 test_done "$testroot" "$ret"
604 local testroot=`test_init tag_changed 1`
606 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
608 if [ $ret -ne 0 ]; then
609 echo "got clone failed unexpectedly" >&2
610 test_done "$testroot" 1
614 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
616 if [ $ret -ne 0 ]; then
617 echo "got checkout failed unexpectedly" >&2
618 test_done "$testroot" 1
622 echo "change alpha" > $testroot/wt/alpha
623 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
624 local commit_id=`git_show_head $testroot/repo-clone`
626 got ref -r $testroot/repo-clone -d refs/tags/1.0 >/dev/null
627 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
628 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
630 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
633 got send -f -t 1.0 -q -r $testroot/repo-clone
635 if [ $ret -ne 0 ]; then
636 echo "got send failed unexpectedly" >&2
637 test_done "$testroot" "1"
641 wait %1 # wait for the http "server"
643 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
645 # XXX: at the moment this is exactly the same as the "new tag"
648 touch "$testroot/stdout.expected"
649 ed -s "$testroot/stdout.expected" <<-EOF
653 "tag":"refs/tags/1.0",
655 "full":"$GOT_AUTHOR",
656 "name":"$GIT_AUTHOR_NAME",
657 "mail":"$GIT_AUTHOR_EMAIL",
658 "user":"$GOT_AUTHOR_11"
665 "message":"new tag\n\n"
672 cmp -s $testroot/stdout.expected $testroot/stdout
674 if [ $ret -ne 0 ]; then
675 diff -u $testroot/stdout.expected $testroot/stdout
676 test_done "$testroot" "$ret"
680 test_done "$testroot" "$ret"
684 run_test test_file_changed
685 run_test test_bad_utf8
686 run_test test_many_commits_not_summarized
687 run_test test_many_commits_summarized
688 run_test test_branch_created
689 run_test test_branch_removed
690 run_test test_tag_created
691 run_test test_tag_changed