mingw: initialize HOME on startup
HOME initialization was historically duplicated in many different places, including /etc/profile, launch scripts such as git-bash.vbs and gitk.cmd, and (although slightly broken) in the git-wrapper. Even unrelated projects such as GitExtensions and TortoiseGit need to implement the same logic to be able to call git directly. Initialize HOME in git's own startup code so that we can eventually retire all the duplicate initialization code. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Karsten Blees committed
Jul 4, 2019 at 02:20 UTC
e12a9556602f4d94254cc4eda25b5615ff07131a
1 file changed
+24
compat/mingw.c
+24
@@ -2299,6 +2299,30 @@ static void setup_windows_environment(void)
2299
/* simulate TERM to enable auto-color (see color.c) */
2300
if (!getenv("TERM"))
2301
setenv("TERM", "cygwin", 1);
2302
+
2303
+ /* calculate HOME if not set */
2304
+ if (!getenv("HOME")) {
2305
+ /*
2306
+ * try $HOMEDRIVE$HOMEPATH - the home share may be a network
2307
+ * location, thus also check if the path exists (i.e. is not
2308
+ * disconnected)
2309
+ */
2310
+ if ((tmp = getenv("HOMEDRIVE"))) {
2311
+ struct strbuf buf = STRBUF_INIT;
2312
+ strbuf_addstr(&buf, tmp);
2313
+ if ((tmp = getenv("HOMEPATH"))) {
2314
+ strbuf_addstr(&buf, tmp);
2315
+ if (is_directory(buf.buf))
2316
+ setenv("HOME", buf.buf, 1);
2317
+ else
2318
+ tmp = NULL; /* use $USERPROFILE */
2319
+ }
2320
+ strbuf_release(&buf);
2321
+ }
2322
+ /* use $USERPROFILE if the home share is not available */
2323
+ if (!tmp && (tmp = getenv("USERPROFILE")))
2324
+ setenv("HOME", tmp, 1);
2325
+ }
2326
}
2327
2328
/*