From: Junio C Hamano Date: Sat, 26 Nov 2005 09:56:41 GMT Subject: [PATCH 2/8] peek-remote: honor proxy config even from subdirectory. Message-ID: <7vd5kn68bq.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <7vmzjtn3h1.fsf@assigned-by-dhcp.cox.net> Introduce setup_git_directory_gently() which does not die() if called outside a git repository, and use it so that later git_config() would work as expected even from a subdirectory, without failing the whole command if run outside a git repository. Use it at the beginning of peek-remote so that git:// proxy can be picked up from the configuration file. Signed-off-by: Junio C Hamano --- cache.h | 1 + peek-remote.c | 3 +++ setup.c | 11 ++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) applies-to: 6afe0a2dc5da18d1090e8d660e45e2c777bfeaaa 1fe3fae4e1dcd864af4010ee572a3bc6de996e95 diff --git a/cache.h b/cache.h index 62920ce..13806d3 100644 --- a/cache.h +++ b/cache.h @@ -147,6 +147,7 @@ extern char *get_graft_file(void); #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" extern const char **get_pathspec(const char *prefix, const char **pathspec); +extern const char *setup_git_directory_gently(int *); extern const char *setup_git_directory(void); extern const char *prefix_path(const char *prefix, int len, const char *path); extern const char *prefix_filename(const char *prefix, int len, const char *path); diff --git a/peek-remote.c b/peek-remote.c index ee49bf3..a90cf22 100644 --- a/peek-remote.c +++ b/peek-remote.c @@ -27,6 +27,9 @@ int main(int argc, char **argv) char *dest = NULL; int fd[2]; pid_t pid; + int nongit = 0; + + setup_git_directory_gently(&nongit); for (i = 1; i < argc; i++) { char *arg = argv[i]; diff --git a/setup.c b/setup.c index 54f6a34..b697bf9 100644 --- a/setup.c +++ b/setup.c @@ -107,7 +107,7 @@ static int is_toplevel_directory(void) return 1; } -static const char *setup_git_directory_1(void) +const char *setup_git_directory_gently(int *nongit_ok) { static char cwd[PATH_MAX+1]; int len, offset; @@ -154,8 +154,13 @@ static const char *setup_git_directory_1 break; chdir(".."); do { - if (!offset) + if (!offset) { + if (nongit_ok) { + *nongit_ok = 1; + return NULL; + } die("Not a git repository"); + } } while (cwd[--offset] != '/'); } @@ -171,6 +176,6 @@ static const char *setup_git_directory_1 const char *setup_git_directory(void) { - const char *retval = setup_git_directory_1(); + const char *retval = setup_git_directory_gently(NULL); return retval; } --- 0.99.9.GIT