Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Log the path of a repository that will not open
The 404 page names only the repository and nothing reached the log, so
a mistyped repo.path left no trace of the path cgit had tried.
| -rw-r--r-- | MANUAL.txt | 4 | |
| -rw-r--r-- | source/cgit.c | 9 | |
| -rwxr-xr-x | tests/t0205-config.sh | 14 |
3 files changed, 26 insertions, 1 deletion
@@ -703,7 +703,9 @@ repo.owner:: repo.path:: An absolute path to the repository directory. For non-bare repositories - this is the .git-directory. Default value: none. + this is the .git-directory. When cgit cannot open the path as a + repository, its pages answer 404 and the path is named in the error + log. Default value: none. repo.readme:: A path (relative to <repo.path>) which specifies a file to show as the diff --git a/source/cgit.c b/source/cgit.c index 0017d75..39e8ab8 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -1132,6 +1132,8 @@ static void prepare_repo_env(struct cgit_repo *repo) static void open_repo(int *nongit, int *err) { + static int reported; + // A repository configured without a path has nothing to open. if (!ctx.repo->path) { *nongit = 1; @@ -1143,6 +1145,13 @@ static void open_repo(int *nongit, int *err) errno = 0; setup_git_directory_gently(the_repository, nongit); *err = errno; + // The error page names the repository alone, so the path goes to the + // log, and only once, since a failed cache fill renders a page again. + if (*nongit && !reported) { + reported = 1; + fprintf(stderr, "[cgit] Unable to open repository %s at %s: %s\n", ctx.repo->url, + ctx.repo->path, *err ? strerror(*err) : "Not a valid git repository"); + } // Notes come out of the object store, which a repository that failed // to open has none of. The commit and log pages always ask for them, // so they are set up either way, but a default ref that names no tree diff --git a/tests/t0205-config.sh b/tests/t0205-config.sh index 3b892e9..5044148 100755 --- a/tests/t0205-config.sh +++ b/tests/t0205-config.sh @@ -179,4 +179,18 @@ test_expect_success 'a word in a scanned git config is reported' ' grep "Reading hide=true in $PWD/wordscan/foo.git/config line $line as 0, since it is not a whole number" err ' +# The error page names the repository alone, so the log gets the path that +# would not open, once for the request. +test_expect_success 'a repository that will not open is logged with its path' ' + cgit_rc gonerc "url=gone/log/" >tmp 2>err && + grep "^Status: 404 Not Found" tmp && + grep "Unable to open repository gone at $PWD/no/such/repo/.git: No such file or directory" err && + test_line_count = 1 err && + mkdir not-a-repo && + cgitrc_repo notreporc notrepo "repo.path=$PWD/not-a-repo" && + cgit_rc notreporc "url=notrepo/" >tmp 2>err && + grep "^Status: 404 Not Found" tmp && + grep "Unable to open repository notrepo at $PWD/not-a-repo: " err +' + test_done |
