test-parse-options: update to handle negative ints
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index 6b5ae6a2ace7fffdd2ec50ce915ad5dc01a9c7da..44374b1d9b6b73b3669f0f851bee058f45ee4f32 100644 (file)
--- a/git.c
+++ b/git.c
@@ -6,7 +6,7 @@
 const char git_usage_string[] =
        "git [--version] [--help] [-C <path>] [-c name=value]\n"
        "           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
-       "           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]\n"
+       "           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]\n"
        "           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
        "           <command> [<args>]";
 
@@ -204,10 +204,12 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
                                fprintf(stderr, "No directory given for -C.\n" );
                                usage(git_usage_string);
                        }
-                       if (chdir((*argv)[1]))
-                               die_errno("Cannot change to '%s'", (*argv)[1]);
-                       if (envchanged)
-                               *envchanged = 1;
+                       if ((*argv)[1][0]) {
+                               if (chdir((*argv)[1]))
+                                       die_errno("Cannot change to '%s'", (*argv)[1]);
+                               if (envchanged)
+                                       *envchanged = 1;
+                       }
                        (*argv)++;
                        (*argc)--;
                } else {
@@ -380,7 +382,7 @@ static struct cmd_struct commands[] = {
        { "check-ignore", cmd_check_ignore, RUN_SETUP | NEED_WORK_TREE },
        { "check-mailmap", cmd_check_mailmap, RUN_SETUP },
        { "check-ref-format", cmd_check_ref_format },
-       { "checkout", cmd_checkout, RUN_SETUP | NEED_WORK_TREE },
+       { "checkout", cmd_checkout, RUN_SETUP },
        { "checkout-index", cmd_checkout_index,
                RUN_SETUP | NEED_WORK_TREE},
        { "cherry", cmd_cherry, RUN_SETUP },
@@ -618,6 +620,7 @@ int main(int argc, char **av)
 {
        const char **argv = (const char **) av;
        const char *cmd;
+       int done_help = 0;
 
        startup_info = &git_startup_info;
 
@@ -680,9 +683,7 @@ int main(int argc, char **av)
        setup_path();
 
        while (1) {
-               static int done_help = 0;
-               static int was_alias = 0;
-               was_alias = run_argv(&argc, &argv);
+               int was_alias = run_argv(&argc, &argv);
                if (errno != ENOENT)
                        break;
                if (was_alias) {