]> git.ipfire.org Git - thirdparty/git.git/commitdiff
expand_user_path: expand ~ to $HOME, not to the actual homedir.
authorMatthieu Moy <Matthieu.Moy@imag.fr>
Thu, 19 Nov 2009 15:21:15 +0000 (16:21 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 19 Nov 2009 18:01:12 +0000 (10:01 -0800)
In 395de250d (Expand ~ and ~user in core.excludesfile, commit.template),
we introduced the mechanism. But expanding ~ using getpw is not what
people overriding $HOME would usually expect. In particular, git looks
for the user's .gitconfig using $HOME, so it's better to be consistent.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
path.c

index 958006ca7673d0c3158fc3f8b16dcebbf11dd9eb..143afb82ebca18fe8b122e885e5f5c1736d6f2f6 100644 (file)
@@ -380,9 +380,9 @@ Common unit suffixes of 'k', 'm', or 'g' are supported.
 core.excludesfile::
        In addition to '.gitignore' (per-directory) and
        '.git/info/exclude', git looks into this file for patterns
-       of files which are not meant to be tracked.  "~/" and "~user/"
-       are expanded to the specified user's home directory.  See
-       linkgit:gitignore[5].
+       of files which are not meant to be tracked.  "~/" is expanded
+       to the value of `$HOME` and "~user/" to the specified user's
+       home directory.  See linkgit:gitignore[5].
 
 core.editor::
        Commands such as `commit` and `tag` that lets you edit
@@ -667,7 +667,8 @@ color.ui::
 
 commit.template::
        Specify a file to use as the template for new commit messages.
-       "~/" and "~user/" are expanded to the specified user's home directory.
+       "~/" is expanded to the value of `$HOME` and "~user/" to the
+       specified user's home directory.
 
 diff.autorefreshindex::
        When using 'git-diff' to compare with work tree
diff --git a/path.c b/path.c
index 2470f78d3971acdf6a716e6d743e4fdaa1fc8a55..00d06332959af03b036b3d0b5ad115dd3b46b920 100644 (file)
--- a/path.c
+++ b/path.c
@@ -235,10 +235,15 @@ char *expand_user_path(const char *path)
        if (path[0] == '~') {
                const char *username = path + 1;
                size_t username_len = first_slash - username;
-               struct passwd *pw = getpw_str(username, username_len);
-               if (!pw)
-                       goto return_null;
-               strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
+               if (username_len == 0) {
+                       const char *home = getenv("HOME");
+                       strbuf_add(&user_path, home, strlen(home));
+               } else {
+                       struct passwd *pw = getpw_str(username, username_len);
+                       if (!pw)
+                               goto return_null;
+                       strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
+               }
                to_copy = first_slash;
        }
        strbuf_add(&user_path, to_copy, strlen(to_copy));