summaryrefslogtreecommitdiff
path: root/compat/mingw.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-07-19 18:30:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-07-19 18:30:23 (GMT)
commitfc613d2d6eadbc57780e4151ef8f89d07cb959cc (patch)
tree96dc4a6ce0e87772e8930c2c7fb41b0efd010d05 /compat/mingw.c
parentdd0bc5b531f47e54d499e944db5276505319eaef (diff)
parente12a9556602f4d94254cc4eda25b5615ff07131a (diff)
downloadgit-fc613d2d6eadbc57780e4151ef8f89d07cb959cc.zip
git-fc613d2d6eadbc57780e4151ef8f89d07cb959cc.tar.gz
git-fc613d2d6eadbc57780e4151ef8f89d07cb959cc.tar.bz2
Merge branch 'kb/mingw-set-home'
Windows port update. * kb/mingw-set-home: mingw: initialize HOME on startup
Diffstat (limited to 'compat/mingw.c')
-rw-r--r--compat/mingw.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/compat/mingw.c b/compat/mingw.c
index 4891789..d991346 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -2333,6 +2333,30 @@ static void setup_windows_environment(void)
/* simulate TERM to enable auto-color (see color.c) */
if (!getenv("TERM"))
setenv("TERM", "cygwin", 1);
+
+ /* calculate HOME if not set */
+ if (!getenv("HOME")) {
+ /*
+ * try $HOMEDRIVE$HOMEPATH - the home share may be a network
+ * location, thus also check if the path exists (i.e. is not
+ * disconnected)
+ */
+ if ((tmp = getenv("HOMEDRIVE"))) {
+ struct strbuf buf = STRBUF_INIT;
+ strbuf_addstr(&buf, tmp);
+ if ((tmp = getenv("HOMEPATH"))) {
+ strbuf_addstr(&buf, tmp);
+ if (is_directory(buf.buf))
+ setenv("HOME", buf.buf, 1);
+ else
+ tmp = NULL; /* use $USERPROFILE */
+ }
+ strbuf_release(&buf);
+ }
+ /* use $USERPROFILE if the home share is not available */
+ if (!tmp && (tmp = getenv("USERPROFILE")))
+ setenv("HOME", tmp, 1);
+ }
}
#if !defined(_MSC_VER)