Skip to content

Commit d475aba

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 290e2bb + f7d76f1 commit d475aba

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

23632387
#if !defined(_MSC_VER)

0 commit comments

Comments
 (0)