git --help COMMAND brings up the git-COMMAND man-page.
It's by design a bit stupid (matching ^git rather than ^git-), so as to work with 'gitk' and 'git' as well. Signed-off-by: Andreas Ericsson <ae@op5.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
cb22bc4447
commit
97fc6c5fba
@ -24,6 +24,8 @@ OPTIONS
|
|||||||
|
|
||||||
--help::
|
--help::
|
||||||
prints the synopsis and a list of available commands.
|
prints the synopsis and a list of available commands.
|
||||||
|
If a git command is named this option will bring up the
|
||||||
|
man-page for that command.
|
||||||
|
|
||||||
--exec-path::
|
--exec-path::
|
||||||
path to wherever your core git programs are installed.
|
path to wherever your core git programs are installed.
|
||||||
|
26
git.c
26
git.c
@ -160,6 +160,26 @@ static void prepend_to_path(const char *dir, int len)
|
|||||||
setenv("PATH", path, 1);
|
setenv("PATH", path, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* has anyone seen 'man' installed anywhere else than in /usr/bin? */
|
||||||
|
#define PATH_TO_MAN "/usr/bin/man"
|
||||||
|
static void show_man_page(char *git_cmd)
|
||||||
|
{
|
||||||
|
char *page;
|
||||||
|
|
||||||
|
if (!strncmp(git_cmd, "git", 3))
|
||||||
|
page = git_cmd;
|
||||||
|
else {
|
||||||
|
int page_len = strlen(git_cmd) + 4;
|
||||||
|
|
||||||
|
page = malloc(page_len + 1);
|
||||||
|
strcpy(page, "git-");
|
||||||
|
strcpy(page + 4, git_cmd);
|
||||||
|
page[page_len] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
execlp(PATH_TO_MAN, "man", page, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp)
|
int main(int argc, char **argv, char **envp)
|
||||||
{
|
{
|
||||||
char git_command[PATH_MAX + 1];
|
char git_command[PATH_MAX + 1];
|
||||||
@ -199,9 +219,13 @@ int main(int argc, char **argv, char **envp)
|
|||||||
usage(NULL, NULL);
|
usage(NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= argc || show_help)
|
if (i >= argc || show_help) {
|
||||||
|
if (i >= argc)
|
||||||
usage(exec_path, NULL);
|
usage(exec_path, NULL);
|
||||||
|
|
||||||
|
show_man_page(argv[i]);
|
||||||
|
}
|
||||||
|
|
||||||
/* allow relative paths, but run with exact */
|
/* allow relative paths, but run with exact */
|
||||||
if (chdir(exec_path)) {
|
if (chdir(exec_path)) {
|
||||||
printf("git: '%s': %s\n", exec_path, strerror(errno));
|
printf("git: '%s': %s\n", exec_path, strerror(errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user