help: make option --help open man pages only for Git commands

If option --help is passed to a Git command, we try to open the man page of that command. However, we do it for both commands and concepts. Make sure it is an actual command. This makes "git <concept> --help" not working anymore, while "git help <concept>" still works. Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ralf Thielow committed Aug 26, 2016 at 19:58 UTC 2c6b6d9f7d8a26b6ae6493584cc3d2a3cbae7358
2 files changed +22 -1
git.c
+14 -1
@@ -522,21 +522,34 @@ static void strip_extension(const char **argv)
522
523 static void handle_builtin(int argc, const char **argv)
524 {
525 + struct argv_array args = ARGV_ARRAY_INIT;
526 const char *cmd;
527 struct cmd_struct *builtin;
528
529 strip_extension(argv);
530 cmd = argv[0];
531
531 - /* Turn "git cmd --help" into "git help cmd" */
532 + /* Turn "git cmd --help" into "git help --exclude-guides cmd" */
533 if (argc > 1 && !strcmp(argv[1], "--help")) {
534 + int i;
535 +
536 argv[1] = argv[0];
537 argv[0] = cmd = "help";
538 +
539 + for (i = 0; i < argc; i++) {
540 + argv_array_push(&args, argv[i]);
541 + if (!i)
542 + argv_array_push(&args, "--exclude-guides");
543 + }
544 +
545 + argc++;
546 + argv = args.argv;
547 }
548
549 builtin = get_builtin(cmd);
550 if (builtin)
551 exit(run_builtin(builtin, argc, argv));
552 + argv_array_clear(&args);
553 }
554
555 static void execv_dashed_external(const char **argv)
t/t0012-help.sh
+8
@@ -41,4 +41,12 @@ test_expect_success "--exclude-guides does not work for guides" '
41 test_must_be_empty test-browser.log
42 '
43
44 +test_expect_success "--help does not work for guides" "
45 + cat <<-EOF >expect &&
46 + git: 'revisions' is not a git command. See 'git --help'.
47 + EOF
48 + test_must_fail git revisions --help 2>actual &&
49 + test_i18ncmp expect actual
50 +"
51 +
52 test_done