Diff options
Diffstat (limited to '')
-rw-r--r--source/ui-empty.c21
-rwxr-xr-xtests/t0102-summary.sh29
2 files changed, 41 insertions, 9 deletions
diff --git a/source/ui-empty.c b/source/ui-empty.c
index deefc21..76b2697 100644
--- a/source/ui-empty.c
+++ b/source/ui-empty.c
@@ -11,8 +11,17 @@
#include "ui-empty.h"
#include "ui-shared.h"
+static int clone_urls_printed;
+
static void print_clone_url(const char *url)
{
+ // cgit_add_clone_urls may call back no times at all, so the table
+ // waits for a first url rather than being opened ahead of the walk.
+ if (clone_urls_printed++ == 0) {
+ html("<table class='list clone' aria-label='Clone urls'>\n<tbody class='clone'>\n");
+ html("<tr class='nohover'><th class='left' scope='col'>Clone</th></tr>\n");
+ }
+
cgit_print_clone_row(url, 0);
}
@@ -23,14 +32,8 @@ static void print_clone_url(const char *url)
void cgit_print_empty_repo(void)
{
cgit_print_error("Repository seems to be empty");
-
- // cgit_add_clone_urls draws on these two alone, so with neither set
- // the table below would be a Clone heading with no rows.
- if (!ctx.repo->clone_url && !ctx.cfg.clone_prefix)
- return;
-
- html("<table class='list clone' aria-label='Clone urls'>\n<tbody class='clone'>\n");
- html("<tr class='nohover'><th class='left' scope='col'>Clone</th></tr>\n");
+ clone_urls_printed = 0;
cgit_add_clone_urls(print_clone_url);
- html("</tbody>\n</table>\n");
+ if (clone_urls_printed)
+ html("</tbody>\n</table>\n");
}
diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh
index e95f270..7df18e4 100755
--- a/tests/t0102-summary.sh
+++ b/tests/t0102-summary.sh
@@ -51,6 +51,35 @@ test_expect_success 'an scp clone url row links to the http url' '
! grep "vcs-git. href=.git@" tmp
'
+# A repository can turn the global clone-url off with an empty one of its own.
+# Neither its summary nor the page an empty repository gets then draws a Clone
+# heading over no rows.
+test_expect_success 'an empty clone url draws no clone heading' '
+ git init -q --bare repos/empty.git &&
+ {
+ echo "virtual-root=/" &&
+ echo "cache-size=0" &&
+ echo "clone-url=https://example.org/\$CGIT_REPO_URL" &&
+ echo "repo.url=foo" &&
+ echo "repo.path=$PWD/repos/foo/.git" &&
+ echo "repo.clone-url=" &&
+ echo "repo.url=empty" &&
+ echo "repo.path=$PWD/repos/empty.git" &&
+ echo "repo.clone-url=" &&
+ echo "repo.url=cloned" &&
+ echo "repo.path=$PWD/repos/empty.git"
+ } >emptyrc &&
+ CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=foo" cgit >tmp &&
+ grep "commit 1" tmp &&
+ ! grep "Clone</th>" tmp &&
+ CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=empty" cgit >tmp &&
+ grep "Repository seems to be empty" tmp &&
+ ! grep "Clone</th>" tmp &&
+ CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=cloned" cgit >tmp &&
+ grep "Clone</th>" tmp &&
+ grep "https://example.org/cloned</a>" tmp
+'
+
# Prints how many columns each row of the page's list table spans, one row to
# a line, counting a cell without a colspan as one.
row_widths() {