3 # Copyright (c) 2024 Stefan Sperling <stsp@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 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
45 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
47 sleep 1 # server starts up
49 got send -b main -q -r $testroot/repo-clone
51 if [ $ret -ne 0 ]; then
52 echo "got send failed unexpectedly" >&2
53 test_done "$testroot" "1"
57 wait %1 # wait for nc -l
59 short_commit_id=`trim_obj_id 28 $commit_id`
61 printf "HELO localhost\r\n" > $testroot/stdout.expected
62 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
63 >> $testroot/stdout.expected
64 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
65 printf "DATA\r\n" >> $testroot/stdout.expected
66 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
67 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
68 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
69 printf "${GOTD_DEVUSER} changed refs/heads/main: $short_commit_id\r\n" \
70 >> $testroot/stdout.expected
71 printf "\r\n" >> $testroot/stdout.expected
72 printf "commit $commit_id\n" >> $testroot/stdout.expected
73 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
74 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
75 printf "date: $d\n" >> $testroot/stdout.expected
76 printf "messagelen: 14\n" >> $testroot/stdout.expected
77 printf " \n" >> $testroot/stdout.expected
78 printf " make changes\n \n" >> $testroot/stdout.expected
79 printf " M alpha | 1+ 1-\n\n" >> $testroot/stdout.expected
80 printf "1 file changed, 1 insertion(+), 1 deletion(-)\n\n" \
81 >> $testroot/stdout.expected
82 printf "\r\n" >> $testroot/stdout.expected
83 printf ".\r\n" >> $testroot/stdout.expected
84 printf "QUIT\r\n" >> $testroot/stdout.expected
86 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
87 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
89 if [ $ret -ne 0 ]; then
90 diff -u $testroot/stdout.expected $testroot/stdout.filtered
91 test_done "$testroot" "$ret"
95 test_done "$testroot" "$ret"
98 test_many_commits_not_summarized() {
99 local testroot=`test_init many_commits_not_summarized 1`
101 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
103 if [ $ret -ne 0 ]; then
104 echo "got clone failed unexpectedly" >&2
105 test_done "$testroot" 1
109 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
111 if [ $ret -ne 0 ]; then
112 echo "got checkout failed unexpectedly" >&2
113 test_done "$testroot" 1
117 for i in `seq 1 24`; do
118 echo "alpha $i" > $testroot/wt/alpha
119 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
120 local commit_id=`git_show_head $testroot/repo-clone`
121 local author_time=`git_show_author_time $testroot/repo-clone`
122 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
123 set -- "$@" "$commit_id $d"
126 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
127 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
129 sleep 1 # server starts up
131 got send -b main -q -r $testroot/repo-clone
133 if [ $ret -ne 0 ]; then
134 echo "got send failed unexpectedly" >&2
135 test_done "$testroot" "1"
139 wait %1 # wait for nc -l
141 short_commit_id=`trim_obj_id 28 $commit_id`
143 printf "HELO localhost\r\n" > $testroot/stdout.expected
144 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
145 >> $testroot/stdout.expected
146 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
147 printf "DATA\r\n" >> $testroot/stdout.expected
148 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" \
149 >> $testroot/stdout.expected
150 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
151 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
152 printf "${GOTD_DEVUSER} changed refs/heads/main: $short_commit_id\r\n" \
153 >> $testroot/stdout.expected
154 printf "\r\n" >> $testroot/stdout.expected
155 for i in `seq 1 24`; do
157 commit_id=$(echo $s | cut -d' ' -f1)
158 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
159 printf "commit $commit_id\n" >> $testroot/stdout.expected
160 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
161 printf "date: $commit_time\n" >> $testroot/stdout.expected
162 printf "messagelen: 14\n" >> $testroot/stdout.expected
163 printf " \n" >> $testroot/stdout.expected
164 printf " make changes\n \n" >> $testroot/stdout.expected
165 printf " M alpha | 1+ 1-\n\n" \
166 >> $testroot/stdout.expected
167 printf "1 file changed, 1 insertion(+), 1 deletion(-)\n\n" \
168 >> $testroot/stdout.expected
170 printf "\r\n" >> $testroot/stdout.expected
171 printf ".\r\n" >> $testroot/stdout.expected
172 printf "QUIT\r\n" >> $testroot/stdout.expected
174 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
175 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
177 if [ $ret -ne 0 ]; then
178 diff -u $testroot/stdout.expected $testroot/stdout.filtered
179 test_done "$testroot" "$ret"
183 test_done "$testroot" "$ret"
186 test_many_commits_summarized() {
187 local testroot=`test_init many_commits_summarized 1`
189 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
191 if [ $ret -ne 0 ]; then
192 echo "got clone failed unexpectedly" >&2
193 test_done "$testroot" 1
197 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
199 if [ $ret -ne 0 ]; then
200 echo "got checkout failed unexpectedly" >&2
201 test_done "$testroot" 1
205 for i in `seq 1 51`; do
206 echo "alpha $i" > $testroot/wt/alpha
207 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
208 local commit_id=`git_show_head $testroot/repo-clone`
209 local short_commit_id=`trim_obj_id 33 $commit_id`
210 local author_time=`git_show_author_time $testroot/repo-clone`
211 d=`date -u -r $author_time +"%F"`
212 set -- "$@" "$short_commit_id $d"
215 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
216 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
218 sleep 1 # server starts up
220 got send -b main -q -r $testroot/repo-clone
222 if [ $ret -ne 0 ]; then
223 echo "got send failed unexpectedly" >&2
224 test_done "$testroot" "1"
228 wait %1 # wait for nc -l
230 short_commit_id=`trim_obj_id 28 $commit_id`
232 printf "HELO localhost\r\n" > $testroot/stdout.expected
233 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
234 >> $testroot/stdout.expected
235 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
236 printf "DATA\r\n" >> $testroot/stdout.expected
237 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" \
238 >> $testroot/stdout.expected
239 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
240 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
241 printf "${GOTD_DEVUSER} changed refs/heads/main: $short_commit_id\r\n" \
242 >> $testroot/stdout.expected
243 printf "\r\n" >> $testroot/stdout.expected
244 for i in `seq 1 51`; do
246 commit_id=$(echo $s | cut -d' ' -f1)
247 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
248 printf "$commit_time $commit_id $GOT_AUTHOR_8 make changes\n" \
249 >> $testroot/stdout.expected
251 printf "\r\n" >> $testroot/stdout.expected
252 printf ".\r\n" >> $testroot/stdout.expected
253 printf "QUIT\r\n" >> $testroot/stdout.expected
255 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
256 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
258 if [ $ret -ne 0 ]; then
259 diff -u $testroot/stdout.expected $testroot/stdout.filtered
260 test_done "$testroot" "$ret"
264 test_done "$testroot" "$ret"
267 test_branch_created() {
268 local testroot=`test_init branch_created 1`
270 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
272 if [ $ret -ne 0 ]; then
273 echo "got clone failed unexpectedly" >&2
274 test_done "$testroot" 1
278 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
280 if [ $ret -ne 0 ]; then
281 echo "got checkout failed unexpectedly" >&2
282 test_done "$testroot" 1
286 (cd $testroot/wt && got branch newbranch > /dev/null)
288 echo "change alpha on branch" > $testroot/wt/alpha
289 (cd $testroot/wt && got commit -m 'newbranch' > /dev/null)
290 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
291 local author_time=`git_show_author_time $testroot/repo-clone $commit_id`
293 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
294 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
296 sleep 1 # server starts up
298 got send -b newbranch -q -r $testroot/repo-clone
300 if [ $ret -ne 0 ]; then
301 echo "got send failed unexpectedly" >&2
302 test_done "$testroot" "1"
306 wait %1 # wait for nc -l
308 short_commit_id=`trim_obj_id 28 $commit_id`
310 printf "HELO localhost\r\n" > $testroot/stdout.expected
311 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
312 >> $testroot/stdout.expected
313 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
314 printf "DATA\r\n" >> $testroot/stdout.expected
315 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
316 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
317 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
318 printf "${GOTD_DEVUSER} created refs/heads/newbranch: $short_commit_id\r\n" \
319 >> $testroot/stdout.expected
320 printf "\r\n" >> $testroot/stdout.expected
321 printf "commit $commit_id\n" >> $testroot/stdout.expected
322 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
323 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
324 printf "date: $d\n" >> $testroot/stdout.expected
325 printf "messagelen: 11\n" >> $testroot/stdout.expected
326 printf " \n" >> $testroot/stdout.expected
327 printf " newbranch\n \n" >> $testroot/stdout.expected
328 printf " M alpha | 1+ 1-\n\n" >> $testroot/stdout.expected
329 printf "1 file changed, 1 insertion(+), 1 deletion(-)\n\n" \
330 >> $testroot/stdout.expected
331 printf "\r\n" >> $testroot/stdout.expected
332 printf ".\r\n" >> $testroot/stdout.expected
333 printf "QUIT\r\n" >> $testroot/stdout.expected
335 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
336 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
338 if [ $ret -ne 0 ]; then
339 diff -u $testroot/stdout.expected $testroot/stdout.filtered
340 test_done "$testroot" "$ret"
344 test_done "$testroot" "$ret"
347 test_branch_removed() {
348 local testroot=`test_init branch_removed 1`
350 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
352 if [ $ret -ne 0 ]; then
353 echo "got clone failed unexpectedly" >&2
354 test_done "$testroot" 1
358 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
359 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
361 sleep 1 # server starts up
363 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
364 local short_commit_id=`trim_obj_id 28 $commit_id`
366 got send -d newbranch -q -r $testroot/repo-clone
368 if [ $ret -ne 0 ]; then
369 echo "got send failed unexpectedly" >&2
370 test_done "$testroot" "1"
374 wait %1 # wait for nc -l
377 printf "HELO localhost\r\n" > $testroot/stdout.expected
378 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
379 >> $testroot/stdout.expected
380 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
381 printf "DATA\r\n" >> $testroot/stdout.expected
382 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
383 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
384 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
385 printf "${GOTD_DEVUSER} removed refs/heads/newbranch: $short_commit_id\r\n" \
386 >> $testroot/stdout.expected
387 printf "\r\n" >> $testroot/stdout.expected
388 printf "Removed refs/heads/newbranch: $commit_id\n" \
389 >> $testroot/stdout.expected
390 printf "\r\n" >> $testroot/stdout.expected
391 printf ".\r\n" >> $testroot/stdout.expected
392 printf "QUIT\r\n" >> $testroot/stdout.expected
394 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
395 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
397 if [ $ret -ne 0 ]; then
398 diff -u $testroot/stdout.expected $testroot/stdout.filtered
399 test_done "$testroot" "$ret"
403 test_done "$testroot" "$ret"
407 local testroot=`test_init tag_created 1`
409 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
411 if [ $ret -ne 0 ]; then
412 echo "got clone failed unexpectedly" >&2
413 test_done "$testroot" 1
417 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
418 local commit_id=`git_show_head $testroot/repo-clone`
419 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
420 local tag_id=`got ref -r $testroot/repo-clone -l \
421 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
422 local short_tag_id=`trim_obj_id 28 $tag_id`
424 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
425 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
427 sleep 1 # server starts up
429 got send -t 1.0 -q -r $testroot/repo-clone
431 if [ $ret -ne 0 ]; then
432 echo "got send failed unexpectedly" >&2
433 test_done "$testroot" "1"
437 wait %1 # wait for nc -l
440 printf "HELO localhost\r\n" > $testroot/stdout.expected
441 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
442 >> $testroot/stdout.expected
443 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
444 printf "DATA\r\n" >> $testroot/stdout.expected
445 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
446 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
447 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
448 printf "${GOTD_DEVUSER} created refs/tags/1.0: $short_tag_id\r\n" \
449 >> $testroot/stdout.expected
450 printf "\r\n" >> $testroot/stdout.expected
451 printf "tag refs/tags/1.0\n" >> $testroot/stdout.expected
452 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
453 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
454 printf "date: $d\n" >> $testroot/stdout.expected
455 printf "object: commit $commit_id\n" >> $testroot/stdout.expected
456 printf "messagelen: 9\n" >> $testroot/stdout.expected
457 printf " \n" >> $testroot/stdout.expected
458 printf " new tag\n \n" >> $testroot/stdout.expected
459 printf "\r\n" >> $testroot/stdout.expected
460 printf ".\r\n" >> $testroot/stdout.expected
461 printf "QUIT\r\n" >> $testroot/stdout.expected
463 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
464 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
466 if [ $ret -ne 0 ]; then
467 diff -u $testroot/stdout.expected $testroot/stdout.filtered
468 test_done "$testroot" "$ret"
472 test_done "$testroot" "$ret"
476 local testroot=`test_init tag_changed 1`
478 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
480 if [ $ret -ne 0 ]; then
481 echo "got clone failed unexpectedly" >&2
482 test_done "$testroot" 1
486 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
488 if [ $ret -ne 0 ]; then
489 echo "got checkout failed unexpectedly" >&2
490 test_done "$testroot" 1
494 echo "change alpha" > $testroot/wt/alpha
495 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
496 local commit_id=`git_show_head $testroot/repo-clone`
498 got ref -r $testroot/repo-clone -d refs/tags/1.0 >/dev/null
499 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
500 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
501 local tag_id=`got ref -r $testroot/repo-clone -l \
502 | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
503 local short_tag_id=`trim_obj_id 28 $tag_id`
505 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
506 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
508 sleep 1 # server starts up
510 got send -f -t 1.0 -q -r $testroot/repo-clone
512 if [ $ret -ne 0 ]; then
513 echo "got send failed unexpectedly" >&2
514 test_done "$testroot" "1"
518 wait %1 # wait for nc -l
521 printf "HELO localhost\r\n" > $testroot/stdout.expected
522 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
523 >> $testroot/stdout.expected
524 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
525 printf "DATA\r\n" >> $testroot/stdout.expected
526 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
527 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
528 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
529 printf "${GOTD_DEVUSER} changed refs/tags/1.0: $short_tag_id\r\n" \
530 >> $testroot/stdout.expected
531 printf "\r\n" >> $testroot/stdout.expected
532 printf "tag refs/tags/1.0\n" >> $testroot/stdout.expected
533 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
534 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
535 printf "date: $d\n" >> $testroot/stdout.expected
536 printf "object: commit $commit_id\n" >> $testroot/stdout.expected
537 printf "messagelen: 9\n" >> $testroot/stdout.expected
538 printf " \n" >> $testroot/stdout.expected
539 printf " new tag\n \n" >> $testroot/stdout.expected
540 printf "\r\n" >> $testroot/stdout.expected
541 printf ".\r\n" >> $testroot/stdout.expected
542 printf "QUIT\r\n" >> $testroot/stdout.expected
544 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
545 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
547 if [ $ret -ne 0 ]; then
548 diff -u $testroot/stdout.expected $testroot/stdout.filtered
549 test_done "$testroot" "$ret"
553 test_done "$testroot" "$ret"
557 run_test test_file_changed
558 run_test test_many_commits_not_summarized
559 run_test test_many_commits_summarized
560 run_test test_branch_created
561 run_test test_branch_removed
562 run_test test_tag_created
563 run_test test_tag_changed