diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Report ignored config keys on stderr
| -rw-r--r-- | source/cgit.c | 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -rwxr-xr-x | tests/t0205-config.sh | 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 files changed, 65 insertions, 4 deletions
diff --git a/source/cgit.c b/source/cgit.c index 23521f5..730e2c6 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -695,6 +695,10 @@ static void apply_config(const char *name, const char *value) add_mimetype(arg, value); else if (!strcmp(name, "include")) config_file_parse(cgit_expand_macros(value), apply_config); + else if (skip_prefix(name, "repo.", &arg)) + fprintf(stderr, "[cgit] Ignoring %s before any repo.url\n", name); + else + fprintf(stderr, "[cgit] Unknown config key: %s\n", name); } /* @@ -1223,16 +1227,20 @@ void cgit_repo_config(struct cgit_repo *repo, const char *name, const char *valu repo->hide = atoi(value); else if (!strcmp(name, "ignore")) repo->ignore = atoi(value); - else if (ctx.cfg.enable_filter_overrides) { - if (!strcmp(name, "about-filter")) + else if (!strcmp(name, "about-filter") || !strcmp(name, "commit-filter") || + !strcmp(name, "source-filter") || !strcmp(name, "email-filter")) { + if (!ctx.cfg.enable_filter_overrides) + fprintf(stderr, "[cgit] Ignoring repo %s: enable-filter-overrides is not set\n", name); + else if (!strcmp(name, "about-filter")) repo->about_filter = cgit_new_filter(value, ABOUT); else if (!strcmp(name, "commit-filter")) repo->commit_filter = cgit_new_filter(value, COMMIT); else if (!strcmp(name, "source-filter")) repo->source_filter = cgit_new_filter(value, SOURCE); - else if (!strcmp(name, "email-filter")) + else repo->email_filter = cgit_new_filter(value, EMAIL); - } + } else + fprintf(stderr, "[cgit] Unknown repo config key: %s\n", name); } int cmd_main(int argc, const char **argv) diff --git a/tests/t0205-config.sh b/tests/t0205-config.sh new file mode 100755 index 0000000..a7d32f4 --- /dev/null +++ b/tests/t0205-config.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# Checks what the configuration parser reports on stderr. A key it does not +# know, a repo key before any repository and a filter override without its +# enabling flag are each ignored with a warning naming the key, and a config +# cgit fully understands stays silent. + +test_description='Check configuration diagnostics' +. ./setup.sh + +test_expect_success 'set up configs' ' + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "no-such-key=1" && + echo "repo.url=diag" && + echo "repo.path=$PWD/repos/foo/.git" && + echo "repo.no-such-repo-key=1" + } >diagrc && + { + echo "virtual-root=/" && + echo "cache-size=0" && + echo "repo.desc=early" && + echo "repo.url=diag" && + echo "repo.path=$PWD/repos/foo/.git" && + echo "repo.about-filter=exec:/bin/true" + } >earlyrc +' + +test_expect_success 'unknown keys are reported and the page still renders' ' + CGIT_CONFIG="$PWD/diagrc" QUERY_STRING="url=diag/" cgit >tmp 2>err && + grep "Status: 200" tmp && + grep "Unknown config key: no-such-key" err && + grep "Unknown repo config key: no-such-repo-key" err +' + +test_expect_success 'a repo key before any repo.url is reported' ' + CGIT_CONFIG="$PWD/earlyrc" QUERY_STRING="url=diag/" cgit >tmp 2>err && + grep "Status: 200" tmp && + grep "Ignoring repo.desc before any repo.url" err +' + +test_expect_success 'a filter override without its flag is reported' ' + grep "Ignoring repo about-filter: enable-filter-overrides is not set" err +' + +test_expect_success 'a fully understood config stays silent' ' + cgit_url "foo/" >tmp 2>err && + grep "Status: 200" tmp && + ! grep "\[cgit\]" err +' + +test_done |
