Skip to content

Commit

Permalink
help: make option --help open man pages only for Git commands
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ralfth authored and gitster committed Aug 30, 2016
1 parent af74128 commit 2c6b6d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion git.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,21 +522,34 @@ static void strip_extension(const char **argv)

static void handle_builtin(int argc, const char **argv)
{
struct argv_array args = ARGV_ARRAY_INIT;
const char *cmd;
struct cmd_struct *builtin;

strip_extension(argv);
cmd = argv[0];

/* Turn "git cmd --help" into "git help cmd" */
/* Turn "git cmd --help" into "git help --exclude-guides cmd" */
if (argc > 1 && !strcmp(argv[1], "--help")) {
int i;

argv[1] = argv[0];
argv[0] = cmd = "help";

for (i = 0; i < argc; i++) {
argv_array_push(&args, argv[i]);
if (!i)
argv_array_push(&args, "--exclude-guides");
}

argc++;
argv = args.argv;
}

builtin = get_builtin(cmd);
if (builtin)
exit(run_builtin(builtin, argc, argv));
argv_array_clear(&args);
}

static void execv_dashed_external(const char **argv)
Expand Down
8 changes: 8 additions & 0 deletions t/t0012-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ test_expect_success "--exclude-guides does not work for guides" '
test_must_be_empty test-browser.log
'

test_expect_success "--help does not work for guides" "
cat <<-EOF >expect &&
git: 'revisions' is not a git command. See 'git --help'.
EOF
test_must_fail git revisions --help 2>actual &&
test_i18ncmp expect actual
"

test_done

0 comments on commit 2c6b6d9

Please sign in to comment.