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: > > Git allows tags to point to commits, trees, blobs, and even other tags. > > Currently, selecting a tag that points to anything but a commit causes a > > fatal error in tog's ref view. This change instead draws a message to > > the status line, and also enables selecting nested tags that resolve to > > a commit. > > > > I've run out of time tonight to write a test case--I'll do this after > > zzz--but to test the nested tag to commit case: > > > > # make tag to base commit > > $ got tag -m "test tag" testtag > > # make tag to previous tag > > $ git tag -a nestedtag -m "nested tag" testtag > > > > then invoke `tog ref` without this diff and select refs/tags/nestedtag: > > > > tog: wrong type of object > > > > With this diff, the log view will instead open starting traversal from > > the tagged commit in the first tag (i.e., testtag). > > > > To test a tag to a blob or tree object, you need to use git to create > > the tag as this is not allowed by design in got: > > > > $ git tag tag2blob $blobid > > > > Selecting the refs/tags/tag2blob entry in tog's ref view without this > > diff causes tog to exit with a fatal error. With this diff, a message is > > drawn to the status line: "commit reference required". This is also a > > good test case for why the wtimeout(3) fix is needed: without that fix, > > the message is not visible when selecting tag2blob after entering a > > compound key (e.g., 2j). > > Please ignore the previous diff: in current HEAD, there's a leak in the > resolve_reflist_entry() error path, which the diff didn't fix. I'd like > to address that too. > > 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. The tests in the first diff should run with no failures with a tog binary built from current HEAD. The tests in the second diff should both fail when run against a tog binary built from current HEAD but should pass when the binary is built with the previous diff applied. ----------------------------------------------- commit eaf43528a3ac966744d9a1e63f3847aaaa9ddf34 from: Mark Jamsek <mark@jamsek.dev> date: Thu Dec 26 13:36:12 2024 UTC regress/tog: add basic ref view tests A regress/tog/ref.sh | 142+ 0- 1 file changed, 142 insertions(+), 0 deletions(-) diff e3559165ad42fbad6553b3af69f97019a173345b eaf43528a3ac966744d9a1e63f3847aaaa9ddf34 commit - e3559165ad42fbad6553b3af69f97019a173345b commit + eaf43528a3ac966744d9a1e63f3847aaaa9ddf34 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 7ffa13b2d44df012d7471130eaf715ced4009efb (main) from: Mark Jamsek <mark@jamsek.dev> date: Thu Dec 26 14:06:18 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(-) diff eaf43528a3ac966744d9a1e63f3847aaaa9ddf34 7ffa13b2d44df012d7471130eaf715ced4009efb commit - eaf43528a3ac966744d9a1e63f3847aaaa9ddf34 commit + 7ffa13b2d44df012d7471130eaf715ced4009efb 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