Skip to content

Commit 25c2a36

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 fa2db85 + 1175106 commit 25c2a36

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
@@ -2364,6 +2364,30 @@ static void setup_windows_environment(void)
23642364
/* simulate TERM to enable auto-color (see color.c) */
23652365
if (!getenv("TERM"))
23662366
setenv("TERM", "cygwin", 1);
2367+
2368+
/* calculate HOME if not set */
2369+
if (!getenv("HOME")) {
2370+
/*
2371+
* try $HOMEDRIVE$HOMEPATH - the home share may be a network
2372+
* location, thus also check if the path exists (i.e. is not
2373+
* disconnected)
2374+
*/
2375+
if ((tmp = getenv("HOMEDRIVE"))) {
2376+
struct strbuf buf = STRBUF_INIT;
2377+
strbuf_addstr(&buf, tmp);
2378+
if ((tmp = getenv("HOMEPATH"))) {
2379+
strbuf_addstr(&buf, tmp);
2380+
if (is_directory(buf.buf))
2381+
setenv("HOME", buf.buf, 1);
2382+
else
2383+
tmp = NULL; /* use $USERPROFILE */
2384+
}
2385+
strbuf_release(&buf);
2386+
}
2387+
/* use $USERPROFILE if the home share is not available */
2388+
if (!tmp && (tmp = getenv("USERPROFILE")))
2389+
setenv("HOME", tmp, 1);
2390+
}
23672391
}
23682392

23692393
#if !defined(_MSC_VER)

0 commit comments

Comments
 (0)