Skip to content

Commit 1cd9508

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
Support "git cmd --help" syntax
The "--help" argument is special, in that it is (along with "--version") in that is taken by the "git" program itself rather than the sub-command, and thus we've had the syntax "git --help cmd". However, as anybody who has ever used CVS or some similar devil-spawn program, it's confusing as h*ll when options before the sub-command act differently from options after the sub-command, so this quick hack just makes it acceptable to do "git cmd --help" instead, and get the exact same result. It may be hacky, but it's simple and does the trick. Of course, this does not help if you use one of the non-builtin commands without using the "git" helper. Ie you won't be getting a man-page just because you do "git-rev-list --help". Don't expect us to be quite _that_ helpful. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 6f4780f commit 1cd9508

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

git.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
413413
};
414414
int i;
415415

416+
/* Turn "git cmd --help" into "git help cmd" */
417+
if (argc > 1 && !strcmp(argv[1], "--help")) {
418+
argv[1] = argv[0];
419+
argv[0] = cmd = "help";
420+
}
421+
416422
for (i = 0; i < ARRAY_SIZE(commands); i++) {
417423
struct cmd_struct *p = commands+i;
418424
if (strcmp(p->cmd, cmd))

0 commit comments

Comments
 (0)