portable: handle gotd/auth
[got-portable.git] / regress / tog / log.sh
blobc9e0f9386c09837c4f369034ac78348d9c7f2abd
1 #!/bin/sh
3 # Copyright (c) 2023 Mark Jamsek <mark@jamsek.dev>
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 . ./common.sh
19 test_log_hsplit_diff()
21 test_init log_hsplit_diff
23 local head_id=`git_show_head $testroot/repo`
24 local author_time=`git_show_author_time $testroot/repo`
25 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
26 local ymd=`date -u -r $author_time +"%G-%m-%d"`
28 cat <<EOF >$TOG_TEST_SCRIPT
29 KEY_ENTER open diff view of selected commit
30 S toggle horizontal split
31 SCREENDUMP
32 EOF
34 cat <<EOF >$testroot/view.expected
35 commit $head_id [1/1] master
36 $ymd flan_hacker [master] adding the test tree
41 --------------------------------------------------------------------------------
42 [1/40] diff /dev/null $head_id
43 commit $head_id (master)
44 from: Flan Hacker <flan_hacker@openbsd.org>
45 date: $date
47 adding the test tree
49 A alpha | 1+ 0-
50 A beta | 1+ 0-
51 A epsilon/zeta | 1+ 0-
52 A gamma/delta | 1+ 0-
54 4 files changed, 4 insertions(+), 0 deletions(-)
56 commit - /dev/null
57 commit + $head_id
58 blob - /dev/null
59 EOF
61 cd $testroot/repo && tog log
62 cmp -s $testroot/view.expected $testroot/view
63 ret=$?
64 if [ $ret -ne 0 ]; then
65 diff -u $testroot/view.expected $testroot/view
66 test_done "$testroot" "$ret"
67 return 1
70 test_done "$testroot" "$ret"
73 test_log_vsplit_diff()
75 # make screen wide enough for vsplit
76 test_init log_vsplit_diff 142
78 local head_id=`git_show_head $testroot/repo`
79 local author_time=`git_show_author_time $testroot/repo`
80 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
81 local ymd=`date -u -r $author_time +"%G-%m-%d"`
82 local blobid_alpha=`get_blob_id $testroot/repo "" alpha`
83 local blobid_beta=`get_blob_id $testroot/repo "" beta`
85 cat <<EOF >$TOG_TEST_SCRIPT
86 KEY_ENTER open diff view of selected commit in vertical split
87 SCREENDUMP
88 EOF
90 cat <<EOF >$testroot/view.expected
91 commit $head_id [1/1] master |[1/40] diff /dev/null $head_id
92 $ymd flan_hacker [master] adding the test tree |commit $head_id (master)
93 |from: Flan Hacker <flan_hacker@openbsd.org>
94 |date: $date
96 |adding the test tree
98 |A alpha | 1+ 0-
99 |A beta | 1+ 0-
100 |A epsilon/zeta | 1+ 0-
101 |A gamma/delta | 1+ 0-
103 |4 files changed, 4 insertions(+), 0 deletions(-)
105 |commit - /dev/null
106 |commit + $head_id
107 |blob - /dev/null
108 |blob + $blobid_alpha (mode 644)
109 |--- /dev/null
110 |+++ alpha
111 |@@ -0,0 +1 @@
112 |+alpha
113 |blob - /dev/null
114 |blob + $blobid_beta (mode 644)
117 cd $testroot/repo && tog log
118 cmp -s $testroot/view.expected $testroot/view
119 ret=$?
120 if [ $ret -ne 0 ]; then
121 diff -u $testroot/view.expected $testroot/view
122 test_done "$testroot" "$ret"
123 return 1
126 test_done "$testroot" "$ret"
129 test_log_show_author()
131 # make view wide enough to show id
132 test_init log_show_author 120 4
134 local head_id=`git_show_head $testroot/repo`
135 local author_time=`git_show_author_time $testroot/repo`
136 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
137 local ymd=`date -u -r $author_time +"%G-%m-%d"`
138 local head_id_len8=`trim_obj_id 32 $head_id`
140 echo "mod alpha" > $testroot/repo/alpha
141 cd $testroot/repo && git add .
142 cd $testroot/repo && \
143 git commit --author "Johnny Cash <john@cash.net>" -m author > \
144 /dev/null
146 local commit1=`git_show_head $testroot/repo`
147 local id1_len8=`trim_obj_id 32 $commit1`
149 cat <<EOF >$TOG_TEST_SCRIPT
150 @ toggle show author
151 SCREENDUMP
154 cat <<EOF >$testroot/view.expected
155 commit $commit1 [1/2] master
156 $ymd $id1_len8 john [master] author
157 $ymd $head_id_len8 flan_hacker adding the test tree
158 :show commit author
161 cd $testroot/repo && tog log
162 cmp -s $testroot/view.expected $testroot/view
163 ret=$?
164 if [ $ret -ne 0 ]; then
165 diff -u $testroot/view.expected $testroot/view
166 test_done "$testroot" "$ret"
167 return 1
170 test_done "$testroot" "$ret"
173 test_log_scroll_right()
175 test_init log_scroll_right 80 3
177 local head_id=`git_show_head $testroot/repo`
178 local author_time=`git_show_author_time $testroot/repo`
179 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
180 local ymd=`date -u -r $author_time +"%G-%m-%d"`
181 local msg="scroll this log message to the right four characters"
182 local scrolled_msg="ter] scroll this log message to the right four character"
184 echo "mod alpha" > $testroot/repo/alpha
185 cd $testroot/repo && git add . && git commit -m "$msg" > /dev/null
187 local commit1=`git_show_head $testroot/repo`
189 cat <<EOF >$TOG_TEST_SCRIPT
190 l scroll right
191 l scroll right
192 SCREENDUMP
195 cat <<EOF >$testroot/view.expected
196 commit $commit1 [1/2] master
197 $ymd flan_hacker $scrolled_msg
198 $ymd flan_hacker ng the test tree
201 cd $testroot/repo && tog log
202 cmp -s $testroot/view.expected $testroot/view
203 ret=$?
204 if [ $ret -ne 0 ]; then
205 diff -u $testroot/view.expected $testroot/view
206 test_done "$testroot" "$ret"
207 return 1
210 test_done "$testroot" "$ret"
213 test_log_hsplit_ref()
215 test_init log_hsplit_ref 80 10
217 local head_id=`git_show_head $testroot/repo`
218 local author_time=`git_show_author_time $testroot/repo`
219 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
220 local ymd=`date -u -r $author_time +"%G-%m-%d"`
222 cat <<EOF >$TOG_TEST_SCRIPT
223 R open ref view
224 S toggle horizontal split
225 - reduce size of ref view split
226 SCREENDUMP
229 cat <<EOF >$testroot/view.expected
230 commit $head_id [1/1] master
231 $ymd flan_hacker [master] adding the test tree
233 --------------------------------------------------------------------------------
234 references [1/2]
235 HEAD -> refs/heads/master
236 refs/heads/master
242 cd $testroot/repo && tog log
243 cmp -s $testroot/view.expected $testroot/view
244 ret=$?
245 if [ $ret -ne 0 ]; then
246 diff -u $testroot/view.expected $testroot/view
247 test_done "$testroot" "$ret"
248 return 1
251 test_done "$testroot" "$ret"
254 test_log_hsplit_tree()
256 test_init log_hsplit_tree 80 10
258 local head_id=`git_show_head $testroot/repo`
259 local author_time=`git_show_author_time $testroot/repo`
260 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
261 local ymd=`date -u -r $author_time +"%G-%m-%d"`
263 cat <<EOF >$TOG_TEST_SCRIPT
264 T open tree view
265 S toggle horizontal split
266 j move selection cursor down one entry to "beta"
267 - reduce size of tree view split
268 SCREENDUMP
271 cat <<EOF >$testroot/view.expected
272 commit $head_id [1/1] master
273 $ymd flan_hacker [master] adding the test tree
275 --------------------------------------------------------------------------------
276 commit $head_id
277 [2/4] /
279 alpha
280 beta
281 epsilon/
284 cd $testroot/repo && tog log
285 cmp -s $testroot/view.expected $testroot/view
286 ret=$?
287 if [ $ret -ne 0 ]; then
288 diff -u $testroot/view.expected $testroot/view
289 test_done "$testroot" "$ret"
290 return 1
293 test_done "$testroot" "$ret"
296 test_log_logmsg_widechar()
298 # make view wide enough to fit logmsg line length
299 # but short enough so long diff lines are truncated
300 test_init log_logmsg_widechar 182 30
301 widechar_commit $testroot/repo
303 local head_id=`git_show_head $testroot/repo`
304 local author_time=`git_show_author_time $testroot/repo`
305 local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
306 local commit1=`git_show_parent_commit $testroot/repo`
307 local blobid=`get_blob_id $testroot/repo "" $(widechar_filename)`
309 cat <<EOF >$TOG_TEST_SCRIPT
310 KEY_ENTER open selected commit in diff view
311 F toggle fullscreen
312 SCREENDUMP
315 cat <<EOF >$testroot/view.expected
316 [1/26] diff $commit1 $head_id
317 commit $head_id (master)
318 from: Flan Hacker <flan_hacker@openbsd.org>
319 date: $date
321 $(widechar_logmsg)
323 A $(widechar_filename) | 5+ 0-
325 1 file changed, 5 insertions(+), 0 deletions(-)
327 commit - $commit1
328 commit + $head_id
329 blob - /dev/null
330 blob + $blobid (mode 644)
331 --- /dev/null
332 +++ $(widechar_filename)
333 @@ -0,0 +1,5 @@
334 +ウィリアム・ユワート・グラッドストン(英語: William Ewart Gladstone PC FRS FSS、1809年12月29日 - 1898年5月19日)は、イギリスの政治家。
336 +ヴィクトリア朝中期から後期にかけて、自由党を指導して、4度にわたり首相を務めた。
338 +生涯を通じて敬虔なイングランド国教会の信徒であり、キリスト教の精神を政治に反映させることを目指した。多くの自由主義改革を行い、帝国主義にも批判的であった。好敵手である保守党党首ベン
342 (END)
345 cd $testroot/repo && tog log
346 cmp -s $testroot/view.expected $testroot/view
347 ret=$?
348 if [ $ret -ne 0 ]; then
349 diff -u $testroot/view.expected $testroot/view
350 test_done "$testroot" "$ret"
351 return 1
354 test_done "$testroot" "$ret"
357 test_log_commit_keywords()
359 test_init log_commit_keywords 120 10
360 local repo="$testroot/repo"
361 local wt="$testroot/wt"
362 local id=$(git_show_head "$repo")
363 local author_time=$(git_show_author_time "$repo")
364 local ymd=$(date -u -r $author_time +"%G-%m-%d")
366 set -- "$id"
368 got checkout "$repo" "$wt" > /dev/null
369 ret=$?
370 if [ $ret -ne 0 ]; then
371 echo "got checkout failed unexpectedly"
372 test_done "$testroot" "$ret"
373 return 1
376 # move into the work tree (test is run in a subshell)
377 cd "$wt"
378 echo -n > alpha
380 for i in $(seq 8); do
381 echo "alpha $i" >> alpha
383 got ci -m "commit $i" > /dev/null
384 ret=$?
385 if [ $ret -ne 0 ]; then
386 echo "commit failed unexpectedly" >&2
387 test_done "$testroot" "$ret"
388 return 1
391 id=$(git_show_head "$repo")
392 set -- "$@" "$id"
393 done
395 cat <<-EOF >$TOG_TEST_SCRIPT
396 WAIT_FOR_UI wait for log thread to finish
397 SCREENDUMP
400 cat <<-EOF >$testroot/view.expected
401 commit $(pop_idx 5 $@) [1/5]
402 $ymd $(trim_obj_id 32 $(pop_idx 5 $@)) flan_hacker commit 4
403 $ymd $(trim_obj_id 32 $(pop_idx 4 $@)) flan_hacker commit 3
404 $ymd $(trim_obj_id 32 $(pop_idx 3 $@)) flan_hacker commit 2
405 $ymd $(trim_obj_id 32 $(pop_idx 2 $@)) flan_hacker commit 1
406 $ymd $(trim_obj_id 32 $(pop_idx 1 $@)) flan_hacker adding the test tree
413 tog log -c:base:-4
414 cmp -s "$testroot/view.expected" "$testroot/view"
415 ret=$?
416 if [ $ret -ne 0 ]; then
417 diff -u "$testroot/view.expected" "$testroot/view"
418 test_done "$testroot" "$ret"
419 return 1
422 cat <<-EOF >$testroot/view.expected
423 commit $(pop_idx 7 $@) [1/7]
424 $ymd $(trim_obj_id 32 $(pop_idx 7 $@)) flan_hacker commit 6
425 $ymd $(trim_obj_id 32 $(pop_idx 6 $@)) flan_hacker commit 5
426 $ymd $(trim_obj_id 32 $(pop_idx 5 $@)) flan_hacker commit 4
427 $ymd $(trim_obj_id 32 $(pop_idx 4 $@)) flan_hacker commit 3
428 $ymd $(trim_obj_id 32 $(pop_idx 3 $@)) flan_hacker commit 2
429 $ymd $(trim_obj_id 32 $(pop_idx 2 $@)) flan_hacker commit 1
430 $ymd $(trim_obj_id 32 $(pop_idx 1 $@)) flan_hacker adding the test tree
435 tog log -r "$repo" -c:head:-2
436 cmp -s "$testroot/view.expected" "$testroot/view"
437 ret=$?
438 if [ $ret -ne 0 ]; then
439 diff -u "$testroot/view.expected" "$testroot/view"
440 test_done "$testroot" "$ret"
441 return 1
444 cat <<-EOF >$testroot/view.expected
445 commit $(pop_idx 5 $@) [1/5]
446 $ymd $(trim_obj_id 32 $(pop_idx 5 $@)) flan_hacker commit 4
447 $ymd $(trim_obj_id 32 $(pop_idx 4 $@)) flan_hacker commit 3
448 $ymd $(trim_obj_id 32 $(pop_idx 3 $@)) flan_hacker ~commit 2
449 $ymd $(trim_obj_id 32 $(pop_idx 2 $@)) flan_hacker commit 1
450 $ymd $(trim_obj_id 32 $(pop_idx 1 $@)) flan_hacker adding the test tree
457 got up -c:base:-6 > /dev/null
458 ret=$?
459 if [ $ret -ne 0 ]; then
460 echo "got update failed unexpectedly"
461 test_done "$testroot" "$ret"
462 return 1
465 tog log -c:base:+2
466 cmp -s "$testroot/view.expected" "$testroot/view"
467 ret=$?
468 if [ $ret -ne 0 ]; then
469 diff -u "$testroot/view.expected" "$testroot/view"
470 test_done "$testroot" "$ret"
471 return 1
474 cat <<-EOF >$testroot/view.expected
475 commit $(pop_idx 1 $@) [1/1]
476 $ymd $(trim_obj_id 32 $(pop_idx 1 $@)) flan_hacker adding the test tree
487 tog log -c:base:-99
488 cmp -s "$testroot/view.expected" "$testroot/view"
489 ret=$?
490 if [ $ret -ne 0 ]; then
491 diff -u "$testroot/view.expected" "$testroot/view"
492 test_done "$testroot" "$ret"
493 return 1
496 test_done "$testroot" "$ret"
499 test_log_show_base_commit()
501 # make view wide enough to show full headline
502 test_init log_show_base_commit 80 3
503 local repo="$testroot/repo"
504 local id=$(git_show_head "$repo")
506 echo "alpha" >> "$repo/alpha"
507 git_commit "$repo" -m "base commit"
509 got checkout "$repo" "$testroot/wt" > /dev/null
510 ret=$?
511 if [ $ret -ne 0 ]; then
512 echo "got checkout failed unexpectedly"
513 test_done "$testroot" "$ret"
514 return 1
517 # move into the work tree (test is run in a subshell)
518 cd "$testroot/wt"
520 local head_id=$(git_show_head "$repo")
521 local author_time=$(git_show_author_time "$repo")
522 local ymd=$(date -u -r "$author_time" +"%G-%m-%d")
524 # check up-to-date base commit marker prefixes base commit log message
525 cat <<-EOF >$TOG_TEST_SCRIPT
526 WAIT_FOR_UI wait for log thread to finish
527 SCREENDUMP
530 cat <<-EOF >$testroot/view.expected
531 commit $head_id [1/2] master
532 $ymd flan_hacker *[master] base commit
533 $ymd flan_hacker adding the test tree
536 tog log
537 cmp -s "$testroot/view.expected" "$testroot/view"
538 ret=$?
539 if [ $ret -ne 0 ]; then
540 diff -u "$testroot/view.expected" "$testroot/view"
541 test_done "$testroot" "$ret"
542 return 1
545 # check marker is not drawn when not in a work tree
546 cat <<-EOF >$testroot/view.expected
547 commit $head_id [1/2] master
548 $ymd flan_hacker [master] base commit
549 $ymd flan_hacker adding the test tree
552 tog log -r "$repo"
553 cmp -s "$testroot/view.expected" "$testroot/view"
554 ret=$?
555 if [ $ret -ne 0 ]; then
556 diff -u "$testroot/view.expected" "$testroot/view"
557 test_done "$testroot" "$ret"
558 return 1
561 # check out-of-date marker is shown with a mixed-commit tree
562 echo "mixed" > alpha
563 got commit -m "new base mixed-commit" > /dev/null
564 head_id=$(git_show_head "$repo")
566 cat <<-EOF >$TOG_TEST_SCRIPT
567 WAIT_FOR_UI wait for log thread to finish
568 SCREENDUMP
571 cat <<-EOF >$testroot/view.expected
572 commit $head_id [1/3] master
573 $ymd flan_hacker ~[master] new base mixed-commit
574 $ymd flan_hacker base commit
577 tog log
578 cmp -s "$testroot/view.expected" "$testroot/view"
579 ret=$?
580 if [ $ret -ne 0 ]; then
581 diff -u "$testroot/view.expected" "$testroot/view"
582 test_done "$testroot" "$ret"
583 return 1
586 test_done "$testroot" "$ret"
589 test_parseargs "$@"
590 run_test test_log_hsplit_diff
591 run_test test_log_vsplit_diff
592 run_test test_log_show_author
593 run_test test_log_scroll_right
594 run_test test_log_hsplit_ref
595 run_test test_log_hsplit_tree
596 run_test test_log_logmsg_widechar
597 run_test test_log_commit_keywords
598 run_test test_log_show_base_commit