diff options
context:
space:
mode:
-rw-r--r--source/cgit.c14
-rwxr-xr-xtests/t0205-config.sh23
2 files changed, 29 insertions, 8 deletions
diff --git a/source/cgit.c b/source/cgit.c
index eb13709..5b26137 100644
--- a/source/cgit.c
+++ b/source/cgit.c
@@ -1033,7 +1033,10 @@ static void prepare_repo_env(int *nongit)
setenv("GIT_DIR", ctx.repo->path, 1);
setup_git_directory_gently(the_repository, nongit);
- load_display_notes(NULL);
+ // Notes come out of the object store, which a repository that failed
+ // to open has none of.
+ if (!*nongit)
+ load_display_notes(NULL);
}
/*
@@ -1050,11 +1053,10 @@ static int prepare_repo_cmd(int nongit)
err = errno;
ctx.page.title = cgit_fmtalloc("%s - %s", ctx.cfg.root_title, "config error");
ctx.repo = NULL;
- cgit_print_http_headers();
- cgit_print_docstart();
- cgit_print_pageheader();
- cgit_print_error("Failed to open %s: %s", name, err ? strerror(err) : "Not a valid git repository");
- cgit_print_docend();
+ cgit_print_error_page(
+ 404, "Not Found", "Failed to open %s: %s", name,
+ err ? strerror(err) : "Not a valid git repository"
+ );
return 1;
}
ctx.page.title = cgit_fmtalloc("%s - %s", ctx.repo->name, ctx.repo->desc);
diff --git a/tests/t0205-config.sh b/tests/t0205-config.sh
index 1a4f5d0..26231af 100755
--- a/tests/t0205-config.sh
+++ b/tests/t0205-config.sh
@@ -3,8 +3,9 @@
# Checks what the configuration parser reports on stderr. A key it does not
# know, a repo key before any repository and a filter set by a scanned
# repository without trust-scan-filters are each ignored with a warning naming
-# the key, a repo filter in the main cgitrc passes without one, and a config
-# cgit fully understands stays silent.
+# the key, a repo filter in the main cgitrc passes without one, a repository
+# whose path is missing answers 404 on every page, and a config cgit fully
+# understands stays silent.
test_description='Check configuration diagnostics'
. ./setup.sh
@@ -70,6 +71,24 @@ test_expect_success 'a repo filter in the main cgitrc needs no flag' '
! grep "about-filter" err
'
+test_expect_success 'a repository whose path is missing answers 404' '
+ {
+ echo "virtual-root=/" &&
+ echo "cache-size=1021" &&
+ echo "cache-root=$PWD/gone-cache" &&
+ echo "repo.url=gone" &&
+ echo "repo.path=$PWD/no/such/repo/.git"
+ } >gonerc &&
+ mkdir -p gone-cache &&
+ for page in "" log/ commit/ "tag/&h=x" atom/ plain/f
+ do
+ CGIT_CONFIG="$PWD/gonerc" QUERY_STRING="url=gone/$page" cgit >tmp 2>err &&
+ grep "^Status: 404 Not Found" tmp &&
+ grep "Failed to open gone: No such file or directory" tmp || return 1
+ done &&
+ test -z "$(ls gone-cache)"
+'
+
test_expect_success 'a fully understood config stays silent' '
cgit_url "foo/" >tmp 2>err &&
grep "Status: 200" tmp &&