@matheusbsbs / matheus-bagliano / commits / df2a79f422
Fork 0

expand_user_path: expand ~ to $HOME, not to the actual homedir.

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>

Matthieu Moy committed Nov 19, 2009 at 16:21 UTC df2a79f4225b7216dce010ebfe41f8ad0de34b24
2 files changed +14 -8
Documentation/config.txt
+5 -4
@@ -380,9 +380,9 @@ Common unit suffixes of 'k', 'm', or 'g' are supported.
380 core.excludesfile::
381 In addition to '.gitignore' (per-directory) and
382 '.git/info/exclude', git looks into this file for patterns
383 - of files which are not meant to be tracked. "~/" and "~user/"
384 - are expanded to the specified user's home directory. See
385 - linkgit:gitignore[5].
383 + of files which are not meant to be tracked. "~/" is expanded
384 + to the value of `$HOME` and "~user/" to the specified user's
385 + home directory. See linkgit:gitignore[5].
386
387 core.editor::
388 Commands such as `commit` and `tag` that lets you edit
@@ -667,7 +667,8 @@ color.ui::
667
668 commit.template::
669 Specify a file to use as the template for new commit messages.
670 - "~/" and "~user/" are expanded to the specified user's home directory.
670 + "~/" is expanded to the value of `$HOME` and "~user/" to the
671 + specified user's home directory.
672
673 diff.autorefreshindex::
674 When using 'git-diff' to compare with work tree
path.c
+9 -4
@@ -235,10 +235,15 @@ char *expand_user_path(const char *path)
235 if (path[0] == '~') {
236 const char *username = path + 1;
237 size_t username_len = first_slash - username;
238 - struct passwd *pw = getpw_str(username, username_len);
239 - if (!pw)
240 - goto return_null;
241 - strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
238 + if (username_len == 0) {
239 + const char *home = getenv("HOME");
240 + strbuf_add(&user_path, home, strlen(home));
241 + } else {
242 + struct passwd *pw = getpw_str(username, username_len);
243 + if (!pw)
244 + goto return_null;
245 + strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
246 + }
247 to_copy = first_slash;
248 }
249 strbuf_add(&user_path, to_copy, strlen(to_copy));