git: treat "git -C '<path>'" as a no-op when <path> is empty
[gitweb.git] / git.c
diff --git a/git.c b/git.c
index 82d7a1cfee806001c2d8b81a9dc822a513c75451..fdea1104079d21ea00f408d4fd5fd36fce4b24a8 100644 (file)
--- a/git.c
+++ b/git.c
@@ -1,10 +1,7 @@
 #include "builtin.h"
-#include "cache.h"
 #include "exec_cmd.h"
 #include "help.h"
-#include "quote.h"
 #include "run-command.h"
-#include "commit.h"
 
 const char git_usage_string[] =
        "git [--version] [--help] [-C <path>] [-c name=value]\n"
@@ -207,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 {