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 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 nc -l
58 printf "HELO localhost\r\n" > $testroot/stdout.expected
59 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
60 >> $testroot/stdout.expected
61 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
62 printf "DATA\r\n" >> $testroot/stdout.expected
63 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
64 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
65 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
66 printf "${GOTD_DEVUSER} changed refs/heads/main\r\n" \
67 >> $testroot/stdout.expected
68 printf "\r\n" >> $testroot/stdout.expected
69 printf "commit $commit_id\n" >> $testroot/stdout.expected
70 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
71 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
72 printf "date: $d\n" >> $testroot/stdout.expected
73 printf "messagelen: 14\n" >> $testroot/stdout.expected
74 printf " \n" >> $testroot/stdout.expected
75 printf " make changes\n \n" >> $testroot/stdout.expected
76 printf " M alpha | 1+ 1-\n\n" >> $testroot/stdout.expected
77 printf "1 file changed, 1 insertion(+), 1 deletion(-)\n\n" \
78 >> $testroot/stdout.expected
79 printf "\r\n" >> $testroot/stdout.expected
80 printf ".\r\n" >> $testroot/stdout.expected
81 printf "QUIT\r\n" >> $testroot/stdout.expected
83 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
84 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
86 if [ $ret -ne 0 ]; then
87 diff -u $testroot/stdout.expected $testroot/stdout.filtered
88 test_done "$testroot" "$ret"
92 test_done "$testroot" "$ret"
95 test_many_commits_not_summarized() {
96 local testroot=`test_init many_commits_not_summarized 1`
98 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
100 if [ $ret -ne 0 ]; then
101 echo "got clone failed unexpectedly" >&2
102 test_done "$testroot" 1
106 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
108 if [ $ret -ne 0 ]; then
109 echo "got checkout failed unexpectedly" >&2
110 test_done "$testroot" 1
114 for i in `seq 1 24`; do
115 echo "alpha $i" > $testroot/wt/alpha
116 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
117 local commit_id=`git_show_head $testroot/repo-clone`
118 local author_time=`git_show_author_time $testroot/repo-clone`
119 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
120 set -- "$@" "$commit_id $d"
123 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
124 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
126 got send -b main -q -r $testroot/repo-clone
128 if [ $ret -ne 0 ]; then
129 echo "got send failed unexpectedly" >&2
130 test_done "$testroot" "1"
134 wait %1 # wait for nc -l
137 printf "HELO localhost\r\n" > $testroot/stdout.expected
138 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
139 >> $testroot/stdout.expected
140 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
141 printf "DATA\r\n" >> $testroot/stdout.expected
142 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" \
143 >> $testroot/stdout.expected
144 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
145 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
146 printf "${GOTD_DEVUSER} changed refs/heads/main\r\n" \
147 >> $testroot/stdout.expected
148 printf "\r\n" >> $testroot/stdout.expected
149 for i in `seq 1 24`; do
151 commit_id=$(echo $s | cut -d' ' -f1)
152 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
153 printf "commit $commit_id\n" >> $testroot/stdout.expected
154 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
155 printf "date: $commit_time\n" >> $testroot/stdout.expected
156 printf "messagelen: 14\n" >> $testroot/stdout.expected
157 printf " \n" >> $testroot/stdout.expected
158 printf " make changes\n \n" >> $testroot/stdout.expected
159 printf " M alpha | 1+ 1-\n\n" \
160 >> $testroot/stdout.expected
161 printf "1 file changed, 1 insertion(+), 1 deletion(-)\n\n" \
162 >> $testroot/stdout.expected
164 printf "\r\n" >> $testroot/stdout.expected
165 printf ".\r\n" >> $testroot/stdout.expected
166 printf "QUIT\r\n" >> $testroot/stdout.expected
168 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
169 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
171 if [ $ret -ne 0 ]; then
172 diff -u $testroot/stdout.expected $testroot/stdout.filtered
173 test_done "$testroot" "$ret"
177 test_done "$testroot" "$ret"
180 test_many_commits_summarized() {
181 local testroot=`test_init many_commits_summarized 1`
183 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
185 if [ $ret -ne 0 ]; then
186 echo "got clone failed unexpectedly" >&2
187 test_done "$testroot" 1
191 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
193 if [ $ret -ne 0 ]; then
194 echo "got checkout failed unexpectedly" >&2
195 test_done "$testroot" 1
199 for i in `seq 1 51`; do
200 echo "alpha $i" > $testroot/wt/alpha
201 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
202 local commit_id=`git_show_head $testroot/repo-clone`
203 local short_commit_id=`trim_obj_id 33 $commit_id`
204 local author_time=`git_show_author_time $testroot/repo-clone`
205 d=`date -u -r $author_time +"%F"`
206 set -- "$@" "$short_commit_id $d"
209 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
210 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
212 got send -b main -q -r $testroot/repo-clone
214 if [ $ret -ne 0 ]; then
215 echo "got send failed unexpectedly" >&2
216 test_done "$testroot" "1"
220 wait %1 # wait for nc -l
223 printf "HELO localhost\r\n" > $testroot/stdout.expected
224 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
225 >> $testroot/stdout.expected
226 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
227 printf "DATA\r\n" >> $testroot/stdout.expected
228 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" \
229 >> $testroot/stdout.expected
230 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
231 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
232 printf "${GOTD_DEVUSER} changed refs/heads/main\r\n" \
233 >> $testroot/stdout.expected
234 printf "\r\n" >> $testroot/stdout.expected
235 for i in `seq 1 51`; do
237 commit_id=$(echo $s | cut -d' ' -f1)
238 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
239 printf "$commit_time $commit_id $GOT_AUTHOR_8 make changes\n" \
240 >> $testroot/stdout.expected
242 printf "\r\n" >> $testroot/stdout.expected
243 printf ".\r\n" >> $testroot/stdout.expected
244 printf "QUIT\r\n" >> $testroot/stdout.expected
246 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
247 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
249 if [ $ret -ne 0 ]; then
250 diff -u $testroot/stdout.expected $testroot/stdout.filtered
251 test_done "$testroot" "$ret"
255 test_done "$testroot" "$ret"
258 test_branch_created() {
259 local testroot=`test_init branch_created 1`
261 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
263 if [ $ret -ne 0 ]; then
264 echo "got clone failed unexpectedly" >&2
265 test_done "$testroot" 1
269 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
271 if [ $ret -ne 0 ]; then
272 echo "got checkout failed unexpectedly" >&2
273 test_done "$testroot" 1
277 (cd $testroot/wt && got branch newbranch > /dev/null)
279 echo "change alpha on branch" > $testroot/wt/alpha
280 (cd $testroot/wt && got commit -m 'newbranch' > /dev/null)
281 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
282 local author_time=`git_show_author_time $testroot/repo-clone $commit_id`
284 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
285 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
287 got send -b newbranch -q -r $testroot/repo-clone
289 if [ $ret -ne 0 ]; then
290 echo "got send failed unexpectedly" >&2
291 test_done "$testroot" "1"
295 wait %1 # wait for nc -l
298 printf "HELO localhost\r\n" > $testroot/stdout.expected
299 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
300 >> $testroot/stdout.expected
301 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
302 printf "DATA\r\n" >> $testroot/stdout.expected
303 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
304 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
305 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
306 printf "${GOTD_DEVUSER} created refs/heads/newbranch\r\n" \
307 >> $testroot/stdout.expected
308 printf "\r\n" >> $testroot/stdout.expected
309 printf "commit $commit_id\n" >> $testroot/stdout.expected
310 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
311 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
312 printf "date: $d\n" >> $testroot/stdout.expected
313 printf "messagelen: 11\n" >> $testroot/stdout.expected
314 printf " \n" >> $testroot/stdout.expected
315 printf " newbranch\n \n" >> $testroot/stdout.expected
316 printf " M alpha | 1+ 1-\n\n" >> $testroot/stdout.expected
317 printf "1 file changed, 1 insertion(+), 1 deletion(-)\n\n" \
318 >> $testroot/stdout.expected
319 printf "\r\n" >> $testroot/stdout.expected
320 printf ".\r\n" >> $testroot/stdout.expected
321 printf "QUIT\r\n" >> $testroot/stdout.expected
323 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
324 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
326 if [ $ret -ne 0 ]; then
327 diff -u $testroot/stdout.expected $testroot/stdout.filtered
328 test_done "$testroot" "$ret"
332 test_done "$testroot" "$ret"
335 test_branch_removed() {
336 local testroot=`test_init branch_removed 1`
338 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
340 if [ $ret -ne 0 ]; then
341 echo "got clone failed unexpectedly" >&2
342 test_done "$testroot" 1
346 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
347 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
349 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
351 got send -d newbranch -q -r $testroot/repo-clone
353 if [ $ret -ne 0 ]; then
354 echo "got send failed unexpectedly" >&2
355 test_done "$testroot" "1"
359 wait %1 # wait for nc -l
362 printf "HELO localhost\r\n" > $testroot/stdout.expected
363 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
364 >> $testroot/stdout.expected
365 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
366 printf "DATA\r\n" >> $testroot/stdout.expected
367 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
368 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
369 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
370 printf "${GOTD_DEVUSER} removed refs/heads/newbranch\r\n" \
371 >> $testroot/stdout.expected
372 printf "\r\n" >> $testroot/stdout.expected
373 printf "Removed refs/heads/newbranch: $commit_id\n" \
374 >> $testroot/stdout.expected
375 printf "\r\n" >> $testroot/stdout.expected
376 printf ".\r\n" >> $testroot/stdout.expected
377 printf "QUIT\r\n" >> $testroot/stdout.expected
379 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
380 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
382 if [ $ret -ne 0 ]; then
383 diff -u $testroot/stdout.expected $testroot/stdout.filtered
384 test_done "$testroot" "$ret"
388 test_done "$testroot" "$ret"
392 local testroot=`test_init tag_created 1`
394 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
396 if [ $ret -ne 0 ]; then
397 echo "got clone failed unexpectedly" >&2
398 test_done "$testroot" 1
402 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
403 local commit_id=`git_show_head $testroot/repo-clone`
404 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
406 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
407 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
409 got send -t 1.0 -q -r $testroot/repo-clone
411 if [ $ret -ne 0 ]; then
412 echo "got send failed unexpectedly" >&2
413 test_done "$testroot" "1"
417 wait %1 # wait for nc -l
420 printf "HELO localhost\r\n" > $testroot/stdout.expected
421 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
422 >> $testroot/stdout.expected
423 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
424 printf "DATA\r\n" >> $testroot/stdout.expected
425 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
426 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
427 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
428 printf "${GOTD_DEVUSER} created refs/tags/1.0\r\n" \
429 >> $testroot/stdout.expected
430 printf "\r\n" >> $testroot/stdout.expected
431 printf "tag refs/tags/1.0\n" >> $testroot/stdout.expected
432 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
433 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
434 printf "date: $d\n" >> $testroot/stdout.expected
435 printf "object: commit $commit_id\n" >> $testroot/stdout.expected
436 printf "messagelen: 9\n" >> $testroot/stdout.expected
437 printf " \n" >> $testroot/stdout.expected
438 printf " new tag\n \n" >> $testroot/stdout.expected
439 printf "\r\n" >> $testroot/stdout.expected
440 printf ".\r\n" >> $testroot/stdout.expected
441 printf "QUIT\r\n" >> $testroot/stdout.expected
443 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
444 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
446 if [ $ret -ne 0 ]; then
447 diff -u $testroot/stdout.expected $testroot/stdout.filtered
448 test_done "$testroot" "$ret"
452 test_done "$testroot" "$ret"
456 local testroot=`test_init tag_changed 1`
458 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
460 if [ $ret -ne 0 ]; then
461 echo "got clone failed unexpectedly" >&2
462 test_done "$testroot" 1
466 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
468 if [ $ret -ne 0 ]; then
469 echo "got checkout failed unexpectedly" >&2
470 test_done "$testroot" 1
474 echo "change alpha" > $testroot/wt/alpha
475 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
476 local commit_id=`git_show_head $testroot/repo-clone`
478 got ref -r $testroot/repo-clone -d refs/tags/1.0 >/dev/null
479 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
480 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
482 (printf "220\r\n250\r\n250\r\n250\r\n354\r\n250\r\n221\r\n" \
483 | timeout 5 nc -l "$GOTD_TEST_SMTP_PORT" > $testroot/stdout) &
485 got send -f -t 1.0 -q -r $testroot/repo-clone
487 if [ $ret -ne 0 ]; then
488 echo "got send failed unexpectedly" >&2
489 test_done "$testroot" "1"
493 wait %1 # wait for nc -l
496 printf "HELO localhost\r\n" > $testroot/stdout.expected
497 printf "MAIL FROM:<${GOTD_USER}@${HOSTNAME}>\r\n" \
498 >> $testroot/stdout.expected
499 printf "RCPT TO:<${GOTD_DEVUSER}>\r\n" >> $testroot/stdout.expected
500 printf "DATA\r\n" >> $testroot/stdout.expected
501 printf "From: ${GOTD_USER}@${HOSTNAME}\r\n" >> $testroot/stdout.expected
502 printf "To: ${GOTD_DEVUSER}\r\n" >> $testroot/stdout.expected
503 printf "Subject: $GOTD_TEST_REPO_NAME: " >> $testroot/stdout.expected
504 printf "${GOTD_DEVUSER} changed refs/tags/1.0\r\n" \
505 >> $testroot/stdout.expected
506 printf "\r\n" >> $testroot/stdout.expected
507 printf "tag refs/tags/1.0\n" >> $testroot/stdout.expected
508 printf "from: $GOT_AUTHOR\n" >> $testroot/stdout.expected
509 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
510 printf "date: $d\n" >> $testroot/stdout.expected
511 printf "object: commit $commit_id\n" >> $testroot/stdout.expected
512 printf "messagelen: 9\n" >> $testroot/stdout.expected
513 printf " \n" >> $testroot/stdout.expected
514 printf " new tag\n \n" >> $testroot/stdout.expected
515 printf "\r\n" >> $testroot/stdout.expected
516 printf ".\r\n" >> $testroot/stdout.expected
517 printf "QUIT\r\n" >> $testroot/stdout.expected
519 grep -v ^Date $testroot/stdout > $testroot/stdout.filtered
520 cmp -s $testroot/stdout.expected $testroot/stdout.filtered
522 if [ $ret -ne 0 ]; then
523 diff -u $testroot/stdout.expected $testroot/stdout.filtered
524 test_done "$testroot" "$ret"
528 test_done "$testroot" "$ret"
532 run_test test_file_changed
533 run_test test_many_commits_not_summarized
534 run_test test_many_commits_summarized
535 run_test test_branch_created
536 run_test test_branch_removed
537 run_test test_tag_created
538 run_test test_tag_changed