Merge branch 'ma/help-w-check-for-requested-page'

The error in "git help no-such-git-command" is handled better.

* ma/help-w-check-for-requested-page:
  help: make sure local html page exists before calling external processes
This commit is contained in:
Junio C Hamano 2021-09-23 13:44:48 -07:00
commit bd42622e5f
2 changed files with 22 additions and 3 deletions

View File

@ -467,11 +467,14 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
if (!html_path)
html_path = to_free = system_path(GIT_HTML_PATH);
/* Check that we have a git documentation directory. */
/*
* Check that the page we're looking for exists.
*/
if (!strstr(html_path, "://")) {
if (stat(mkpath("%s/git.html", html_path), &st)
if (stat(mkpath("%s/%s.html", html_path, page), &st)
|| !S_ISREG(st.st_mode))
die("'%s': not a documentation directory.", html_path);
die("'%s/%s.html': documentation file not found.",
html_path, page);
}
strbuf_init(page_path, 0);

View File

@ -73,6 +73,22 @@ test_expect_success 'git help -g' '
test_i18ngrep "^ tutorial " help.output
'
test_expect_success 'git help fails for non-existing html pages' '
configure_help &&
mkdir html-empty &&
test_must_fail git -c help.htmlpath=html-empty help status &&
test_must_be_empty test-browser.log
'
test_expect_success 'git help succeeds without git.html' '
configure_help &&
mkdir html-with-docs &&
touch html-with-docs/git-status.html &&
git -c help.htmlpath=html-with-docs help status &&
echo "html-with-docs/git-status.html" >expect &&
test_cmp expect test-browser.log
'
test_expect_success 'generate builtin list' '
git --list-cmds=builtins >builtins
'