msysgit / git

msysGit-based Git for Windows 1.x is now superseded by Git for Windows 2.x
http://github.com/git-for-windows/git
Other
1.01k stars 317 forks source link

For git.exe alone, use the same HOME directory fallback mechanism as /etc/profile #322

Closed linquize closed 9 years ago

linquize commented 9 years ago

For git.exe alone, use the same HOME directory fallback mechanism as /etc/profile

This allows the fallback mechanism to work outside Git Bash.

buildhive commented 9 years ago

MSysGit - the development behind Git for Windows » git #264 SUCCESS This pull request looks good (what's this?)

linquize commented 9 years ago

Changed to use is_directory()

dscho commented 9 years ago

Thank you so much!

My only remaining request is to adjust the commit message a bit. The idea is that we contribute all of the modifications of the Git source code to upstream, eventually, therefore it would be good to abide by their rules. Would you please prefix the patch by mingw:, make sure that the first line is shorter than 73 characters, and maybe mention in the commit message's body why we go through such a dance with the HOME variable? Oh, and please sign off on the patch, as described here.

buildhive commented 9 years ago

MSysGit - the development behind Git for Windows » git #266 SUCCESS This pull request looks good (what's this?)

linquize commented 9 years ago

Commit message updated.

buildhive commented 9 years ago

MSysGit - the development behind Git for Windows » git #267 FAILURE Looks like there's a problem with this pull request (what's this?)

dscho commented 9 years ago

Thank you so much!

kblees commented 9 years ago

Good intentions - unfortunately, you've based your change on code that is not in the master branch.

Rather than fixing any of the pre-existing issues with get_windows_home_directory() discussed in [1], you've added quite a few more:

To set "HOME" in git, I would have expected something like this on master:

@@ -2239,6 +2239,27 @@ void mingw_startup()
    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 (getenv("HOMEDRIVE") && getenv("HOMEPATH")) {
+           struct strbuf buf = STRBUF_INIT;
+           strbuf_addf(&buf, "%s%s", getenv("HOMEDRIVE"),
+                   getenv("HOMEPATH"));
+           if (is_directory(buf.buf))
+               setenv("HOME", buf.buf, 1);
+           strbuf_release(&buf);
+       }
+
+       /* use $USERPROFILE if the home share is not available */
+       if (!getenv("HOME") && getenv("USERPROFILE"))
+           setenv("HOME", getenv("USERPROFILE"), 1);
+   }
+
    /* initialize critical section for waitpid pinfo_t list */
    InitializeCriticalSection(&pinfo_cs);

[1] https://groups.google.com/forum/#!topic/msysgit/wmyWC6M2hl4