From bdd3af7c6ab23ecb8fc377b3404282793eb9c802 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sun, 1 Nov 2026 16:10:49 -1000 Subject: Say when nothing matches a mistyped url --- source/ui-repolist.c | 24 +++++++++++++++++++++++- tests/t0101-index.sh | 11 +++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/source/ui-repolist.c b/source/ui-repolist.c index 87abf0b..3eb9375 100644 --- a/source/ui-repolist.c +++ b/source/ui-repolist.c @@ -169,6 +169,23 @@ static int any_repos_visible(void) return 0; } +/* + * Whether any listed repository lies under the url the request carried, + * whatever the search terms. + */ +static int any_repos_under_url(void) +{ + int i; + + for (i = 0; i < cgit_repolist.count; i++) { + struct cgit_repo *repo = &cgit_repolist.repos[i]; + + if (!repo->hide && !repo->ignore && matches_url(repo)) + return 1; + } + return 0; +} + /* * currenturl is passed in because it is the same for every heading and every * row, and working it out here would mean an allocation and a free per cell. @@ -398,7 +415,12 @@ void cgit_print_repolist(void) cgit_read_repo_desc(&cgit_repolist.repos[i]); if (!any_repos_visible()) { - cgit_print_error_page(404, "Not Found", "No repositories found"); + // A url naming no repository or page lands here, as a prefix + // that no repository's url starts with. + if (ctx.qry.url && *ctx.qry.url && !any_repos_under_url()) + cgit_print_error_page(404, "Not Found", "Nothing matches this url"); + else + cgit_print_error_page(404, "Not Found", "No repositories found"); return; } diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh index 0953b8d..fcf873b 100755 --- a/tests/t0101-index.sh +++ b/tests/t0101-index.sh @@ -53,6 +53,17 @@ test_expect_success 'a cut description keeps whole characters' ' grep ">日本語\.\.\." tmp ' +# A url naming no repository falls through to the index as a prefix that +# matches none, which is not the same as a search finding nothing. +test_expect_success 'a url matching no repository says so' ' + cgit_url "nonexistent/tree/" >tmp && + grep "^Status: 404" tmp && + grep "
Nothing matches this url
" tmp && + cgit_query "q=nonexistent" >tmp && + grep "^Status: 404" tmp && + grep "
No repositories found
" tmp +' + # The index sorts by a column only when asked, which nothing else exercises. test_expect_success 'the index sorts by a column on request' ' cgit_query "s=name" >tmp && -- cgit 2.12.1