From 861429a7c37cce27b07331ab9106c3c52c68cf2d Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Fri, 29 Dec 2006 08:54:11 +0100 Subject: [PATCH] Be prepared for DOS-like drive letters in the getcwd() result. An earlier patch has implemented getcwd() so that it converts the drive letter into the POSIX-like path that is used internally by MinGW (C:\foo => /c/foo), but this style does not work outside the MinGW shell. It is better to just convert the backslashes to forward slashes and handle the drive letter explicitly. --- compat/mingw.c | 2 -- setup.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index ac4d4eb7fe..f22ab57461 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -122,8 +122,6 @@ char *mingw_getcwd(char *pointer, int len) return ret; if (pointer[0] != 0 && pointer[1] == ':') { int i; - pointer[1] = pointer[0]; - pointer[0] = '/'; for (i = 2; pointer[i]; i++) /* Thanks, Bill. You'll burn in hell for that. */ if (pointer[i] == '\\') diff --git a/setup.c b/setup.c index cc97f9f5c1..707f8f9a55 100644 --- a/setup.c +++ b/setup.c @@ -173,6 +173,7 @@ const char *setup_git_directory_gently(int *nongit_ok) static char cwd[PATH_MAX+1]; const char *gitdirenv; int len, offset; + int minoffset = 0; /* * If GIT_DIR is set explicitly, we're not going @@ -192,8 +193,15 @@ const char *setup_git_directory_gently(int *nongit_ok) die("Not a git repository: '%s'", gitdirenv); } +#ifdef __MINGW32__ + if (!getcwd(cwd, sizeof(cwd)) || !(cwd[0] == '/' || cwd[1] == ':')) + die("Unable to read current working directory"); + if (cwd[1] == ':') + minoffset = 2; +#else if (!getcwd(cwd, sizeof(cwd)) || cwd[0] != '/') die("Unable to read current working directory"); +#endif offset = len = strlen(cwd); for (;;) { @@ -201,7 +209,7 @@ const char *setup_git_directory_gently(int *nongit_ok) break; chdir(".."); do { - if (!offset) { + if (offset <= minoffset) { if (is_git_directory(cwd)) { if (chdir(cwd)) die("Cannot come back to cwd"); @@ -216,7 +224,7 @@ const char *setup_git_directory_gently(int *nongit_ok) } die("Not a git repository"); } - } while (cwd[--offset] != '/'); + } while (offset > minoffset && cwd[--offset] != '/'); } if (offset == len)