Download raw body.
tog: make ref view selection of non-commit tags non-fatal
Mark Jamsek <mark@jamsek.com> wrote: > Mark Jamsek <mark@jamsek.com> wrote: > > Mark Jamsek <mark@jamsek.com> wrote: > > > > As such, below are two diffs: the first plugs the object id leak that > > happens when the object id does not reference a commit, and when the > > call to got_object_open_as_tag() fails. The second is the previous diff > > slightly modified, which adds the ability to select from the ref view > > nested tags that resolve to commits, and makes selection of tags that > > point to non-commit objects non-fatal. > > > > Regress still to come :) > > Here are two regress diffs: the first adds some long overdue basic ref > view tests; and the second adds two tests covering the previous diff > that adds support for nested tags resolving to commit objects, and fixes > the fatal error when selecting tags that point to non-commit objects. Updated the first diff to add the new ref view regress target to the makefile. Second diff is unchanged but added below for convenience. commit c15c2a98804357ef76ce8cacf21c2a3d97902900 from: Mark Jamsek <mark@jamsek.dev> date: Fri Dec 27 13:26:14 2024 UTC regress/tog: add basic ref view tests M regress/tog/Makefile | 4+ 1- A regress/tog/ref.sh | 142+ 0- 2 files changed, 146 insertions(+), 1 deletion(-) commit - 039128b92a909f17b668890dc4429d265ba86033 commit + c15c2a98804357ef76ce8cacf21c2a3d97902900 blob - 03259147951700e81a8aef5359da33d889dc0a6e blob + d38fcd2cd55b679e9afe63b68087e93be32f4dcc --- regress/tog/Makefile +++ regress/tog/Makefile @@ -1,4 +1,4 @@ -REGRESS_TARGETS=log diff blame tree +REGRESS_TARGETS=log diff blame tree ref NOOBJ=Yes GOT_TEST_ROOT=/tmp @@ -15,4 +15,7 @@ blame: tree: ./tree.sh -q -r "$(GOT_TEST_ROOT)" +ref: + ./ref.sh -q -r "$(GOT_TEST_ROOT)" + .include <bsd.regress.mk> blob - /dev/null blob + b6c1fc12ce3fdf5a04a5b37782be5523ea18f036 (mode 755) --- /dev/null +++ regress/tog/ref.sh @@ -0,0 +1,142 @@ +#!/bin/sh +# +# Copyright (c) 2024 Mark Jamsek <mark@jamsek.dev> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +. ./common.sh + +test_ref_basic() +{ + test_init ref_basic 32 3 + + cat <<-EOF >$TOG_TEST_SCRIPT + SCREENDUMP + EOF + + cat <<-EOF >$testroot/view.expected + references [1/2] + HEAD -> refs/heads/master + refs/heads/master + EOF + + cd $testroot/repo && tog ref + cmp -s $testroot/view.expected $testroot/view + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/view.expected $testroot/view + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + +test_ref_id_keymap() +{ + test_init ref_id_keymap 83 3 + + local id=$(git_show_head $testroot/repo) + + cat <<-EOF >$TOG_TEST_SCRIPT + i # toggle IDs + SCREENDUMP + EOF + + cat <<-EOF >$testroot/view.expected + references [1/2] + HEAD -> refs/heads/master + refs/heads/master: $id + EOF + + cd $testroot/repo && tog ref + cmp -s $testroot/view.expected $testroot/view + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/view.expected $testroot/view + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + +test_ref_date_keymap() +{ + test_init ref_date_keymap 40 3 + + local author_time=$(git_show_author_time $testroot/repo) + local date=$(date -u -r $author_time +"%a %b %e %X %Y UTC") + local ymd=$(date -u -r $author_time +"%F") + + cat <<-EOF >$TOG_TEST_SCRIPT + m # toggle last modified date + SCREENDUMP + EOF + + cat <<-EOF >$testroot/view.expected + references [1/2] + $ymd HEAD -> refs/heads/master + $ymd refs/heads/master + EOF + + cd $testroot/repo && tog ref + cmp -s $testroot/view.expected $testroot/view + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/view.expected $testroot/view + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + +test_ref_id_date_keymaps() +{ + test_init ref_id_date_keymaps 95 3 + + local author_time=$(git_show_author_time $testroot/repo) + local date=$(date -u -r $author_time +"%a %b %e %X %Y UTC") + local ymd=$(date -u -r $author_time +"%F") + local id=$(git_show_head $testroot/repo) + + cat <<-EOF >$TOG_TEST_SCRIPT + i # toggle IDs + m # toggle last modified date + SCREENDUMP + EOF + + cat <<-EOF >$testroot/view.expected + references [1/2] + $ymd HEAD -> refs/heads/master + $ymd refs/heads/master: $id + EOF + + cd $testroot/repo && tog ref + cmp -s $testroot/view.expected $testroot/view + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/view.expected $testroot/view + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + +test_parseargs "$@" +run_test test_ref_basic +run_test test_ref_id_keymap +run_test test_ref_date_keymap +run_test test_ref_id_date_keymaps commit 6c185310f28c4ac8a4ed01a7e6f2991529017b28 from: Mark Jamsek <mark@jamsek.dev> date: Fri Dec 27 13:26:14 2024 UTC regress/tog: ref view coverage of tag references Test for the error case when selecting tags that point to non-commit objects. And test the valid case of selecting nested tags that resolve to commit objects. M regress/tog/ref.sh | 98+ 0- 1 file changed, 98 insertions(+), 0 deletions(-) commit - c15c2a98804357ef76ce8cacf21c2a3d97902900 commit + 6c185310f28c4ac8a4ed01a7e6f2991529017b28 blob - b6c1fc12ce3fdf5a04a5b37782be5523ea18f036 blob + 9ab0f1ee21ad588017f9903b260fe6c4c1dd934c --- regress/tog/ref.sh +++ regress/tog/ref.sh @@ -135,8 +135,106 @@ test_ref_id_date_keymaps() test_done "$testroot" "$ret" } +test_ref_nested_tag_to_commit() +{ + test_init ref_nested_tag_to_commit 142 5 + + local author_time=$(git_show_author_time $testroot/repo) + local date=$(date -u -r $author_time +"%a %b %e %X %Y UTC") + local ymd=$(date -u -r $author_time +"%F") + local id=$(git_show_head $testroot/repo) + + cd $testroot/repo + + git tag -a tagref -m "tag to commit" > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "git tag failed unexpectedly" + test_done "$testroot" "$ret" + return 1 + fi + + git tag -a nestedtag -m "nested tag" tagref > /dev/null 2>&1 + ret=$? + if [ $ret -ne 0 ]; then + echo "git tag failed unexpectedly" + test_done "$testroot" "$ret" + return 1 + fi + + cat <<-EOF >$TOG_TEST_SCRIPT + 2j # select nested tag ref + KEY_ENTER # open log view + 35+ # grow log view vsplit + SCREENDUMP + EOF + + cat <<EOF >$testroot/view.expected +references [3/4] |commit $id [1/1] master, tags/tagref +HEAD -> refs/heads/master |$ymd flan_hacker [master, tags/tagref] adding the test tree +refs/heads/master | +refs/tags/nestedtag | +refs/tags/tagref | +EOF + + cd $testroot/repo && tog ref + cmp -s $testroot/view.expected $testroot/view + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/view.expected $testroot/view + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + +test_ref_non_commit_tag() +{ + test_init ref_non_commit_tag 32 5 + + local blobid_alpha=$(get_blob_id $testroot/repo "" alpha) + + cd $testroot/repo + + git tag blobtag $blobid_alpha > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "git tag failed unexpectedly" + test_done "$testroot" "$ret" + return 1 + fi + + cat <<-EOF >$TOG_TEST_SCRIPT + 2j # select tag to blob entry + KEY_ENTER + SCREENDUMP + EOF + + cat <<-EOF >$testroot/view.expected + references [3/3] + HEAD -> refs/heads/master + refs/heads/master + refs/tags/blobtag + :commit reference required + EOF + + cd $testroot/repo && tog ref + cmp -s $testroot/view.expected $testroot/view + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/view.expected $testroot/view + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + test_parseargs "$@" run_test test_ref_basic run_test test_ref_id_keymap run_test test_ref_date_keymap run_test test_ref_id_date_keymaps +run_test test_ref_nested_tag_to_commit +run_test test_ref_non_commit_tag -- Mark Jamsek <https://bsdbox.org> GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68
tog: make ref view selection of non-commit tags non-fatal