From: kevin brintnall <kbrint@rufus.net>
To: git@vger.kernel.org
Cc: kevin brintnall <kbrint@rufus.net>
Subject: [PATCH] added -C option to chdir() into another directory first
Date: Thu, 26 Feb 2009 14:11:39 -0600 [thread overview]
Message-ID: <1235679099-33994-1-git-send-email-kbrint@rufus.net> (raw)
This allows things like 'git -C /somewhere pull' without specifying both
--work-tree and --git-dir.
Signed-off-by: kevin brintnall <kbrint@rufus.net>
---
git.c | 12 +++++++++++-
1 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/git.c b/git.c
index c2b181e..b218bfe 100644
--- a/git.c
+++ b/git.c
@@ -5,7 +5,7 @@
#include "run-command.h"
const char git_usage_string[] =
- "git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]";
+ "git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [-C BASE_DIR] [--help] COMMAND [ARGS]";
const char git_more_info_string[] =
"See 'git help COMMAND' for more information on a specific command.";
@@ -116,6 +116,16 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);
if (envchanged)
*envchanged = 1;
+ } else if (!strcmp(cmd, "-C")) {
+ char *dir = (*argv)[1];
+ if (*argc < 2) {
+ fprintf(stderr, "No directory given for -C");
+ usage(git_usage_string);
+ }
+ if (chdir(dir))
+ die("Cannot change to %s: %s", dir, strerror(errno));
+ (*argv)++;
+ (*argc)--;
} else {
fprintf(stderr, "Unknown option: %s\n", cmd);
usage(git_usage_string);
--
1.6.1.3
next reply other threads:[~2009-02-26 20:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-26 20:11 kevin brintnall [this message]
2009-02-26 20:35 ` [PATCH] added -C option to chdir() into another directory first Junio C Hamano
2009-02-26 20:44 ` kevin brintnall
2009-02-26 21:50 ` Junio C Hamano
2009-02-27 14:21 ` Michael J Gruber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1235679099-33994-1-git-send-email-kbrint@rufus.net \
--to=kbrint@rufus.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox