]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'kb/mingw-set-home'
authorJunio C Hamano <gitster@pobox.com>
Fri, 19 Jul 2019 18:30:23 +0000 (11:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Jul 2019 18:30:23 +0000 (11:30 -0700)
Windows port update.

* kb/mingw-set-home:
  mingw: initialize HOME on startup

1  2 
compat/mingw.c

diff --cc compat/mingw.c
index 48917897710169fff29d93e5f1b5313cea871808,1047427cb559efc2f3c1d932f94e25d35da5d45d..d9913463be184fc508610c082f2ec1827898d12d
@@@ -2333,9 -2299,32 +2333,33 @@@ static void setup_windows_environment(v
        /* 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)
  /*
   * Disable MSVCRT command line wildcard expansion (__getmainargs called from
   * mingw startup code, see init.c in mingw runtime).