[PATCH 2/2] help: make option --help open man pages only for Git commands
- From
Ralf Thielow <ralf.thielow@gmail.com>
- Date
- Aug 18, 2016, 18:57 UTC
- Message-ID
- <20160818185719.4909-3-ralf.thielow@gmail.com>
- In-Reply-To
- <20160818185719.4909-2-ralf.thielow@gmail.com>
If option --help is passed to a Git command, we try to open the man page of that command. However, we do it even for commands we don't know. Make sure it is a Git command.
This breaks "git <concept> --help" while "git help <concept>" still works.
Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com> --- git.c | 15 ++++++++++++++- t/t0012-help.sh | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/git.c b/git.c index 0f1937f..2cd2e06 100644 --- a/git.c +++ b/git.c @@ -528,10 +528,23 @@ static void handle_builtin(int argc, const char **argv) strip_extension(argv); cmd = argv[0]; - /* Turn "git cmd --help" into "git help cmd" */ + /* Turn "git cmd --help" into "git help --command-only cmd" */ if (argc > 1 && !strcmp(argv[1], "--help")) { + struct argv_array args; + int i; + argv[1] = argv[0]; argv[0] = cmd = "help"; + + argv_array_init(&args); + for (i = 0; i < argc; i++) { + argv_array_push(&args, argv[i]); + if (!i) + argv_array_push(&args, "--command-only"); + } + + argc++; + argv = argv_array_detach(&args); } builtin = get_builtin(cmd); diff --git a/t/t0012-help.sh b/t/t0012-help.sh index e20f907..81fec90 100755 --- a/t/t0012-help.sh +++ b/t/t0012-help.sh @@ -18,4 +18,12 @@ test_expect_success "--command-only does not work for guides" " test_i18ncmp expected actual " +test_expect_success "--help does not work for guides" " + cat <<-EOF >expected && + git: 'revisions' is not a git command. See 'git --help'. + EOF + (git revisions --help 2>actual || true) && + test_i18ncmp expected actual +" + test_done
-- 2.9.2.912.gd0c0e83