]> git.ipfire.org Git - thirdparty/git.git/commitdiff
help: make sure local html page exists before calling external processes
authorMatthias Aßhauer <mha1993@live.de>
Tue, 14 Sep 2021 13:27:17 +0000 (13:27 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Sep 2021 17:04:08 +0000 (10:04 -0700)
We check that git.html exists, regardless of the page the user wants to open.
Checking whether the requested page exists instead gives us a smoother user
experience in two use cases:

1) The requested page doesn't exist

When calling a git command and there is an error, most users reasonably expect
git to produce an error message on the standard error stream, but in this case
we pass the filepath to git web--browse which passes it on to a browser (or a
helper program like xdg-open or start that should in turn open a browser)
without any error and many GUI based browsers or helpers won't output such a
message onto the standard error stream.

Especially the helper programs tend to show the corresponding error message in
a message box and wait for user input before exiting. This leaves users in
interactive console sessions without an error message in their console,
without a console prompt and without the help page they expected.

2) git.html is missing for some reason, but the user asked for some other page

We currently refuse to show any local html help page when we can't find
git.html. Even if the requested help page exists. If we check for the requested
page instead, we can show the user all available pages and only error out on
those that don't exist.

Signed-off-by: Matthias Aßhauer <mha1993@live.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/help.c
t/t0012-help.sh

index b7eec06c3de8a943fdbd22ba83502d69335726d0..7731659765c5ab67c095effb3452cd7d9fdea683 100644 (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);
index 5679e29c62479c663446e76fbc587a2648efe601..913f34c8e9df2d4b4dd5e301d0774907b39b068e 100755 (executable)
@@ -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
 '