Merge branch 'nr/git-cd-to-a-directory'
authorJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2013 19:35:42 +0000 (12:35 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Sep 2013 19:35:42 +0000 (12:35 -0700)
Just like "make -C <directory>", make "git -C <directory> ..." to
go there before doing anything else.

* nr/git-cd-to-a-directory:
t0056: "git -C" test updates
git: run in a directory given with -C option

1  2 
Documentation/git.txt
git.c
diff --combined Documentation/git.txt
index c4f0ed59576b877a5eab2e36aa874d8c572bb905,d6baf98f7916290d0e40c6b83e85084cfbc69528..5d68d33e46587deb785317a213857f0de5371022
@@@ -9,7 -9,7 +9,7 @@@ git - the stupid content tracke
  SYNOPSIS
  --------
  [verse]
- 'git' [--version] [--help] [-c <name>=<value>]
+ 'git' [--version] [--help] [-C <path>] [-c <name>=<value>]
      [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
      [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
      [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
@@@ -395,6 -395,20 +395,20 @@@ displayed. See linkgit:git-help[1] for 
  because `git --help ...` is converted internally into `git
  help ...`.
  
+ -C <path>::
+       Run as if git was started in '<path>' instead of the current working
+       directory.  When multiple `-C` options are given, each subsequent
+       non-absolute `-C <path>` is interpreted relative to the preceding `-C
+       <path>`.
+ +
+ This option affects options that expect path name like `--git-dir` and
+ `--work-tree` in that their interpretations of the path names would be
+ made relative to the working directory caused by the `-C` option. For
+ example the following invocations are equivalent:
+     git --git-dir=a.git --work-tree=b -C c status
+     git --git-dir=c/a.git --work-tree=c/b status
  -c <name>=<value>::
        Pass a configuration parameter to the command. The value
        given will override values from configuration files.
        linkgit:git-replace[1] for more information.
  
  --literal-pathspecs::
 -      Treat pathspecs literally, rather than as glob patterns. This is
 -      equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
 +      Treat pathspecs literally (i.e. no globbing, no pathspec magic).
 +      This is equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
        variable to `1`.
  
 +--glob-pathspecs:
 +      Add "glob" magic to all pathspec. This is equivalent to setting
 +      the `GIT_GLOB_PATHSPECS` environment variable to `1`. Disabling
 +      globbing on individual pathspecs can be done using pathspec
 +      magic ":(literal)"
 +
 +--noglob-pathspecs:
 +      Add "literal" magic to all pathspec. This is equivalent to setting
 +      the `GIT_NOGLOB_PATHSPECS` environment variable to `1`. Enabling
 +      globbing on individual pathspecs can be done using pathspec
 +      magic ":(glob)"
 +
 +--icase-pathspecs:
 +      Add "icase" magic to all pathspec. This is equivalent to setting
 +      the `GIT_ICASE_PATHSPECS` environment variable to `1`.
  
  GIT COMMANDS
  ------------
@@@ -838,7 -837,7 +852,7 @@@ for further details
  'GIT_FLUSH'::
        If this environment variable is set to "1", then commands such
        as 'git blame' (in incremental mode), 'git rev-list', 'git log',
 -      'git check-attr', 'git check-ignore', and 'git whatchanged' will
 +      'git check-attr' and 'git check-ignore' will
        force a flush of the output stream after each record have been
        flushed. If this
        variable is set to "0", the output of these commands will be done
@@@ -882,18 -881,6 +896,18 @@@ GIT_LITERAL_PATHSPECS:
        literal paths to Git (e.g., paths previously given to you by
        `git ls-tree`, `--raw` diff output, etc).
  
 +GIT_GLOB_PATHSPECS::
 +      Setting this variable to `1` will cause Git to treat all
 +      pathspecs as glob patterns (aka "glob" magic).
 +
 +GIT_NOGLOB_PATHSPECS::
 +      Setting this variable to `1` will cause Git to treat all
 +      pathspecs as literal (aka "literal" magic).
 +
 +GIT_ICASE_PATHSPECS::
 +      Setting this variable to `1` will cause Git to treat all
 +      pathspecs as case-insensitive.
 +
  
  Discussion[[Discussion]]
  ------------------------
diff --combined git.c
index b3893e73c93c59431516bccb86e12e8f64d39319,a2d99a7d82104f894edc8f2a473c03f0a69b1f24..1188979465654248c5936e8246886341846cc6f1
--- 1/git.c
--- 2/git.c
+++ b/git.c
@@@ -7,7 -7,7 +7,7 @@@
  #include "commit.h"
  
  const char git_usage_string[] =
-       "git [--version] [--help] [-c name=value]\n"
+       "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"
        "           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
@@@ -147,24 -147,23 +147,35 @@@ static int handle_options(const char **
                        setenv(GIT_LITERAL_PATHSPECS_ENVIRONMENT, "0", 1);
                        if (envchanged)
                                *envchanged = 1;
 +              } else if (!strcmp(cmd, "--glob-pathspecs")) {
 +                      setenv(GIT_GLOB_PATHSPECS_ENVIRONMENT, "1", 1);
 +                      if (envchanged)
 +                              *envchanged = 1;
 +              } else if (!strcmp(cmd, "--noglob-pathspecs")) {
 +                      setenv(GIT_NOGLOB_PATHSPECS_ENVIRONMENT, "1", 1);
 +                      if (envchanged)
 +                              *envchanged = 1;
 +              } else if (!strcmp(cmd, "--icase-pathspecs")) {
 +                      setenv(GIT_ICASE_PATHSPECS_ENVIRONMENT, "1", 1);
 +                      if (envchanged)
 +                              *envchanged = 1;
                } else if (!strcmp(cmd, "--shallow-file")) {
                        (*argv)++;
                        (*argc)--;
                        set_alternate_shallow_file((*argv)[0]);
                        if (envchanged)
                                *envchanged = 1;
+               } else if (!strcmp(cmd, "-C")) {
+                       if (*argc < 2) {
+                               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;
+                       (*argv)++;
+                       (*argc)--;
                } else {
                        fprintf(stderr, "Unknown option: %s\n", cmd);
                        usage(git_usage_string);