Skip to content

Commit bfd7543

Browse files
committed
Merge branch 'mingw-home'
The environment variable `HOME` is not exactly a native concept on Windows, but Git and its scripts rely heavily on it. Make sure that it is set (using a default that is sensible in most cases, and can easily be overridden by setting the user-wide environment variable `HOME` explicitly, before starting Git). Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 97d076f + 5b49112 commit bfd7543

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

compat/mingw.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,30 @@ static void setup_windows_environment(void)
23492349
/* simulate TERM to enable auto-color (see color.c) */
23502350
if (!getenv("TERM"))
23512351
setenv("TERM", "cygwin", 1);
2352+
2353+
/* calculate HOME if not set */
2354+
if (!getenv("HOME")) {
2355+
/*
2356+
* try $HOMEDRIVE$HOMEPATH - the home share may be a network
2357+
* location, thus also check if the path exists (i.e. is not
2358+
* disconnected)
2359+
*/
2360+
if ((tmp = getenv("HOMEDRIVE"))) {
2361+
struct strbuf buf = STRBUF_INIT;
2362+
strbuf_addstr(&buf, tmp);
2363+
if ((tmp = getenv("HOMEPATH"))) {
2364+
strbuf_addstr(&buf, tmp);
2365+
if (is_directory(buf.buf))
2366+
setenv("HOME", buf.buf, 1);
2367+
else
2368+
tmp = NULL; /* use $USERPROFILE */
2369+
}
2370+
strbuf_release(&buf);
2371+
}
2372+
/* use $USERPROFILE if the home share is not available */
2373+
if (!tmp && (tmp = getenv("USERPROFILE")))
2374+
setenv("HOME", tmp, 1);
2375+
}
23522376
}
23532377

23542378
#if !defined(_MSC_VER)

0 commit comments

Comments
 (0)