File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -2333,6 +2333,30 @@ static void setup_windows_environment(void)
23332333 /* simulate TERM to enable auto-color (see color.c) */
23342334 if (!getenv ("TERM" ))
23352335 setenv ("TERM" , "cygwin" , 1 );
2336+
2337+ /* calculate HOME if not set */
2338+ if (!getenv ("HOME" )) {
2339+ /*
2340+ * try $HOMEDRIVE$HOMEPATH - the home share may be a network
2341+ * location, thus also check if the path exists (i.e. is not
2342+ * disconnected)
2343+ */
2344+ if ((tmp = getenv ("HOMEDRIVE" ))) {
2345+ struct strbuf buf = STRBUF_INIT ;
2346+ strbuf_addstr (& buf , tmp );
2347+ if ((tmp = getenv ("HOMEPATH" ))) {
2348+ strbuf_addstr (& buf , tmp );
2349+ if (is_directory (buf .buf ))
2350+ setenv ("HOME" , buf .buf , 1 );
2351+ else
2352+ tmp = NULL ; /* use $USERPROFILE */
2353+ }
2354+ strbuf_release (& buf );
2355+ }
2356+ /* use $USERPROFILE if the home share is not available */
2357+ if (!tmp && (tmp = getenv ("USERPROFILE" )))
2358+ setenv ("HOME" , tmp , 1 );
2359+ }
23362360}
23372361
23382362#if !defined(_MSC_VER )
You can’t perform that action at this time.
0 commit comments