aboutsummaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-09-20 12:35:42 -0700
committerJunio C Hamano <gitster@pobox.com>2013-09-20 12:35:42 -0700
commit087350398e8b2c5d4b39f051b23a2e533f4d830b (patch)
tree2cd7effc6e38cb59c117262c839080ff0db97802 /git.c
parentf26f250b442b57d0e6d9295bb98690ce70640759 (diff)
parent28a81f8b93897402a8c8c15ee16e67f0c24ac11c (diff)
downloadgit-087350398e8b2c5d4b39f051b23a2e533f4d830b.tar.gz
git-087350398e8b2c5d4b39f051b23a2e533f4d830b.tar.xz
Merge branch 'nr/git-cd-to-a-directory'
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
Diffstat (limited to 'git.c')
-rw-r--r--git.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/git.c b/git.c
index b3893e73c..118897946 100644
--- a/git.c
+++ b/git.c
@@ -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"
@@ -165,6 +165,17 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
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);