From 2c2d007f33b8bcba23c30057fd8f1224b1b16f1d Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 17 Oct 2026 12:53:17 -1000 Subject: Offer tag snapshots only for a tagged commit The tag page offered a download for a tag of a tree or a blob, which only led to a "Not a commit" page. The refs listing already checks. --- source/ui-tag.c | 14 +++++++++----- tests/t0113-tag.sh | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/source/ui-tag.c b/source/ui-tag.c index 559cb54..5fa8a17 100644 --- a/source/ui-tag.c +++ b/source/ui-tag.c @@ -57,8 +57,14 @@ static void print_object_row(struct object *obj) html("\n"); } -static void print_download_row(const char *revname) +/* + * A snapshot is cut from a commit, so a tag of anything else offers none, as in + * the refs listing. + */ +static void print_download_row(const char *revname, const struct object *obj) { + if (!ctx.repo->snapshots || obj->type != OBJ_COMMIT) + return; html("download"); cgit_print_snapshot_links(ctx.repo, revname, "
"); html("\n"); @@ -111,8 +117,7 @@ static void print_annotated_tag(const char *revname, const struct object_id *oid if (info->tagger) print_tagger_row(info); print_object_row(tag->tagged); - if (ctx.repo->snapshots) - print_download_row(revname); + print_download_row(revname, tag->tagged); html("\n"); print_message(info->msg); cgit_print_layout_end(); @@ -125,8 +130,7 @@ static void print_lightweight_tag(const char *revname, struct object *obj) html("\n"); print_name_row(revname, NULL); print_object_row(obj); - if (ctx.repo->snapshots) - print_download_row(revname); + print_download_row(revname, obj); html("
\n"); cgit_print_layout_end(); } diff --git a/tests/t0113-tag.sh b/tests/t0113-tag.sh index 2c9dc25..ff50f90 100755 --- a/tests/t0113-tag.sh +++ b/tests/t0113-tag.sh @@ -45,4 +45,18 @@ test_expect_success 'a lightweight tag gets the shorter table' ' ! grep "tagged by" tmp ' +# A snapshot is cut from a commit, so a tag of a tree or a blob offers none. +test_expect_success 'a tag of anything but a commit offers no download' ' + git -C repos/foo tag -a -m "a tree" tree-tag HEAD^{tree} && + git -C repos/foo tag blob-tag HEAD:file-1 && + cgit_url "foo/tag/&h=tree-tag" >tmp && + grep "tagged object" tmp && + ! grep ">download<" tmp && + cgit_url "foo/tag/&h=blob-tag" >tmp && + grep "tagged object" tmp && + ! grep ">download<" tmp && + cgit_url "foo/tag/&h=v1.0" >tmp && + grep ">download<" tmp +' + test_done -- cgit