mirror of
https://github.com/git/git.git
synced 2026-03-13 18:33:25 +01:00
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.
This commit is contained in:
@@ -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] == '\\')
|
||||
|
||||
12
setup.c
12
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)
|
||||
|
||||
Reference in New Issue
Block a user