@matheusbsbs / matheus-bagliano / commits / 97fc6c5fba
Fork 0

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>

Andreas Ericsson committed Nov 16, 2005 at 00:31 UTC 97fc6c5fbacc2181319bbd7e2faa8ac04476f862
2 files changed +28 -2
Documentation/git.txt
+2
@@ -24,6 +24,8 @@ OPTIONS
24
25 --help::
26 prints the synopsis and a list of available commands.
27 + If a git command is named this option will bring up the
28 + man-page for that command.
29
30 --exec-path::
31 path to wherever your core git programs are installed.
git.c
+26 -2
@@ -160,6 +160,26 @@ static void prepend_to_path(const char *dir, int len)
160 setenv("PATH", path, 1);
161 }
162
163 +/* has anyone seen 'man' installed anywhere else than in /usr/bin? */
164 +#define PATH_TO_MAN "/usr/bin/man"
165 +static void show_man_page(char *git_cmd)
166 +{
167 + char *page;
168 +
169 + if (!strncmp(git_cmd, "git", 3))
170 + page = git_cmd;
171 + else {
172 + int page_len = strlen(git_cmd) + 4;
173 +
174 + page = malloc(page_len + 1);
175 + strcpy(page, "git-");
176 + strcpy(page + 4, git_cmd);
177 + page[page_len] = 0;
178 + }
179 +
180 + execlp(PATH_TO_MAN, "man", page, NULL);
181 +}
182 +
183 int main(int argc, char **argv, char **envp)
184 {
185 char git_command[PATH_MAX + 1];
@@ -199,8 +219,12 @@ int main(int argc, char **argv, char **envp)
219 usage(NULL, NULL);
220 }
221
202 - if (i >= argc || show_help)
203 - usage(exec_path, NULL);
222 + if (i >= argc || show_help) {
223 + if (i >= argc)
224 + usage(exec_path, NULL);
225 +
226 + show_man_page(argv[i]);
227 + }
228
229 /* allow relative paths, but run with exact */
230 if (chdir(exec_path)) {