git wrapper: add --git-dir=<path> and --bare options
With this, you can say git --bare repack -a -d inside a bare repository, and it will actually work. While at it, also move the --version, --help and --exec-path options to the handle_options() function. While at documenting the new options, also document the --paginate option. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Jul 25, 2006 at 20:24 UTC
6acbcb927f8e34857fa8f68fcb4f9076941b24ff
3 files changed
+58
-47
Documentation/git.txt
+11
-1
@@ -8,7 +8,8 @@ git - the stupid content tracker
8
9
SYNOPSIS
10
--------
11
-'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--help] COMMAND [ARGS]
11
+'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate]
12
+ [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]
13
14
DESCRIPTION
15
-----------
@@ -41,6 +42,15 @@ OPTIONS
42
environment variable. If no path is given 'git' will print
43
the current setting and then exit.
44
45
+-p|--paginate::
46
+ Pipe all output into 'less' (or if set, $PAGER).
47
+
48
+--git-dir=<path>::
49
+ Set the path to the repository. This can also be controlled by
50
+ setting the GIT_DIR environment variable.
51
+
52
+--bare::
53
+ Same as --git-dir=`pwd`.
54
55
FURTHER DOCUMENTATION
56
---------------------
builtin-help.c
+1
-1
@@ -229,7 +229,7 @@ int cmd_version(int argc, const char **argv, char **envp)
229
230
int cmd_help(int argc, const char **argv, char **envp)
231
{
232
- const char *help_cmd = argv[1];
232
+ const char *help_cmd = argc > 1 ? argv[1] : NULL;
233
if (!help_cmd)
234
cmd_usage(0, git_exec_path(), NULL);
235
else if (!strcmp(help_cmd, "--all") || !strcmp(help_cmd, "-a"))
git.c
+46
-45
@@ -44,10 +44,42 @@ static int handle_options(const char*** argv, int* argc)
44
if (cmd[0] != '-')
45
break;
46
47
- if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
47
+ /*
48
+ * For legacy reasons, the "version" and "help"
49
+ * commands can be written with "--" prepended
50
+ * to make them look like flags.
51
+ */
52
+ if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version"))
53
+ break;
54
+
55
+ /*
56
+ * Check remaining flags.
57
+ */
58
+ if (!strncmp(cmd, "--exec-path", 11)) {
59
+ cmd += 11;
60
+ if (*cmd == '=')
61
+ git_set_exec_path(cmd + 1);
62
+ else {
63
+ puts(git_exec_path());
64
+ exit(0);
65
+ }
66
+ } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
67
setup_pager();
49
- } else
50
- die ("Unknown option: %s", cmd);
68
+ } else if (!strcmp(cmd, "--git-dir")) {
69
+ if (*argc < 1)
70
+ return -1;
71
+ setenv("GIT_DIR", (*argv)[1], 1);
72
+ (*argv)++;
73
+ (*argc)--;
74
+ } else if (!strncmp(cmd, "--git-dir=", 10)) {
75
+ setenv("GIT_DIR", cmd + 10, 1);
76
+ } else if (!strcmp(cmd, "--bare")) {
77
+ static char git_dir[1024];
78
+ setenv("GIT_DIR", getcwd(git_dir, 1024), 1);
79
+ } else {
80
+ fprintf(stderr, "Unknown option: %s\n", cmd);
81
+ cmd_usage(0, NULL, NULL);
82
+ }
83
84
(*argv)++;
85
(*argc)--;
@@ -293,50 +325,19 @@ int main(int argc, const char **argv, char **envp)
325
die("cannot handle %s internally", cmd);
326
}
327
296
- /* Default command: "help" */
297
- cmd = "help";
298
-
328
/* Look for flags.. */
300
- while (argc > 1) {
301
- argv++;
302
- argc--;
303
-
304
- handle_options(&argv, &argc);
305
-
306
- cmd = *argv;
307
-
308
- if (strncmp(cmd, "--", 2))
309
- break;
310
-
311
- cmd += 2;
312
-
313
- /*
314
- * For legacy reasons, the "version" and "help"
315
- * commands can be written with "--" prepended
316
- * to make them look like flags.
317
- */
318
- if (!strcmp(cmd, "help"))
319
- break;
320
- if (!strcmp(cmd, "version"))
321
- break;
322
-
323
- /*
324
- * Check remaining flags (which by now must be
325
- * "--exec-path", but maybe we will accept
326
- * other arguments some day)
327
- */
328
- if (!strncmp(cmd, "exec-path", 9)) {
329
- cmd += 9;
330
- if (*cmd == '=') {
331
- git_set_exec_path(cmd + 1);
332
- continue;
333
- }
334
- puts(git_exec_path());
335
- exit(0);
336
- }
337
- cmd_usage(0, NULL, NULL);
329
+ argv++;
330
+ argc--;
331
+ handle_options(&argv, &argc);
332
+ if (argc > 0) {
333
+ if (!strncmp(argv[0], "--", 2))
334
+ argv[0] += 2;
335
+ } else {
336
+ /* Default command: "help" */
337
+ argv[0] = "help";
338
+ argc = 1;
339
}
339
- argv[0] = cmd;
340
+ cmd = argv[0];
341
342
/*
343
* We search for git commands in the following order: