mirror of
https://github.com/git/git.git
synced 2026-01-31 21:09:39 +00:00
git-wrapper: fix HOME initialization
git-wrapper fails to initialize HOME correctly if $HOMEDRIVE$HOMEPATH points to a disconnected network drive. Check if the directory exists before using $HOMEDRIVE$HOMEPATH. Signed-off-by: Karsten Blees <blees@dcon.de>
This commit is contained in:
committed by
Johannes Schindelin
parent
c181f00358
commit
44cb23c5e2
@@ -56,13 +56,29 @@ static void setup_environment(LPWSTR exepath, int full_path)
|
||||
if (!GetEnvironmentVariable(L"PLINK_PROTOCOL", NULL, 0))
|
||||
SetEnvironmentVariable(L"PLINK_PROTOCOL", L"ssh");
|
||||
|
||||
/* set HOME to %HOMEDRIVE%%HOMEPATH% or %USERPROFILE%
|
||||
/*
|
||||
* set HOME to %HOMEDRIVE%%HOMEPATH% or %USERPROFILE%
|
||||
* With roaming profiles: HOMEPATH is the roaming location and
|
||||
* USERPROFILE is the local location
|
||||
*/
|
||||
if (!GetEnvironmentVariable(L"HOME", NULL, 0)) {
|
||||
LPWSTR e = NULL;
|
||||
len = GetEnvironmentVariable(L"HOMEPATH", NULL, 0);
|
||||
if (len) {
|
||||
DWORD attr, drvlen = GetEnvironmentVariable(L"HOMEDRIVE", NULL, 0);
|
||||
e = (LPWSTR)malloc(sizeof(WCHAR) * (drvlen + len));
|
||||
drvlen = GetEnvironmentVariable(L"HOMEDRIVE", e, drvlen);
|
||||
GetEnvironmentVariable(L"HOMEPATH", e + drvlen, len);
|
||||
/* check if the path exists */
|
||||
attr = GetFileAttributesW(e);
|
||||
if (attr != INVALID_FILE_ATTRIBUTES
|
||||
&& (attr & FILE_ATTRIBUTE_DIRECTORY))
|
||||
SetEnvironmentVariable(L"HOME", e);
|
||||
else
|
||||
len = 0; /* use USERPROFILE */
|
||||
free(e);
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
len = GetEnvironmentVariable(L"USERPROFILE", NULL, 0);
|
||||
if (len != 0) {
|
||||
@@ -72,15 +88,6 @@ static void setup_environment(LPWSTR exepath, int full_path)
|
||||
free(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int n;
|
||||
len += GetEnvironmentVariable(L"HOMEDRIVE", NULL, 0);
|
||||
e = (LPWSTR)malloc(sizeof(WCHAR) * (len + 2));
|
||||
n = GetEnvironmentVariable(L"HOMEDRIVE", e, len);
|
||||
GetEnvironmentVariable(L"HOMEPATH", &e[n], len-n);
|
||||
SetEnvironmentVariable(L"HOME", e);
|
||||
free(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* extend the PATH */
|
||||
|
||||
Reference in New Issue
Block a user