Merge branch 'kn/git-cd-to-empty'
authorJunio C Hamano <gitster@pobox.com>
Fri, 20 Mar 2015 20:11:46 +0000 (13:11 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Mar 2015 20:11:46 +0000 (13:11 -0700)
"git -C '' subcmd" refused to work in the current directory, unlike
"cd ''" which silently behaves as a no-op.

* kn/git-cd-to-empty:
git: treat "git -C '<path>'" as a no-op when <path> is empty

1  2 
git.c
diff --combined git.c
index 8b5659b2086a2716b8978b2a57bbdc0d7ff5124a,fdea1104079d21ea00f408d4fd5fd36fce4b24a8..42a4ee57843f569fb754121f01bb8c46feee2fd3
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -6,7 -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 +204,12 @@@ static int handle_options(const char **
                                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 {
@@@ -618,7 -620,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;
  
        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) {